BOOL ReceiveMsgManage::pushMessageBySId(const std::string& sId, MessageEntity& msg) { if (sId.empty()) { LOG__(ERR, _T("sId is empty!")); return FALSE; } CAutoLock lock(&m_lock); try { SessionMessage_List* listChatMsg = _getChatMsgListBySID(sId); if (listChatMsg) { listChatMsg->push_back(msg); } else { SessionMessage_List listChatMsg2; listChatMsg2.push_back(msg); m_mapSessionMsg[sId] = listChatMsg2; } } catch (...) { CString csSid = util::stringToCString(sId); CString csMsgCnt = util::stringToCString(msg.content, CP_UTF8); LOG__(ERR, _T("pushMessageBySId failed,SId:%s,msg conteng:%s"), csSid, csMsgCnt); return FALSE; } return TRUE; }
void ReceiveMsgManage::removeAllMessage() { CAutoLock lock(&m_lock); //记录下程序退出时所有的消息列表,并且记录下来,这个会成为离线消息 SessionMessageMap::iterator iterMap = m_mapSessionMsg.begin(); LOG__(ERR, _T("MessageMananger unread message trace begin:")); for (; iterMap != m_mapSessionMsg.end(); ++iterMap) { SessionMessage_List msgList; if (popMessagesBySId(iterMap->first, msgList)) { SessionMessage_List::iterator iter = msgList.begin(); for (; iter != msgList.end(); ++iter) { MessageEntity& msg = *iter; CString csUId = util::stringToCString(msg.talkerSid); CString csCnt = util::stringToCString(msg.content, CP_UTF8); CTime time(msg.msgTime); CString csTime = time.Format(_T("%Y-%m-%d %H:%M:%S")); LOG__(DEBG, _T("time:%s id:%s,content:%s"), csTime, csUId, csCnt); } } } LOG__(DEBG, _T("MessageMananger unread message trace end")); m_mapSessionMsg.clear(); }
BOOL SessionLayout::_DisplayUnreadMsg() { SessionMessage_List msgList; if (!ReceiveMsgManage::getInstance()->popMessagesBySId(m_sId, msgList) && msgList.empty()) { //没有未读消息 return FALSE; } for (auto MessageInfo : msgList) { if (MESSAGE_RENDERTYPE_SYSTEMTIPS != MessageInfo.msgRenderType) { DECRYPT_MSG(MessageInfo.content, MessageInfo.content); } _DisplayMsgToIE(MessageInfo); } //保存到历史消息中 module::getDatabaseModule()->sqlBatchInsertMessage(msgList); //离线消息需要重置获取历史消息的msgid MessageEntity msgFront = msgList.front(); module::getMessageModule()->setSessionTopMsgId(msgFront.sessionId, msgFront.msgId -1); //更新总未读计数 module::getSessionModule()->asynNotifyObserver(module::KEY_SESSION_UPDATE_TOTAL_UNREADMSG_COUNT); //发送已读确认 auto msgBack = msgList.back(); _AsynSendReadAck(msgBack); return TRUE; }
void ReceiveMsgManage::removeMessageBySId(const std::string& sId) { CAutoLock lock(&m_lock); SessionMessage_List* listChatMsg = _getChatMsgListBySID(sId); if (listChatMsg && !listChatMsg->empty()) { listChatMsg->clear(); } }
BOOL ReceiveMsgManage::frontMessageBySId(const std::string& sId, MessageEntity& msg) { CAutoLock lock(&m_lock); SessionMessage_List* listChatMsg = _getChatMsgListBySID(sId); if (listChatMsg && !listChatMsg->empty()) { msg = listChatMsg->back(); return TRUE; } return FALSE; }
BOOL AudioMessageMananger::pushAudioMessageBySId(const std::string& sId, MessageEntity& msg) { SessionMessageMap::iterator it = m_mapUnReadAudioMsg.find(sId); if (it == m_mapUnReadAudioMsg.end()) { SessionMessage_List listChatMsg; listChatMsg.push_back(msg); m_mapUnReadAudioMsg[sId] = listChatMsg; } else { SessionMessage_List& listChatMsg = it->second; listChatMsg.push_back(msg); } return TRUE; }
BOOL ReceiveMsgManage::popMessageBySId(const std::string& sId, MessageEntity& msg) { CAutoLock lock(&m_lock); SessionMessage_List* listChatMsg = _getChatMsgListBySID(sId); if (listChatMsg && !listChatMsg->empty()) { msg = listChatMsg->front(); if (MSG_TYPE_AUDIO_P2P == msg.msgType && !msg.isReaded())//如果是语音未读消息,先存起来 { AudioMessageMananger::getInstance()->pushAudioMessageBySId(sId, msg); } listChatMsg->pop_front(); return TRUE; } return FALSE; }
BOOL ReceiveMsgManage::popMessagesBySId(IN const std::string& sId, OUT SessionMessage_List& msgList, IN MSG_TYPE_STATUS status /*= MESSAGE_TYPE_NONE*/, IN const UINT32 msgId/* = 0*/) { CAutoLock lock(&m_lock); SessionMessage_List* listChatMsg = _getChatMsgListBySID(sId); if (listChatMsg && !listChatMsg->empty()) { SessionMessage_List::iterator it = listChatMsg->begin(); while (it != listChatMsg->end()) { if (MESSAGE_RENDERTYPE_AUDIO == it->msgRenderType && !it->isReaded()) { AudioMessageMananger::getInstance()->pushAudioMessageBySId(sId, *it); } if (MESSAGE_TYPE_NONE == status || it->msgStatusType == status) { if (0 == msgId)//获取该会话符合条件的所有消息 { msgList.push_back(*it); it = listChatMsg->erase(it); } else if (it->msgId <= msgId)//获取这个msgId之前的消息 { msgList.push_back(*it); it = listChatMsg->erase(it); } else { ++it; } } else { ++it; } } return TRUE; } return FALSE; }