void CMessageModel::getUnReadCntAll(uint32_t nUserId, uint32_t &nTotalCnt) { CacheManager* pCacheManager = CacheManager::getInstance(); CacheConn* pCacheConn = pCacheManager->GetCacheConn("unread"); if (pCacheConn) { map<string, string> mapUnread; string strKey = "unread_" + int2string(nUserId); bool bRet = pCacheConn->hgetAll(strKey, mapUnread); pCacheManager->RelCacheConn(pCacheConn); if(bRet) { for (auto it = mapUnread.begin(); it != mapUnread.end(); it++) { nTotalCnt += atoi(it->second.c_str()); } } else { log("hgetall %s failed!", strKey.c_str()); } } else { log("no cache connection for unread"); } }
void CMessageModel::getUnreadMsgCount(uint32_t nUserId, uint32_t &nTotalCnt, list<IM::BaseDefine::UnreadInfo>& lsUnreadCount) { CacheManager* pCacheManager = CacheManager::getInstance(); CacheConn* pCacheConn = pCacheManager->GetCacheConn("unread"); if (pCacheConn) { map<string, string> mapUnread; string strKey = "unread_" + int2string(nUserId); bool bRet = pCacheConn->hgetAll(strKey, mapUnread); pCacheManager->RelCacheConn(pCacheConn); if(bRet) { IM::BaseDefine::UnreadInfo cUnreadInfo; for (auto it = mapUnread.begin(); it != mapUnread.end(); it++) { cUnreadInfo.set_session_id(atoi(it->first.c_str())); cUnreadInfo.set_unread_cnt(atoi(it->second.c_str())); cUnreadInfo.set_session_type(IM::BaseDefine::SESSION_TYPE_SINGLE); uint32_t nMsgId = 0; string strMsgData; IM::BaseDefine::MsgType nMsgType; getLastMsg(cUnreadInfo.session_id(), nUserId, nMsgId, strMsgData, nMsgType); if(IM::BaseDefine::MsgType_IsValid(nMsgType)) { cUnreadInfo.set_latest_msg_id(nMsgId); cUnreadInfo.set_latest_msg_data(strMsgData); cUnreadInfo.set_latest_msg_type(nMsgType); cUnreadInfo.set_latest_msg_from_user_id(cUnreadInfo.session_id()); lsUnreadCount.push_back(cUnreadInfo); nTotalCnt += cUnreadInfo.unread_cnt(); } else { log("invalid msgType. userId=%u, peerId=%u, msgType=%u", nUserId, cUnreadInfo.session_id(), nMsgType); } } } else { log("hgetall %s failed!", strKey.c_str()); } } else { log("no cache connection for unread"); } }