void MsgRecordForm::ShowMore(bool more)
{
	is_loading_ = true;
	QLOG_APP(L"query online msg begin: id={0} type={1} last_time={2} last_server_id={3}") <<session_id_ <<session_type_ <<farst_msg_time_ <<last_server_id_;
	nim::MsgLog::QueryMsgCallback cb = nbase::Bind(&MsgRecordForm::QueryMsgOnlineCb, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);
	nim::MsgLog::QueryMsgOnlineAsync(session_id_, session_type_, kMsgLogNumberShow, 0, farst_msg_time_, last_server_id_, false, true, cb);
}
void LoginCallback::DoLogout(bool over, nim::NIMLogoutType type)
{
	QLOG_APP(L"DoLogout: {0} {1}") <<over <<type;

	LoginStatus status = LoginManager::GetInstance()->GetLoginStatus();
	if(status == LoginStatus_EXIT)
		return;
	LoginManager::GetInstance()->SetLoginStatus(LoginStatus_EXIT);

	WindowsManager::GetInstance()->SetStopRegister(true);
	WindowsManager::GetInstance()->DestroyAllWindows();

	if(status == LoginStatus_NONE)
	{
		UILogoutCallback();
		return;
	}

	if(over)
	{
		if (type == nim::kNIMLogoutKickout || type == nim::kNIMLogoutRelogin)
		{
			QCommand::Set(kCmdAccount, nbase::UTF8ToUTF16(LoginManager::GetInstance()->GetAccount()));
			QCommand::Set(kCmdRestart, L"true");
			std::wstring param = nbase::StringPrintf(L"%d", type);
			QCommand::Set(kCmdExitWhy, param);
		}
		UILogoutCallback();
	}
	else
	{
		NimLogout(type);
	}
}
void MsgRecordForm::QueryMsgOnlineCb(nim::NIMResCode code, const std::string& id, nim::NIMSessionType type, const nim::QueryMsglogResult& result)
{
	QLOG_APP(L"query online msg end: code={0} id={1} type={2}") <<code <<id <<type;


	if (id != session_id_)
		return;
	is_loading_ = false;
	LoadingTip(false);

	if (code == nim::kNIMResSuccess)
	{
		std::vector<nim::IMMessage> vec;
		for (auto& msg : result.msglogs_)
		{
			vec.push_back(msg);
		}
		ShowMsgs(vec);

		if (vec.size() < kMsgLogNumberShow)
		{
			has_more_ = false;
			return;
		}
	}
}
void LoginCallback::ReLogin()
{
	assert(LoginManager::GetInstance()->GetLoginStatus() == LoginStatus_NONE);
	LoginManager::GetInstance()->SetLoginStatus(LoginStatus_LOGIN);

	QLOG_APP(L"-----relogin begin-----");
	nim::Client::Relogin();
}
void CefManager::UnInitialize()
{
#if !defined(SUPPORT_CEF)
	return;
#endif
	QLOG_APP(L"shutting down cef...");
	CefShutdown();
}
//多端
void LoginCallback::OnMultispotLoginCallback(const nim::MultiSpotLoginRes& res)
{
	QLOG_APP(L"OnMultispotLoginCallback: {0} - {1}") << res.notiry_type_ << res.other_clients_.size();

	bool online = res.notiry_type_ == nim::kNIMMultiSpotNotiyTypeImIn;
	if (!res.other_clients_.empty())
		Post2UI(nbase::Bind(LoginCallback::OnMultispotChange, online, res.other_clients_));

}
void TeamService::InvokeAddTeam(const std::string& tid, const std::string& tname, nim::NIMTeamType type)
{
	assert(nbase::MessageLoop::current()->ToUIMessageLoop());

	QLOG_APP(L"InvokeAddTeam: tid={0} ") <<tid;
	for(auto& it : add_team_cb_)
	{
		(*it.second)(tid, tname, type);
	}
}
void TeamService::InvokeChangeTeamAdmin( const std::string& tid, const std::string& uid, bool admin )
{
	assert(nbase::MessageLoop::current()->ToUIMessageLoop());

	QLOG_APP(L"invoke admin: tid={0} uid={1} admin={2}") <<tid <<uid <<admin;
	for(auto& it : change_team_admin_cb_)
	{
		(*it.second)(tid, uid, admin);
	}
}
void TeamService::InvokeSetTeamOwner(const std::string& tid, const std::string& uid)
{
	assert(nbase::MessageLoop::current()->ToUIMessageLoop());

	QLOG_APP(L"invoke admin: tid={0} uid={1} admin={2}") << tid << uid;
	for (auto& it : set_team_owner_cb_)
	{
		(*it.second)(tid, uid);
	}
}
void TeamService::InvokeAddTeamMember(const std::string& tid, const nim::TeamMemberProperty& team_member)
{
	assert(nbase::MessageLoop::current()->ToUIMessageLoop());

	QLOG_APP(L"invoke add: tid={0} uid={1}") << tid << team_member.GetAccountID();
	for(auto& it : add_team_member_cb_)
	{
		(*it.second)(tid, team_member);
	}
}
void TeamService::InvokeRemoveTeam(const std::string& tid)
{
	assert(nbase::MessageLoop::current()->ToUIMessageLoop());

	QLOG_APP(L"InvokeRemoveTeam: tid={0} ") <<tid;

	tid_tname_pair_.erase(tid);

	for(auto& it : remove_team_cb_)
	{
		(*it.second)(tid);
	}
}
void ChatroomCallback::OnSendMsgCallback(__int64 room_id, int error_code, const ChatRoomMessage& result)
{
	QLOG_APP(L"Chatroom:OnSendMsgCallback: id={0} msg_id={1} code={2}") << result.room_id_ << result.client_msg_id_ << error_code;

	if (error_code != 200)
	{
		StdClosure cb = [=](){
			std::wstring toast = nbase::StringPrintf(L"Send room msg error(%d), content:%s", error_code, nbase::UTF8ToUTF16(result.msg_attach_).c_str());
			nim_ui::ShowToast(toast, 5000);
		};
		Post2UI(cb);
	}
}
void ChatroomCallback::OnNotificationCallback(__int64 room_id, const ChatRoomNotification& notification)
{
	QLOG_APP(L"Chatroom:OnNotificationCallback: id={0}") << room_id;
	//QLOG_APP(L"Chatroom:OnNotificationCallback: ext : {0}") << notification.ext_;

	StdClosure cb = [=](){
		ChatroomForm* chat_form = static_cast<ChatroomForm*>(nim_ui::WindowsManager::GetInstance()->GetWindow(ChatroomForm::kClassName, nbase::Int64ToString16(room_id)));
		if (chat_form != NULL)
		{
			chat_form->OnNotificationCallback(notification);
		}
	};
	Post2UI(cb);
}
void ChatroomCallback::OnRegLinkConditionCallback(__int64 room_id, const NIMChatRoomLinkCondition condition)
{
	QLOG_APP(L"Chatroom:OnRegLinkConditionCallback: id={0} condition={1}") << room_id << condition;

	StdClosure cb = [=](){
		ChatroomForm* chat_form = static_cast<ChatroomForm*>(nim_ui::WindowsManager::GetInstance()->GetWindow(ChatroomForm::kClassName, nbase::Int64ToString16(room_id)));
		if (chat_form != NULL)
		{
			chat_form->OnRegLinkConditionCallback(room_id, condition);
		}
	};
	Post2UI(cb);

}
void TeamService::InvokeChangeTeamMember(const std::string& tid, const std::string& uid, const std::string& team_card)
{
	assert(nbase::MessageLoop::current()->ToUIMessageLoop());

	QLOG_APP(L"invoke change: tid={0} uid={1} team_card={2}") << tid << uid << team_card;

	for(auto& it : change_team_member_cb_)
	{
		std::string new_team_card = team_card;
		if (new_team_card.empty())
			new_team_card = nbase::UTF16ToUTF8(UserService::GetInstance()->GetUserName(uid));

		(*it.second)(tid + "#" + uid, new_team_card);
	}
}
void TeamService::InvokeRemoveTeamMember( const std::string& tid, const std::string& uid )
{
	assert(nbase::MessageLoop::current()->ToUIMessageLoop());

	QLOG_APP(L"invoke remove: tid={0} uid={1}") <<tid <<uid;

	if (LoginManager::GetInstance()->IsEqual(uid))
	{
		tid_tname_pair_.erase(tid);
	}

	for(auto& it : remove_team_member_cb_)
	{
		(*it.second)(tid, uid);
	}
}
void LoginCallback::OnReLoginCallback(const nim::LoginRes& login_res)
{
	QLOG_APP(L"OnReLoginCallback: {0} - {1}") << login_res.login_step_ << login_res.res_code_;

	if (login_res.res_code_ == nim::kNIMResSuccess)
	{
		if (login_res.login_step_ == nim::kNIMLoginStepLogin)
		{
			Post2UI(nbase::Bind(&UILoginCallback, login_res.res_code_, true));
		}
	}
	else
	{
		Post2UI(nbase::Bind(&UILoginCallback, login_res.res_code_, true));
	}
}
void LoginCallback::OnLoginCallback( const nim::LoginRes& login_res, const void* user_data )
{
	QLOG_APP(L"OnLoginCallback: {0} - {1}") << login_res.login_step_ << login_res.res_code_;

	if (login_res.res_code_ == nim::kNIMResSuccess)
	{
		if (login_res.login_step_ == nim::kNIMLoginStepLogin)
		{
			Post2UI(nbase::Bind(&UILoginCallback, login_res.res_code_, false));
			if (!login_res.other_clients_.empty())
			{
				Post2UI(nbase::Bind(LoginCallback::OnMultispotChange, true, login_res.other_clients_));
			}
		}
	}
	else
	{
		Post2UI(nbase::Bind(&UILoginCallback, login_res.res_code_, false));
	}
}
void ChatroomCallback::OnEnterCallback(__int64 room_id, const NIMChatRoomEnterStep step, int error_code, const ChatRoomInfo& info, const ChatRoomMemberInfo& my_info)
{
	QLOG_APP(L"Chatroom:OnEnterCallback: id={0} step={1} code={2}") << room_id << step << error_code;

	if (step != kNIMChatRoomEnterStepRoomAuthOver)
		return;

	StdClosure cb = [=](){
		if (error_code != nim::kNIMResSuccess && error_code != nim::kNIMResTimeoutError)
		{
			ChatroomForm* chat_form = static_cast<ChatroomForm*>(nim_ui::WindowsManager::GetInstance()->GetWindow(ChatroomForm::kClassName, nbase::Int64ToString16(room_id)));
			if (chat_form)
			{
				if (error_code == nim::kNIMResRoomLocalNeedRequestAgain)
				{//重新登录
					chat_form->RequestEnter(room_id);
					return;
				}
				else
					chat_form->Close();
			}

			ChatroomFrontpage* front_page = nim_ui::WindowsManager::GetInstance()->SingletonShow<ChatroomFrontpage>(ChatroomFrontpage::kClassName);
			if (!front_page) return;

			std::wstring kick_tip_str;
			ui::MutiLanSupport *multilan = ui::MutiLanSupport::GetInstance();
			switch (error_code)
			{
			case nim::kNIMResNotExist:
				kick_tip_str = L"聊天室不存在";
				break;
			case nim::kNIMResForbidden:
				kick_tip_str = L"权限问题";
				break;
			case nim::kNIMResRoomLinkError:
			case nim::kNIMResRoomError:
				kick_tip_str = L"聊天室异常";
				break;
			case nim::kNIMResRoomBlackBeOut:
				kick_tip_str = L"黑名单用户禁止进入聊天室";
				break;
			case nim::kNIMResFrequently:
				kick_tip_str = L"操作太频繁,稍后重试";
				break;
			default:
				QLOG_APP(L"enter faled: {0} , {1}") << room_id << error_code;
				return;
			}

			ui::Box* kicked_tip_box = (ui::Box*)front_page->FindControl(L"kicked_tip_box");
			kicked_tip_box->SetVisible(true);
			nbase::ThreadManager::PostDelayedTask(front_page->ToWeakCallback([kicked_tip_box]() {
				kicked_tip_box->SetVisible(false);
			}), nbase::TimeDelta::FromSeconds(2));

			ui::Label* kick_tip_label = (ui::Label*)kicked_tip_box->FindSubControl(L"kick_tip");
			kick_tip_label->SetText(kick_tip_str);

			ui::Label* room_name_label = (ui::Label*)kicked_tip_box->FindSubControl(L"room_name");
			room_name_label->SetDataID(nbase::Int64ToString16(room_id));
			ChatRoomInfo info = front_page->GetRoomInfo(room_id);
			if (!info.name_.empty())
				room_name_label->SetUTF8Text(info.name_);
			else
				room_name_label->SetText(nbase::StringPrintf(L"直播间(id %lld)", room_id));
		}
		else
		{
			ChatroomForm* chat_form = static_cast<ChatroomForm*>(nim_ui::WindowsManager::GetInstance()->GetWindow(ChatroomForm::kClassName, nbase::Int64ToString16(room_id)));
			if (chat_form != NULL)
				chat_form->OnEnterCallback(error_code, info, my_info);
		}
	};
	Post2UI(cb);
}
//执行sdk退出函数
void NimLogout(nim::NIMLogoutType type = nim::kNIMLogoutAppExit)
{
	QLOG_APP(L"-----logout begin {0}-----") << type;
	nim::Client::Logout( type, &LoginCallback::OnLogoutCallback );
}
void LoginCallback::UILoginCallback(nim::NIMResCode code, bool relogin)
{
	if(relogin)
	{
		QLOG_APP(L"-----relogin end {0}-----") <<code;

		if (code == nim::kNIMResSuccess)
		{
			LoginManager::GetInstance()->SetLoginStatus(LoginStatus_SUCCESS);
			LoginManager::GetInstance()->SetLinkActive(true);
		}
		else if (code == nim::kNIMResTimeoutError || code == nim::kNIMResConnectionError)
		{
			LoginManager::GetInstance()->SetLoginStatus(LoginStatus_NONE);
			LoginManager::GetInstance()->SetLinkActive(false);

			ShowLinkForm();
		}
		else
		{
			LoginManager::GetInstance()->SetLoginStatus(LoginStatus_NONE);

			QCommand::Set(kCmdRestart, L"true");
			std::wstring wacc = nbase::UTF8ToUTF16(LoginManager::GetInstance()->GetAccount());
			QCommand::Set(kCmdAccount, wacc);
			QCommand::Set(kCmdExitWhy, nbase::IntToString16(code));
			DoLogout(false, nim::kNIMLogoutChangeAccout);
		}
	}
	else
	{
		QLOG_APP(L"-----login end {0}-----") <<code;

		if (nim_ui::LoginManager::GetInstance()->IsLoginFormValid())
		{
		 	if(LoginManager::GetInstance()->GetLoginStatus() == LoginStatus_CANCEL)
		 	{
		 		QLOG_APP(L"-----login cancel end-----");
		 		if (code == nim::kNIMResSuccess)
		 			NimLogout(nim::kNIMLogoutChangeAccout);
		 		else
		 			UILogoutCallback();
		 		return;
		 	}
		 	else
		 		LoginManager::GetInstance()->SetLoginStatus(code == nim::kNIMResSuccess ? LoginStatus_SUCCESS : LoginStatus_NONE);
		 
		 	if (code == nim::kNIMResSuccess)
		 	{
		 		//LoginManager::GetInstance()->GetLoginData()->status_ = kLoginDataStatusValid;
		 		//LoginManager::GetInstance()->GetLoginData()->remember_ = remember_pwd_ckb_->IsSelected() ? 1 : 0;
		 		//LoginManager::GetInstance()->GetLoginData()->auto_login_ = auto_login_ckb_->IsSelected() ? 1 : 0;
		 		//LoginManager::GetInstance()->SaveLoginData();
		 
				nim_ui::LoginManager::GetInstance()->InvokeHideWindow();
		 
		 		std::string acc = LoginManager::GetInstance()->GetAccount();
		 		assert(!acc.empty());
		 		std::wstring app_data_audio_path = QPath::GetUserAppDataDir(acc);
		 		nbase::CreateDirectory(app_data_audio_path);
		 		std::string res_audio_path = nbase::UTF16ToUTF8(app_data_audio_path);
		 		bool ret = nim_audio::Audio::Init(res_audio_path);
		 		assert(ret);
		 		//audio
		 		nim_audio::Audio::RegStartPlayCb(&AudioCallback::OnPlayAudioCallback);
		 		nim_audio::Audio::RegStopPlayCb(&AudioCallback::OnStopAudioCallback);
		 
		 		_DoAfterLogin();
		 		// 登录成功,显示主界面
				nim_ui::LoginManager::GetInstance()->InvokeShowMainForm();
				nim_ui::LoginManager::GetInstance()->InvokeDestroyWindow();
		 	}
		 	else
		 	{
				nim_ui::LoginManager::GetInstance()->InvokeLoginResult(code);
		 	}
		}
		else
		{
		 	QLOG_APP(L"login form has been closed");
		 	LoginManager::GetInstance()->SetLoginStatus(code == nim::kNIMResSuccess ? LoginStatus_SUCCESS : LoginStatus_NONE);
		 	LoginCallback::DoLogout(false);
		}
//依赖demo部分
// 		LoginForm* login_form = dynamic_cast<LoginForm*>( WindowsManager::GetInstance()->GetWindow(LoginForm::kClassName, LoginForm::kClassName) );
// 		if(login_form)
// 		{
// 			if(LoginManager::GetInstance()->GetLoginStatus() == LoginStatus_CANCEL)
// 			{
// 				QLOG_APP(L"-----login cancel end-----");
// 				if (code == nim::kNIMResSuccess)
// 					NimLogout(nim::kNIMLogoutChangeAccout);
// 				else
// 					UILogoutCallback();
// 				return;
// 			}
// 			else
// 				LoginManager::GetInstance()->SetLoginStatus(code == nim::kNIMResSuccess ? LoginStatus_SUCCESS : LoginStatus_NONE);
// 
// 			if (code == nim::kNIMResSuccess)
// 			{
// 				//LoginManager::GetInstance()->GetLoginData()->status_ = kLoginDataStatusValid;
// 				//LoginManager::GetInstance()->GetLoginData()->remember_ = remember_pwd_ckb_->IsSelected() ? 1 : 0;
// 				//LoginManager::GetInstance()->GetLoginData()->auto_login_ = auto_login_ckb_->IsSelected() ? 1 : 0;
// 				//LoginManager::GetInstance()->SaveLoginData();
// 
// 				login_form->ShowWindow(false, false);
// 
// 				std::string acc = LoginManager::GetInstance()->GetAccount();
// 				assert(!acc.empty());
// 				std::wstring app_data_audio_path = QPath::GetUserAppDataDir(acc);
// 				nbase::CreateDirectory(app_data_audio_path);
// 				std::string res_audio_path = nbase::UTF16ToUTF8(app_data_audio_path);
// 				bool ret = nim_audio::Audio::Init(res_audio_path);
// 				assert(ret);
// 				//audio
// 				nim_audio::Audio::RegStartPlayCb(&AudioCallback::OnPlayAudioCallback);
// 				nim_audio::Audio::RegStopPlayCb(&AudioCallback::OnStopAudioCallback);
// 
// 				_DoAfterLogin();
// 				// 登录成功,显示主界面
// 				WindowsManager::SingletonShow<MainForm>(MainForm::kClassName);
// 
// 				::DestroyWindow( login_form->GetHWND() );
// 			}
// 			else
// 			{
// 				login_form->OnLoginResult(code);
// 			}
// 		}
// 		else
// 		{
// 			QLOG_APP(L"login form has been closed");
// 			LoginManager::GetInstance()->SetLoginStatus(code == nim::kNIMResSuccess ? LoginStatus_SUCCESS : LoginStatus_NONE);
// 			LoginCallback::DoLogout(false);
// 		}
	}
}
void TeamEventForm::DeleteAllCb(nim::NIMResCode res_code, int unread)
{
	QLOG_APP(L"DeleteAllCb, code={0} unread={1}") <<res_code <<unread;
	UpdateSysmsgUnread(unread);
}
Exemple #23
0
void DBThread::Cleanup()
{
	nbase::ThreadManager::UnregisterThread();

	QLOG_APP(L"DBThread Cleanup");
}
void LoginCallback::OnKickoutCallback(const nim::KickoutRes& res)
{
	QLOG_APP(L"OnKickoutCallback: {0} - {1}") << res.client_type_ << res.kick_reason_;
	DoLogout(true, nim::kNIMLogoutKickout);
}
void LoginCallback::OnDisconnectCallback()
{
	QLOG_APP(L"OnDisconnectCallback");
}
void LoginCallback::CacelLogin()
{
	assert(LoginManager::GetInstance()->GetLoginStatus() == LoginStatus_LOGIN);
	LoginManager::GetInstance()->SetLoginStatus(LoginStatus_CANCEL);
	QLOG_APP(L"-----login cancel begin-----");
}
void SessionList::OnSessionChangeCallback(nim::NIMResCode rescode, const nim::SessionData& data, int total_unread_counts)
{
	if (rescode != nim::kNIMResSuccess)
	{
		QLOG_APP(L"SessionList::OnChangeCallback Error! {0}, uid:{1}, unread_count: {2}") << rescode << data.id_<< total_unread_counts;
		assert(0);
		return;
	}
	QLOG_APP(L"SessionList::OnChangeCallback. command: {0}, uid: {1}, type: {2}, total unread_count: {3}") << data.command_ << data.id_ << data.type_ << total_unread_counts;
	switch (data.command_)
	{
	case nim::kNIMSessionCommandAdd:
	case nim::kNIMSessionCommandUpdate:
	case nim::kNIMSessionCommandMsgDeleted:
	{
		if (data.last_updated_msg_)
		{
			AddSessionItem(data);
			if (SessionManager::GetInstance()->IsSessionBoxActive(data.id_))
			{
				ResetUnreadCount(data.id_);
			}
		}
	}
	break;
	case nim::kNIMSessionCommandRemoveAll:
		RemoveAllSessionItem();
		break;
	case nim::kNIMSessionCommandRemoveAllP2P:
	case nim::kNIMSessionCommandRemoveAllTeam:
	{
		for (int i = session_list_->GetCount() - 1; i >= 0; i--)
		{
			SessionItem* item = dynamic_cast<SessionItem*>(session_list_->GetItemAt(i));
			if (item && (item->GetIsTeam() == (data.command_ == nim::kNIMSessionCommandRemoveAllTeam)))
			{
				session_list_->RemoveAt(i);
			}
		}
	}
	break;
	case nim::kNIMSessionCommandRemove:
		break;
	case nim::kNIMSessionCommandAllMsgDeleted:
	case nim::kNIMSessionCommandAllP2PMsgDeleted:
	case nim::kNIMSessionCommandAllTeamMsgDeleted:
	{
		for (int i = session_list_->GetCount() - 1; i >= 0; i--)
		{
			SessionItem* item = dynamic_cast<SessionItem*>(session_list_->GetItemAt(i));
			if (item)
			{
				if (data.command_ == nim::kNIMSessionCommandAllMsgDeleted || (item->GetIsTeam() == (data.command_ == nim::kNIMSessionCommandAllTeamMsgDeleted)))
				{
					item->ClearMsg();
				}
			}
		}
	}
	break;
	}
}
void LoginCallback::OnLogoutCallback(nim::NIMResCode res_code)
{
	QLOG_APP(L"OnLogoutCallback: {0}") << res_code;
	QLOG_APP(L"-----logout end-----");
	UILogoutCallback();
}
void TeamEventForm::SysMsgReadAllCb(nim::NIMResCode code, int unread)
{
	QLOG_APP(L"SysMsgReadAllCb, code={0} unread={1}") <<code <<unread;
	UpdateSysmsgUnread(unread);
}
void AudioCallback::OnStopAudioCallback( int code, const char* file_path, const char* sid, const char* cid )
{
	QLOG_APP(L"OnStopAudioCallback: sid={0} cid={1} code={2}") <<sid <<cid <<code;
	Post2UI( nbase::Bind(&UIStopAudioCallback, code, std::string(sid), std::string(cid)) );
}