示例#1
0
 /**
  *  获取群信息
  *
  *  @param pPdu      收到的packet包指针
  *  @param conn_uuid 该包过来的socket 描述符
  */
 void getGroupInfo(CImPdu* pPdu, uint32_t conn_uuid)
 {
     IM::Group::IMGroupInfoListReq msg;
     IM::Group::IMGroupInfoListRsp msgResp;
     if(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength()))
     {
         CImPdu* pPduRes = new CImPdu;
         uint32_t nUserId = msg.user_id();
         uint32_t nGroupCnt = msg.group_version_list_size();
         
         map<uint32_t, IM::BaseDefine::GroupVersionInfo> mapGroupId;
         for(uint32_t i=0; i<nGroupCnt; ++i)
         {
             IM::BaseDefine::GroupVersionInfo groupInfo = msg.group_version_list(i);
             if(CGroupModel::getInstance()->isValidateGroupId(groupInfo.group_id()))
             {
                 mapGroupId[groupInfo.group_id()] = groupInfo;
             }
         }
         list<IM::BaseDefine::GroupInfo> lsGroupInfo;
         CGroupModel::getInstance()->getGroupInfo(mapGroupId, lsGroupInfo);
         
         msgResp.set_user_id(nUserId);
         for(auto it=lsGroupInfo.begin(); it!=lsGroupInfo.end(); ++it)
         {
             IM::BaseDefine::GroupInfo* pGroupInfo = msgResp.add_group_info_list();
 //            *pGroupInfo = *it;
             pGroupInfo->set_group_id(it->group_id());
             pGroupInfo->set_version(it->version());
             pGroupInfo->set_group_name(it->group_name());
             pGroupInfo->set_group_avatar(it->group_avatar());
             pGroupInfo->set_group_creator_id(it->group_creator_id());
             pGroupInfo->set_group_type(it->group_type());
             pGroupInfo->set_shield_status(it->shield_status());
             uint32_t nGroupMemberCnt = it->group_member_list_size();
             for (uint32_t i=0; i<nGroupMemberCnt; ++i)
             {
                 uint32_t userId = it->group_member_list(i);
                 pGroupInfo->add_group_member_list(userId);
             }
         }
         
         log("userId=%u, requestCount=%u", nUserId, nGroupCnt);
         
         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_INFO_RESPONSE);
         CProxyConn::AddResponsePdu(conn_uuid, pPduRes);
     }
     else
     {
         log("parse pb failed");
     }
 }
示例#2
0
void ClientConn::_HandleGroupInfo(CImPdu *pPdu)
{
	IM::Group::IMGroupInfoListRsp msgResp;
	uint32_t nSeqNo = pPdu->GetSeqNum();
	    if(msgResp.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength()))
    {
		uint32_t nUserId = msgResp.user_id();
		int Cnt = msgResp.group_info_list_size();
        list<IM::BaseDefine::GroupInfo> lsGroupInfo;
        for (uint32_t i=0; i<Cnt; ++i) {
            IM::BaseDefine::GroupInfo groupInfo = msgResp.group_info_list(i);
            lsGroupInfo.push_back(groupInfo);
        }
        m_pCallback->onGroupInfo(nSeqNo,  nUserId , lsGroupInfo);
    }
    else
    {
        m_pCallback->onError(nSeqNo, pPdu->GetCommandId(), "parse pb error");
    }
}
示例#3
0
void CGroupChat::HandleGroupInfoResponse(CImPdu* pPdu)
{
    IM::Group::IMGroupInfoListRsp msg;
    CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength()));

    uint32_t user_id = msg.user_id();
    uint32_t group_cnt = msg.group_info_list_size();
    CPduAttachData pduAttachData((uchar_t*)msg.attach_data().c_str(), msg.attach_data().length());
    
    log("HandleGroupInfoResponse, user_id=%u, group_cnt=%u. ", user_id, group_cnt);

    //此处是查询成员时使用,主要用于群消息从数据库获得msg_id后进行发送,一般此时group_cnt = 1
    if (pduAttachData.GetPduLength() > 0 && group_cnt > 0)
    {
        IM::BaseDefine::GroupInfo group_info = msg.group_info_list(0);
        uint32_t group_id = group_info.group_id();
        log("GroupInfoRequest is send by server, group_id=%u ", group_id);
        
        std::set<uint32_t> group_member_set;
        for (uint32_t i = 0; i < group_info.group_member_list_size(); i++)
        {
            uint32_t member_user_id = group_info.group_member_list(i);
            group_member_set.insert(member_user_id);
        }
        if (group_member_set.find(user_id) == group_member_set.end())
        {
            log("user_id=%u is not in group, group_id=%u. ", user_id, group_id);
            return;
        }
        
        IM::Message::IMMsgData msg2;
        CHECK_PB_PARSE_MSG(msg2.ParseFromArray(pduAttachData.GetPdu(), pduAttachData.GetPduLength()));
        CImPdu pdu;
        pdu.SetPBMsg(&msg2);
        pdu.SetServiceId(SID_MSG);
        pdu.SetCommandId(CID_MSG_DATA);
        
        //Push相关
        IM::Server::IMGroupGetShieldReq msg3;
        msg3.set_group_id(group_id);
        msg3.set_attach_data(pdu.GetBodyData(), pdu.GetBodyLength());
        for (uint32_t i = 0; i < group_info.group_member_list_size(); i++)
        {
            uint32_t member_user_id = group_info.group_member_list(i);
            
            msg3.add_user_id(member_user_id);
            
            CImUser* pToImUser = CImUserManager::GetInstance()->GetImUserById(member_user_id);
            if (pToImUser)
            {
                CMsgConn* pFromConn = NULL;
                if( member_user_id == user_id )
                {
                    uint32_t reqHandle = pduAttachData.GetHandle();
                    if(reqHandle != 0)
                        pFromConn = CImUserManager::GetInstance()->GetMsgConnByHandle(user_id, reqHandle);
                }
                
                pToImUser->BroadcastData(pdu.GetBuffer(), pdu.GetLength(), pFromConn);
            }
        }
        
        CImPdu pdu2;
        pdu2.SetPBMsg(&msg3);
        pdu2.SetServiceId(SID_OTHER);
        pdu2.SetCommandId(CID_OTHER_GET_SHIELD_REQ);
        CDBServConn* pDbConn = get_db_serv_conn();
        if (pDbConn)
        {
            pDbConn->SendPdu(&pdu2);
        }
    }
    else if (pduAttachData.GetPduLength() == 0)
    {
        //正常获取群信息的返回
        CMsgConn* pConn = CImUserManager::GetInstance()->GetMsgConnByHandle(user_id, pduAttachData.GetHandle());
        if (pConn)
        {
            msg.clear_attach_data();
            pPdu->SetPBMsg(&msg);
            pConn->SendPdu(pPdu);
        }
    }
}