/** * 创建群组 * * @param pPdu 收到的packet包指针 * @param conn_uuid 该包过来的socket 描述符 */ void createGroup(CImPdu* pPdu, uint32_t conn_uuid) { IM::Group::IMGroupCreateReq msg; IM::Group::IMGroupCreateRsp msgResp; if(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())) { CImPdu* pPduRes = new CImPdu; uint32_t nUserId = msg.user_id(); string strGroupName = msg.group_name(); IM::BaseDefine::GroupType nGroupType = msg.group_type(); if(IM::BaseDefine::GroupType_IsValid(nGroupType)) { string strGroupAvatar = msg.group_avatar(); set<uint32_t> setMember; uint32_t nMemberCnt = msg.member_id_list_size(); for(uint32_t i=0; i<nMemberCnt; ++i) { uint32_t nUserId = msg.member_id_list(i); setMember.insert(nUserId); } log("createGroup.%d create %s, userCnt=%u", nUserId, strGroupName.c_str(), setMember.size()); uint32_t nGroupId = CGroupModel::getInstance()->createGroup(nUserId, strGroupName, strGroupAvatar, nGroupType, setMember); msgResp.set_user_id(nUserId); msgResp.set_group_name(strGroupName); for(auto it=setMember.begin(); it!=setMember.end();++it) { msgResp.add_user_id_list(*it); } if(nGroupId != INVALID_VALUE) { msgResp.set_result_code(0); msgResp.set_group_id(nGroupId); } else { msgResp.set_result_code(1); } log("createGroup.%d create %s, userCnt=%u, result:%d", nUserId, strGroupName.c_str(), setMember.size(), msgResp.result_code()); msgResp.set_attach_data(msg.attach_data()); pPduRes->SetPBMsg(&msgResp); pPduRes->SetSeqNum(pPdu->GetSeqNum()); pPduRes->SetServiceId(IM::BaseDefine::SID_GROUP); pPduRes->SetCommandId(IM::BaseDefine::CID_GROUP_CREATE_RESPONSE); CProxyConn::AddResponsePdu(conn_uuid, pPduRes); } else { log("invalid group type.userId=%u, groupType=%u, groupName=%s", nUserId, nGroupType, strGroupName.c_str()); } } else { log("parse pb failed"); } }
void CGroupChat::HandleClientGroupCreateRequest(CImPdu* pPdu, CMsgConn* pFromConn) { IM::Group::IMGroupCreateReq msg; CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())); uint32_t req_user_id = pFromConn->GetUserId(); string group_name = msg.group_name(); uint32_t group_type = msg.group_type(); if (group_type == IM::BaseDefine::GROUP_TYPE_NORMAL) { log("HandleClientGroupCreateRequest, create normal group failed, req_id=%u, group_name=%s. ", req_user_id, group_name.c_str()); return; } string group_avatar = msg.group_avatar(); uint32_t user_cnt = msg.member_id_list_size(); log("HandleClientGroupCreateRequest, req_id=%u, group_name=%s, avatar_url=%s, user_cnt=%u ", req_user_id, group_name.c_str(), group_avatar.c_str(), user_cnt); CDBServConn* pDbConn = get_db_serv_conn(); if (pDbConn) { CDbAttachData attach_data(ATTACH_TYPE_HANDLE, pFromConn->GetHandle(), 0); msg.set_user_id(req_user_id); msg.set_attach_data(attach_data.GetBuffer(), attach_data.GetLength()); pPdu->SetPBMsg(&msg); pDbConn->SendPdu(pPdu); } else { log("no DB connection "); IM::Group::IMGroupCreateRsp msg2; msg2.set_user_id(req_user_id); msg2.set_result_code(1); msg2.set_group_name(group_name); CImPdu pdu; pdu.SetPBMsg(&msg2); pdu.SetServiceId(SID_GROUP); pdu.SetCommandId(CID_GROUP_CREATE_RESPONSE); pdu.SetSeqNum(pPdu->GetSeqNum()); pFromConn->SendPdu(&pdu); } }
void CreateDiscussionGrpDialog::OnClick(TNotifyUI& msg) { __super::OnClick(msg); if (0 == _tcsicmp(msg.pSender->GetName(), _T("okbtn")) && m_pListCreatFrom && m_pListGroupMembers) { CDuiString groupName = m_editGroupName->GetText(); if (groupName.IsEmpty()) { m_TextErrorTip->SetText(util::getMultilingual()->getStringById( _T("STRID_CREATEDISCUSSIONGRPDIALOG_ERROR_EMPTY_GROUPNAME"))); return; } if (m_pListGroupMembers->GetCount() < 2) { m_TextErrorTip->SetText(util::getMultilingual()->getStringById( _T("STRID_CREATEDISCUSSIONGRPDIALOG_ERROR_COUNT"))); return; } std::vector<std::string> vecMembers; for (int n = 0; n < m_pListGroupMembers->GetCount(); ++n) { CControlUI* pItem = m_pListGroupMembers->GetItemAt(n); if (pItem) { CString strID = pItem->GetUserData(); vecMembers.push_back(util::cStringToString(strID)); } } std::string strGroupName = util::cStringToString(CString(groupName)); imcore::IMLibCoreStartOperationWithLambda( //创建讨论组 [=]() { IM::Group::IMGroupCreateReq imGroupCreateReq; imGroupCreateReq.set_user_id(module::getSysConfigModule()->userId()); imGroupCreateReq.set_group_type(IM::BaseDefine::GroupType::GROUP_TYPE_TMP); imGroupCreateReq.set_group_name(strGroupName); imGroupCreateReq.set_group_avatar(std::string(""));//群头像先不传 for (auto sid : vecMembers) { imGroupCreateReq.add_member_id_list(util::stringToInt32(sid)); } module::getTcpClientModule()->sendPacket(IM::BaseDefine::ServiceID::DFFX_SID_GROUP , IM::BaseDefine::GroupCmdID::DFFX_CID_GROUP_CREATE_REQUEST , &imGroupCreateReq); } ); Close(IDCANCEL); } else if (0 == _tcsicmp(msg.pSender->GetName(), _T("removebtn"))) { CListContainerElementUI* pListElement = reinterpret_cast<CListContainerElementUI*>(msg.pSender->GetTag()); if (pListElement) { m_pListGroupMembers->Remove(pListElement); _refreshUIAddedNum(); } } }
void CHttpQuery::_QueryCreateGroup(const string& strAppKey, Json::Value &post_json_obj, CHttpConn *pHttpConn) { HTTP::CDBServConn *pConn = HTTP::get_db_serv_conn(); if (!pConn) { log("no connection to DBProxy "); char* response_buf = PackSendResult(HTTP_ERROR_SERVER_EXCEPTION , HTTP_ERROR_MSG[9].c_str()); pHttpConn->Send(response_buf, (uint32_t)strlen(response_buf)); pHttpConn->Close(); return; } if ( post_json_obj["req_user_id"].isNull()) { log("no user id "); char* response_buf = PackSendResult(HTTP_ERROR_PARMENT, HTTP_ERROR_MSG[1].c_str()); pHttpConn->Send(response_buf, (uint32_t)strlen(response_buf)); pHttpConn->Close(); return; } if (post_json_obj["group_name"].isNull()) { log("no group name "); char* response_buf = PackSendResult(HTTP_ERROR_PARMENT, HTTP_ERROR_MSG[1].c_str()); pHttpConn->Send(response_buf, (uint32_t)strlen(response_buf)); pHttpConn->Close(); return; } if (post_json_obj["group_type"].isNull()) { log("no group type "); char* response_buf = PackSendResult(HTTP_ERROR_PARMENT, HTTP_ERROR_MSG[1].c_str()); pHttpConn->Send(response_buf, (uint32_t)strlen(response_buf)); pHttpConn->Close(); return; } if (post_json_obj["group_avatar"].isNull()) { log("no group avatar "); char* response_buf = PackSendResult(HTTP_ERROR_PARMENT, HTTP_ERROR_MSG[1].c_str()); pHttpConn->Send(response_buf, (uint32_t)strlen(response_buf)); pHttpConn->Close(); return; } if (post_json_obj["user_id_list"].isNull()) { log("no user list "); char* response_buf = PackSendResult(HTTP_ERROR_PARMENT, HTTP_ERROR_MSG[1].c_str()); pHttpConn->Send(response_buf, (uint32_t)strlen(response_buf)); pHttpConn->Close(); return; } try { uint32_t user_id = post_json_obj["req_user_id"].asUInt(); string group_name = post_json_obj["group_name"].asString(); uint32_t group_type = post_json_obj["group_type"].asUInt(); string group_avatar = post_json_obj["group_avatar"].asString(); uint32_t user_cnt = post_json_obj["user_id_list"].size(); log("QueryCreateGroup, user_id: %u, group_name: %s, group_type: %u, user_cnt: %u. ", user_id, group_name.c_str(), group_type, user_cnt); if (!IM::BaseDefine::GroupType_IsValid(group_type)) { log("QueryCreateGroup, unvalid group_type"); char* response_buf = PackSendResult(HTTP_ERROR_PARMENT, HTTP_ERROR_MSG[1].c_str()); pHttpConn->Send(response_buf, (uint32_t)strlen(response_buf)); pHttpConn->Close(); return; } CDbAttachData attach_data(ATTACH_TYPE_HANDLE, pHttpConn->GetConnHandle()); IM::Group::IMGroupCreateReq msg; msg.set_user_id(0); msg.set_group_name(group_name); msg.set_group_avatar(group_avatar); msg.set_group_type((::IM::BaseDefine::GroupType)group_type); for (uint32_t i = 0; i < user_cnt; i++) { uint32_t member_id = post_json_obj["user_id_list"][i].asUInt(); msg.add_member_id_list(member_id); } msg.set_attach_data(attach_data.GetBuffer(), attach_data.GetLength()); CImPdu pdu; pdu.SetPBMsg(&msg); pdu.SetServiceId(IM::BaseDefine::DFFX_SID_GROUP); pdu.SetCommandId(IM::BaseDefine::DFFX_CID_GROUP_CREATE_REQUEST); pConn->SendPdu(&pdu); } catch (std::runtime_error msg) { log("parse json data failed."); char* response_buf = PackSendResult(HTTP_ERROR_PARMENT, HTTP_ERROR_MSG[1].c_str()); pHttpConn->Send(response_buf, (uint32_t)strlen(response_buf)); pHttpConn->Close(); } }