Ejemplo n.º 1
0
void PhotoService::DownloadUserPhoto(const nim::UserNameCard &info)
{
	std::string url = info.GetIconUrl();
	std::wstring photo_path = GetPhotoDir(kUser) + nbase::UTF8ToUTF16(QString::GetMd5(url));
	int valid = CheckForDownload(kUser, url);
	if (valid != 0)
	{
		if (valid == 1)
		{
			for (auto &it : photo_ready_cb_list_) // 执行监听头像下载的回调
				(*it.second)(kUser, info.GetAccId(), photo_path);
		}
		return;
	}

	nim::NOS::DownloadMediaCallback cb = ToWeakCallback([this, info, photo_path](nim::NIMResCode res_code, const std::string& file_path, const std::string& call_id, const std::string& res_id) {
		if (res_code == nim::kNIMResSuccess)
		{
			std::wstring ws_file_path = nbase::UTF8ToUTF16(file_path);
			if (nbase::FilePathIsExist(ws_file_path, false))
			{
				nbase::CopyFileW(ws_file_path, photo_path);
				nbase::DeleteFile(ws_file_path);

				for (auto &it : photo_ready_cb_list_) // 执行监听头像下载的回调
					(*it.second)(kUser, info.GetAccId(), photo_path);
			}
		}
	});
	nim::NOS::DownloadResource(url, cb);
}
Ejemplo n.º 2
0
// [working on DUI thread]
void HeadModifyForm::LoadHeadImage()
{
	is_loading_image_ = true;
	BeginLoadAnimation(); // 开始转菊花

	/*
	// 目前首次加载或者更换图片过程中的加载,都采用当前头像的Bitmap
	// 释放历史数据,初始化参数。TIP:务必在DUI线程操作,避免DUI(Paint)和Misc(Init)同时操作参数
	if(big_head_preview_ctrl_)
		big_head_preview_ctrl_->Init();
	if(small_head_preview_ctrl_)
		small_head_preview_ctrl_->Init();
	*/
	if(head_view_ctrl_)
		head_view_ctrl_->Init(false);

	head_select_ctrl_->SetVisible(false); // 会引起HeadViewCtrl也重绘
	select_image_btn_->SetEnabled(false);
	save_image_btn_->SetEnabled(false);

	// MISC线程渲染图片
	is_misc_thread_rendering_ = true; // 渲染过程中不要退出,会崩溃
	StdClosure render_image_closure = 
		nbase::Bind(&HeadModifyForm::DoLoadHeadImage, this);
	nbase::ThreadManager::PostTask(kThreadUI, ToWeakCallback(render_image_closure));
}
Ejemplo n.º 3
0
void HeadModifyForm::OnUploadHeadIconCallback(nim::NIMResCode res_code, const std::string& url)
{
	if(res_code == nim::kNIMResSuccess)
	{
		QLOG_APP(L"Head icon upload success and call callback!");

		if (complete_callback_)
			complete_callback_(uid_, url);

		if (specific_cached_file_.empty())
		{
			//删除缓存头像
			StdClosure closure = nbase::Bind(&HeadModifyForm::DeleteFileCallback, new_temp_head_image_path_);
			nbase::ThreadManager::PostTask(kThreadGlobalMisc, closure);
		}

		OnNotifyHeadModifyCallback();
	}
	else
	{
		// 头像上传失败
		QLOG_ERR(L"Upload head icon failed");
		StdClosure closure = nbase::Bind(&HeadModifyForm::OnNotifyHeadModifyFailed, this);
		nbase::ThreadManager::PostTask(kThreadUI, ToWeakCallback(closure));
	}
}
Ejemplo n.º 4
0
void TeamService::QueryTeamInfo(const std::string & tid, OnGetTeamInfo cb)
{
	nim::Team::QueryTeamInfoAsync(tid, ToWeakCallback([cb](const std::string& tid, const nim::TeamInfo& result) 
	{
		cb(result);
	}));
}
Ejemplo n.º 5
0
bool MsgBubbleSnapChat::OnClicked(ui::EventArgs* arg)
{
	//如果是阅后即焚,则需要先下载好图片
	Json::Value json;
	if (StringToJson(msg_.attach_, json))
	{
		std::string url = json["data"]["url"].asString();
		if (nbase::FilePathIsExist(src_image_path_, false)) {
			ImageViewManager::GetInstance()->StartViewPic(src_image_path_, L"", true, true);
			nim::MsgLog::DeleteAsync(sid_, type_, msg_.client_msg_id_, nim::MsgLog::DeleteCallback());
			SessionBox* session = dynamic_cast<SessionBox*>(SessionManager::GetInstance()->FindSessionBox(sid_));
			if (session)
				session->OnSnapchatReadCallback(msg_.client_msg_id_);
		}
		else {
			nim::NOS::DownloadResource(url, ToWeakCallback([this](int res_code, const std::string& file_path, const std::string& call_id, const std::string& res_id) {
				if (res_code == nim::kNIMResSuccess)
				{
					std::wstring ws_file_path = nbase::UTF8ToUTF16(file_path);
					if (nbase::FilePathIsExist(ws_file_path, false))
					{
						ImageViewManager::GetInstance()->StartViewPic(ws_file_path, L"", true, true);
						nim::MsgLog::DeleteAsync(sid_, type_, msg_.client_msg_id_, nim::MsgLog::DeleteCallback());
						SessionBox* session_form = dynamic_cast<SessionBox*>(SessionManager::GetInstance()->FindSessionBox(sid_));
						if (session_form)
							session_form->OnSnapchatReadCallback(msg_.client_msg_id_);
					}
				}
			}));
		}
	}

	return true;
}
Ejemplo n.º 6
0
// [working on misc thread]
void HeadModifyForm::DoLoadHeadImage()
{
	// 渲染图片
	PreLoadHeadImage();

	// 投递到DUI线程将渲染好的图片显示到界面上
	StdClosure show_image_closure = 
		nbase::Bind(&HeadModifyForm::PostLoadHeadImage, this);
	nbase::ThreadManager::PostTask(kThreadUI, ToWeakCallback(show_image_closure));
}
Ejemplo n.º 7
0
bool MemberManagerForm::OnBtnConfirmClick(ui::EventArgs* param)
{
	if (((Option*)FindControl(L"owner"))->IsSelected())
	{
		nim::Team::TransferTeamAsync(tid_, user_id_, false, nbase::Bind(&TeamCallback::OnTeamEventCallback, std::placeholders::_1));
	}
	else if (((Option*)FindControl(L"manager"))->IsSelected() && user_type_ != nim::kNIMTeamUserTypeManager)
	{
		std::list<std::string> uids_list;
		uids_list.push_back(user_id_);
		nim::Team::AddManagersAsync(tid_, uids_list, nbase::Bind(&TeamCallback::OnTeamEventCallback, std::placeholders::_1));
	}
	else if (((Option*)FindControl(L"member"))->IsSelected() && user_type_ != nim::kNIMTeamUserTypeNomal)
	{
		std::list<std::string> uids_list;
		uids_list.push_back(user_id_);
		nim::Team::RemoveManagersAsync(tid_, uids_list, nbase::Bind(&TeamCallback::OnTeamEventCallback, std::placeholders::_1));
	}
	
	std::string new_team_card = nbase::StringTrim(re_team_card_->GetUTF8Text());
	if (!team_card_.empty() && new_team_card.empty())
	{
		MsgboxCallback cb = ToWeakCallback([this](MsgBoxRet ret) {
			this->ActiveWindow();
		});
		ShowMsgBox(m_hWnd, L"群昵称不能为空", ToWeakCallback(cb), L"提示", L"确定", L"");
		return true;
	}

	if (new_team_card != team_card_)
	{
		nim::TeamMemberProperty values(tid_, user_id_);
		values.SetNick(new_team_card);
		if (user_id_ != LoginManager::GetInstance()->GetAccount()) 
			nim::Team::UpdateOtherNickAsync(values, nbase::Bind(&OnTeamEventCallback, user_id_, new_team_card, std::placeholders::_1));
		else 
			nim::Team::UpdateMyPropertyAsync(values, nbase::Bind(&OnTeamEventCallback, user_id_, new_team_card, std::placeholders::_1));
	}

	Close();
	return true; 
}
Ejemplo n.º 8
0
UnregisterCallback TeamService::RegChangeTeamOwner(OnTeamOwnerChange set_team_owner)
{
	assert(nbase::MessageLoop::current()->ToUIMessageLoop());
	OnTeamOwnerChange* new_cb = new OnTeamOwnerChange(set_team_owner);
	int cb_id = (int)new_cb;
	set_team_owner_cb_[cb_id].reset(new_cb);
	auto unregister = ToWeakCallback([this, cb_id]() {
		set_team_owner_cb_.erase(cb_id);
	});
	return unregister;
}
Ejemplo n.º 9
0
UnregisterCallback TeamService::RegRemoveTeamMember( OnTeamMemberRemove remove )
{
	assert(nbase::MessageLoop::current()->ToUIMessageLoop());
	OnTeamMemberRemove* new_cb = new OnTeamMemberRemove(remove);
	int cb_id = (int)new_cb;
	remove_team_member_cb_[cb_id].reset(new_cb);
	auto unregister = ToWeakCallback([this, cb_id]() {
		remove_team_member_cb_.erase(cb_id);
	});
	return unregister;
}
Ejemplo n.º 10
0
UnregisterCallback TeamService::RegAddTeamMember( OnTeamMemberAdd add )
{
	assert(nbase::MessageLoop::current()->ToUIMessageLoop());
	OnTeamMemberAdd* new_cb = new OnTeamMemberAdd(add);
	int cb_id = (int)new_cb;
	add_team_member_cb_[cb_id].reset(new_cb);
	auto unregister = ToWeakCallback([this, cb_id]() {
		add_team_member_cb_.erase(cb_id);
	});
	return unregister;
}
Ejemplo n.º 11
0
UnregisterCallback TeamService::RegChangeTeamName(OnTeamNameChange change)
{
	assert(nbase::MessageLoop::current()->ToUIMessageLoop());
	OnTeamNameChange* new_cb = new OnTeamNameChange(change);
	int cb_id = (int)new_cb;
	change_team_name_cb_[cb_id].reset(new_cb);
	auto unregister = ToWeakCallback([this, cb_id]() {
		change_team_name_cb_.erase(cb_id);
	});
	return unregister;
}
Ejemplo n.º 12
0
UnregisterCallback SessionList::RegUnreadCountChange(const OnUnreadCountChangeCallback& callback)
{
	OnUnreadCountChangeCallback* new_callback = new OnUnreadCountChangeCallback(callback);
	int cb_id = (int)new_callback;
	assert(nbase::MessageLoop::current()->ToUIMessageLoop());
	unread_count_change_cb_list_[cb_id].reset(new_callback);
	auto cb = ToWeakCallback([this, cb_id]() {
		unread_count_change_cb_list_.erase(cb_id);
	});
	return cb;	
}
Ejemplo n.º 13
0
UnregisterCallback TeamService::RegSetTeamAdmin( OnTeamAdminSet admin )
{
	assert(nbase::MessageLoop::current()->ToUIMessageLoop());
	OnTeamAdminSet* new_cb = new OnTeamAdminSet(admin);
	int cb_id = (int)new_cb;
	change_team_admin_cb_[cb_id].reset(new_cb);
	auto unregister = ToWeakCallback([this, cb_id]() {
		change_team_admin_cb_.erase(cb_id);
	});
	return unregister;
}
Ejemplo n.º 14
0
UnregisterCallback PhotoService::RegPhotoReady(const OnPhotoReadyCallback & callback)
{
	OnPhotoReadyCallback* new_callback = new OnPhotoReadyCallback(callback);
	int cb_id = (int)new_callback;
	assert(nbase::MessageLoop::current()->ToUIMessageLoop());
	photo_ready_cb_list_[cb_id].reset(new_callback);
	auto cb = ToWeakCallback([this, cb_id]() {
		photo_ready_cb_list_.erase(cb_id);
	});
	return cb;
}
Ejemplo n.º 15
0
void SessionForm::OnGetTeamMemberCb(const std::string& tid, int count, const std::list<nim::TeamMemberProperty>& team_member_info_list)
{
	team_member_info_list_.clear();
	std::list<std::string> acc_list;
	for (auto& it : team_member_info_list)
	{
		if (IsTeamMemberType(it.GetUserType()))
		{
			team_member_info_list_[it.GetAccountID()] = it;
			acc_list.push_back(it.GetAccountID());
		}
	}

	btn_refresh_member_->SetEnabled(true);
	member_list_->RemoveAll();
	label_member_->SetText(nbase::StringPrintf(L"群成员(共%d人)", team_member_info_list_.size()));

	OnGetUserInfoCallback cb = ToWeakCallback([this](const std::list<nim::UserNameCard>& uinfos) {
		for (const auto &uinfo : uinfos)
		{
			nim::TeamMemberProperty tm_info = team_member_info_list_.at(uinfo.GetAccId());

			std::wstring wid = nbase::UTF8ToUTF16(tm_info.GetAccountID());
			Control* ctrl = member_list_->FindSubControl(wid);
			if (ctrl == NULL)
			{
				TeamItem* item = new TeamItem;
				GlobalManager::FillBoxWithCache(item, L"session/team_item.xml");
				if (tm_info.GetUserType() == nim::kNIMTeamUserTypeCreator)
					member_list_->AddAt(item, 0);
				else
					member_list_->Add(item);

				item->InitControl();
				item->InitInfo(tm_info);
			}
			else
			{
				QLOG_WAR(L"OnGetTeamMemberCb found the duplicate id, id={0}") << wid.c_str();
			}

			if (tm_info.GetUserType() == nim::kNIMTeamUserTypeCreator || tm_info.GetUserType() == nim::kNIMTeamUserTypeManager)
			{
				if (LoginManager::GetInstance()->IsEqual(tm_info.GetAccountID()))
				{
					btn_new_broad_->SetVisible(true);
				}
			}
		}
	});
	UserService::GetInstance()->GetUserInfoWithEffort(acc_list, cb);
}
Ejemplo n.º 16
0
// 图片无效或者DUILIB图片引擎Read图片失败
void HeadModifyForm::OnNotifyImageInvalid()
{
	// 提示图片无效,不是图片或者图片为超过200*200
	auto multilan = MutiLanSupport::GetInstance();
	std::wstring content = multilan->GetStringViaID(L"STRID_HEAD_MODIFY_IMAGE_VALID");
	std::wstring title = multilan->GetStringViaID(L"STRID_HEAD_MODIFY_BUTTON_LOCAL_UPLOAD");
	std::wstring yes = multilan->GetStringViaID(L"STRING_OK");
	MsgboxCallback cb = nbase::Bind(&HeadModifyForm::OnButtonCloseTipCallback, this, std::placeholders::_1);
	cb = ToWeakCallback(cb);
	ShowMsgBox(m_hWnd, content, MsgboxCallback(), title, yes, L"");

	select_image_btn_->SetEnabled(true);
}
Ejemplo n.º 17
0
void MsgRecordForm::RefreshRecord(std::string id, nim::NIMSessionType type)
{
	if(id == session_id_)
		return;
	session_id_ = id;
	session_type_ = type;

	//初始化
	first_show_msg_ = true;
	last_msg_time_ = 0;
	farst_msg_time_ = 0;
	last_server_id_ = 0;

	has_more_ = true;
	is_loading_ = false;

	std::wstring name;
	if (type == nim::kNIMSessionTypeP2P)
		name = UserService::GetInstance()->GetUserName(id);
	else
		name = TeamService::GetInstance()->GetTeamName(id);
	label_title_->SetText(name);
	SetTaskbarTitle(name);

	msg_list_->RemoveAll();
	id_bubble_pair_.clear();

	std::string play_sid = AudioCallback::GetPlaySid();
	std::wstring wsid = nbase::UTF8ToUTF16(play_sid);
	if(GetWindowId() == wsid)
	{
		AudioCallback::SetPlaySid("");
		AudioCallback::SetPlayCid("");

		nim_audio::Audio::StopPlayAudio();
	}

	if (type == nim::kNIMSessionTypeTeam)
	{
		nim::Team::QueryTeamMembersCallback cb = ToWeakCallback([this](const std::string& tid, int member_count, const std::list<nim::TeamMemberProperty>& props) 
		{
			team_member_info_list_.clear();
			for (const auto &info : props)
				team_member_info_list_[info.GetAccountID()] = info;
			ShowMore(false);
		});
		nim::Team::QueryTeamMembersAsync(session_id_, cb);
	}
	else
		ShowMore(false);
}
Ejemplo n.º 18
0
void HeadModifyForm::OnNotifyHeadModifyFailed()
{
	auto multilan = MutiLanSupport::GetInstance();
	std::wstring content = multilan->GetStringViaID(L"STRID_HEAD_MODIFY_SAVE_FAILED");
	std::wstring title = multilan->GetStringViaID(L"STRID_HEAD_MODIFY_TITLE");
	std::wstring yes = multilan->GetStringViaID(L"STRING_OK");
	MsgboxCallback cb = nbase::Bind(&HeadModifyForm::OnButtonCloseTipCallback, this, std::placeholders::_1);
	cb = ToWeakCallback(cb);
	ShowMsgBox(m_hWnd, content, cb, title, yes, L"");

	//删除缓存头像
	StdClosure closure = nbase::Bind(&HeadModifyForm::DeleteFileCallback, new_temp_head_image_path_);
	nbase::ThreadManager::PostTask(kThreadGlobalMisc, closure);
}
Ejemplo n.º 19
0
// 保存头像
void HeadModifyForm::OnButtonSaveImage()
{
	if(is_loading_image_)
		return;

	//if (!shared::FilePathIsExist(attach_path, true))
	//	return shared::CreateDirRecursively(attach_path);

	static const std::wstring mime_type = L"image/png";
	std::wstring temp_file_path;
	if (!specific_cached_file_.empty())
	{
		temp_file_path = specific_cached_file_;
	}
	else
	{
		temp_file_path = PhotoService::GetInstance()->GetPhotoDir(kUser);
		std::wstring temp_file_name;
		nbase::Time::TimeStruct now = nbase::Time::Now().ToTimeStruct(true);
		nbase::StringPrintf(temp_file_name, L"temp_head_icon_%d%d%d%d%d%d",
			now.year(), now.month(), now.day_of_month(), now.hour(), now.minute(), now.second());
		temp_file_path.append(temp_file_name);
	}

	// 覆盖本地的旧头像
	if(head_view_ctrl_->SaveSelectBitmap(head_select_ctrl_->GetPos(), temp_file_path, mime_type))
	{
		g_last_save_head_image_ = image_path_;
		RECT head_select_rect = head_select_ctrl_->GetPos();
		RECT head_panel_rect = head_panel_->GetPos();
		RECT select_padding = { head_select_rect.left - head_panel_rect.left,
			head_select_rect.top - head_panel_rect.top, 0, 0};
		g_last_select_padding_ = select_padding;
		g_last_select_width_ = head_select_rect.right - head_select_rect.left;
		new_temp_head_image_path_ = temp_file_path;

		// 在Core线程触发头像修改监听
		StdClosure notify_head_modify_closure = 
			nbase::Bind(&HeadModifyForm::NotifyHeadModify, this, temp_file_path, uid_);
		nbase::ThreadManager::PostTask(kThreadUI, ToWeakCallback(notify_head_modify_closure));
	}
	else
	{
		// 提示用户,保存失败
		QLOG_ERR(L"Save new head icon failed!");
		OnNotifyHeadModifyFailed();
	}
}
Ejemplo n.º 20
0
LRESULT SessionForm::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	CloseReason closeReason = (CloseReason)wParam;

	// 如果是因为所有会话盒子都关闭了导致窗口关闭,则正常返回
	if (kSessionBoxClose == closeReason)
	{
		return __super::OnClose(uMsg, wParam, lParam, bHandled);
	}
	// 如果是其他原因触发了WM_CLOSE
	else
	{
		int session_count = merge_list_->GetCount();
		if (session_count > 0 && NULL != active_session_box_)
		{
			// 如果只有一个会话盒子,就直接关闭
			if (1 == session_count)
			{
				CloseSessionBox(active_session_box_->GetSessionId());
			}
			// 如果包含多个会话盒子,就询问用户
			else
			{
				MsgboxCallback cb = ToWeakCallback([this](MsgBoxRet ret)
				{
					if (ret == MB_YES)
					{
						while (merge_list_->GetCount() > 0)
						{
							Control *merge_item = merge_list_->GetItemAt(0);
							ASSERT(NULL != merge_item);
							if (NULL == merge_item)
								break;

							CloseSessionBox(merge_item->GetUTF8Name());
						}
					}				
				});
				ShowMsgBox(this->GetHWND(), L"当前窗口包含多个会话,确定要关闭窗口吗?", cb);
			}

			bHandled = TRUE;
			return 0;
		}
	}

	return __super::OnClose(uMsg, wParam, lParam, bHandled);
}
Ejemplo n.º 21
0
// 选择图像
void HeadModifyForm::OnButtonSelectImage()
{
	if(is_loading_image_)
		return;

	select_image_btn_->SetEnabled(false);
	std::wstring file_type = ui::MutiLanSupport::GetInstance()->GetStringViaID(L"STRING_PIC_FILE");
	LPCTSTR filter_text = L"*.jpg;*.jpeg;*.png";
	std::wstring text = nbase::StringPrintf(L"%s(%s)", file_type.c_str(),filter_text);
	CFileDialogEx* file_dlg = new CFileDialogEx();
	PTR_VOID(file_dlg);
	std::map<LPCTSTR,LPCTSTR> filters;
	filters[text.c_str()] = filter_text;
	file_dlg->SetFilter(filters);
	file_dlg->SetParentWnd(m_hWnd);
	CFileDialogEx::FileDialogCallback2 callback2 = nbase::Bind(&HeadModifyForm::OnButtonSelectImageCallback, this, std::placeholders::_1, std::placeholders::_2);
	file_dlg->AyncShowOpenFileDlg(ToWeakCallback(callback2));
}
Ejemplo n.º 22
0
// 退出修改
void HeadModifyForm::OnButtonClose(bool forced_close /*= false*/)
{
	if(forced_close)
	{
		// 强制退出
		this->Close();
	}
	else
	{
		// 是否已经设置退出标记
		if(is_quit_)
			return;

		if(is_misc_thread_rendering_)
		{
			// 设置退出标记,在渲染回调DUI时再弹出提示
			is_quit_ = true; 
		}
		else
		{
			// 判断是否需要弹出提示
			if(head_view_ctrl_->CheckHasLoadImage())
			{
				// 退出提示:是否放弃修改?
				auto multilan = MutiLanSupport::GetInstance();
				std::wstring content = multilan->GetStringViaID(L"STRID_HEAD_MODIFY_CLOSE_TIP");
				std::wstring title = multilan->GetStringViaID(L"STRID_HEAD_MODIFY_TITLE");
				std::wstring yes = multilan->GetStringViaID(L"STRID_HEAD_MODIFY_GIVEUP_MODIFY");
				std::wstring no = multilan->GetStringViaID(L"STRID_HEAD_MODIFY_CONTINUE_MODIFY");
				MsgboxCallback cb = nbase::Bind(&HeadModifyForm::OnButtonCloseTipCallback, this, std::placeholders::_1); 
				cb = ToWeakCallback(cb);
				ShowMsgBox(m_hWnd, content, cb, title, yes, no);
			}
			else
			{
				this->Close();
			}
		}
	}
}
void CefControlBase::LoadString(const CefString& stringW, const CefString& url)
{
	if (browser_handler_.get() && browser_handler_->GetBrowser().get())
	{
		CefRefPtr<CefFrame> frame = browser_handler_->GetBrowser()->GetMainFrame();
		if (!frame)
			return;

		frame->LoadStringW(stringW, url);
	}
	else
	{
		if (browser_handler_.get())
		{
			StdClosure cb = ToWeakCallback([this, stringW, url]()
			{
				LoadString(stringW, url);
			});
			browser_handler_->AddAfterCreateTask(cb);
		}
	}
}
Ejemplo n.º 24
0
void MemberManagerForm::InitWindow()
{
	FindControl(L"privilege_panel")->SetVisible(show_privilege_panel_);
	nim::UserNameCard user_info;
	UserService::GetInstance()->GetUserInfo(user_id_, user_info);
	Button* head_image_button = (Button*)FindControl(L"head_image");
	head_image_button->SetBkImage(UserService::GetInstance()->GetUserPhoto(user_info.GetAccId()));
	Label* show_name_label = (Label*)FindControl(L"show_name");
	show_name_label->SetText(UserService::GetInstance()->GetUserName(user_info.GetAccId()));
	re_team_card_ = (ui::RichEdit*)FindControl(L"team_card");
	re_team_card_->SetLimitText(10);
	ui::Button* btn_confirm = (ui::Button*)FindControl(L"confirm");
	btn_confirm->AttachClick(nbase::Bind(&MemberManagerForm::OnBtnConfirmClick, this, std::placeholders::_1));
	ui::Button* btn_cancel = (ui::Button*)FindControl(L"cancel");
	btn_cancel->AttachClick(nbase::Bind(&MemberManagerForm::OnBtnCancelClick, this, std::placeholders::_1));

	nim::Team::QueryTeamMembersAsync(tid_, nbase::Bind(&MemberManagerForm::OnQueryTeamMembers, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
	
	OnUserPhotoReadyCallback cb = ToWeakCallback([this](const std::string& accid, const std::wstring& photo_path) {
		if (user_id_ == accid) FindControl(L"head_image")->SetBkImage(photo_path); });
	unregister_cb.Add(UserService::GetInstance()->RegUserPhotoReady(cb));
}
Ejemplo n.º 25
0
void ChatroomFrontpage::CreateRoomItem(const ChatRoomInfo& room_info)
{
	ui::Box* kicked_tip_box = (ui::Box*)FindControl(L"kicked_tip_box");
	if (kicked_tip_box->IsVisible())
	{
		ui::Label* room_name_label = (ui::Label*)kicked_tip_box->FindSubControl(L"room_name");
		__int64 label_room_id;
		nbase::StringToInt64(room_name_label->GetUTF8DataID(), &label_room_id);
		if (label_room_id == room_info.id_)
			room_name_label->SetUTF8Text(room_info.name_);
	}

	ui::ButtonBox* room_item = (ui::ButtonBox*)ui::GlobalManager::CreateBoxWithCache(L"chatroom/room_item.xml");
	if (room_item)
	{
		room_list_->Add(room_item);

		ui::Label* room_name_label = (ui::Label*)room_item->FindSubControl(L"room_name");
		room_name_label->SetUTF8Text(room_info.name_);
		ui::Label* online_count_label = (ui::Label*)room_item->FindSubControl(L"online_num");
		if(room_info.online_count_ >= 10000)
			online_count_label->SetText(nbase::StringPrintf(L"在线人数:%.1f万人", (float)room_info.online_count_ / (float)10000));
		else
			online_count_label->SetText(nbase::StringPrintf(L"在线人数:%d人", room_info.online_count_));

		ui::Button* room_shot = (ui::Button*)room_item->FindSubControl(L"room_shot");
		room_shot->SetDataID(nbase::Int64ToString16(room_info.id_));
		room_shot->AttachClick(ToWeakCallback([this](ui::EventArgs* args)
		{
			std::wstring room_id = args->pSender->GetDataID();
			if (room_id.empty())
				return true;
			
			//这里应该查找当前房间号
			ChatroomForm* chat_form = static_cast<ChatroomForm*>(nim_ui::WindowsManager::GetInstance()->GetWindow(ChatroomForm::kClassName, room_id));
			if (chat_form != NULL)
			{
				chat_form->ActiveWindow();
				return true;
			}
			else
			{
				nim_comp::WindowList list = nim_ui::WindowsManager::GetInstance()->GetWindowsByClassName(ChatroomForm::kClassName);
				for (auto &it : list)
				{
					ChatroomForm* form = static_cast<ChatroomForm*>(it);
					form->Close();
				}
			}
			__int64 id;
			nbase::StringToInt64(room_id, &id);
			if (0 == id)
				return true;
			
			chat_form = new ChatroomForm(id);
			if (chat_form != NULL)
			{
				chat_form->Create(NULL, ChatroomForm::kClassName, WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX, 0);
				chat_form->RequestEnter(id);
			}

			return true;
		}));
	}
}
Ejemplo n.º 26
0
void ChatroomFrontpage::InvokeGetRoomList()
{
	FindControl(L"loading_tip")->SetVisible(true);

	auto http_cb = ToWeakCallback([this](bool ret, int response_code, const std::string& reply)
	{
		StdClosure error_cb = ToWeakCallback([this]()
		{
			FindControl(L"loading_tip")->SetVisible(false);
			FindControl(L"load_error_tip")->SetVisible(true);
		});

		if (!ret || response_code != nim::kNIMResSuccess)
		{
			QLOG_ERR(L"Invoke get room list error. Error code: {0}.") << response_code;
			Post2UI(error_cb);

			return;
		}

		Json::Value json_reply;
		Json::Reader reader;
		if (reader.parse(reply, json_reply) && json_reply.isObject())
		{
			int res = json_reply["res"].asInt();
			if (res != 200)
			{
				QLOG_ERR(L"Invoke get room list error. Json rescode: {0}.") << res;
				Post2UI(error_cb);

				return;
			}

			int count = json_reply["msg"]["total"].asInt();
			Json::Value json_list = json_reply["msg"]["list"];
			if (!json_list.isArray())
			{
				QLOG_ERR(L"Invoke get room list error. Reason: Not an array.");
				Post2UI(error_cb);

				return;
			}

			StdClosure closure = ToWeakCallback([this, json_list, count]() 
			{
				FindControl(L"loading_tip")->SetVisible(false);

				for (int i = 0; i < count; i++)
				{
					ChatRoomInfo info;
					info.id_ = json_list[i]["roomid"].asInt64();
					info.name_ = json_list[i]["name"].asString();
					info.creator_id_ = json_list[i]["creator"].asString();
					nbase::StringToInt(json_list[i]["onlineusercount"].asString(), &info.online_count_);
					info.valid_flag_ = json_list[i]["status"].asInt();
					info.ext_ = json_list[i]["ext"].asString();
					info.announcement_ = json_list[i]["announcement"].asString();
					info.broadcast_url_ = json_list[i]["broadcasturl"].asString();
					id_info_map_[info.id_] = info;

					CreateRoomItem(info);
				}
			});
			Post2UI(closure);
		}
		else
		{
			QLOG_ERR(L"invoke get room list json parse error {0}.") << reply;
			Post2UI(error_cb);
		}
	});

	std::string api_addr = "https://app.netease.im/api/chatroom/homeList";
	std::string new_api_addr = GetConfigValue("kNIMChatRoomAddress");
	if (!new_api_addr.empty())
		api_addr = new_api_addr;

	std::string app_key = "45c6af3c98409b18a84451215d0bdd6e";
	std::string new_app_key = GetConfigValue(g_AppKey);
	if (!new_app_key.empty())
		app_key = new_app_key;
	nim_http::HttpRequest request(api_addr, "", 0, http_cb);
	request.AddHeader("Content-Type", "application/json; charset=utf-8");
	request.AddHeader("appKey", app_key);
	nim_http::PostRequest(request);
}