add recent session message

This commit is contained in:
xyz
2025-06-17 18:40:02 +08:00
parent e4ec73b510
commit c50f574eed
9 changed files with 423 additions and 7 deletions

View File

@ -189,4 +189,106 @@ namespace model
}
QList<ChatSessionInfo>* DataCenter::getChatSessionList()
{
return chatSessionList;
}
void DataCenter::getChatSessionListAsync()
{
netClient.getChatSessionList(loginSessionId);
}
void DataCenter::resetChatSessionList(std::shared_ptr<bite_im::GetChatSessionListRsp> resp)
{
if (chatSessionList == nullptr) {
chatSessionList = new QList<ChatSessionInfo>();
}
chatSessionList->clear();
auto& chatSessionListPB = resp->chatSessionInfoList();
for (auto& c : chatSessionListPB) {
ChatSessionInfo chatSessionInfo;
chatSessionInfo.load(const_cast<bite_im::ChatSessionInfo&>(c));
chatSessionList->push_back(chatSessionInfo);
}
}
QList<UserInfo>* DataCenter::getApplyList()
{
return applyList;
}
void DataCenter::getApplyListAsync()
{
netClient.getApplyList(loginSessionId);
}
void DataCenter::resetApplyList(std::shared_ptr<bite_im::GetPendingFriendEventListRsp> resp)
{
if (applyList == nullptr) {
applyList = new QList<UserInfo>();
}
applyList->clear();
auto& eventList = resp->event();
for (auto& event : eventList) {
UserInfo userInfo;
userInfo.load(event.sender());
applyList->push_back(userInfo);
}
}
void DataCenter::getRecnetMessageListAsync(const QString& chatSessionId)
{
netClient.getRecentMessageList(loginSessionId, chatSessionId);
}
QList<Message>* DataCenter::getRecentMessageList(const QString& chatSessionId)
{
if (!recentMessages->contains(chatSessionId)) {
return nullptr;
}
return &(*recentMessages)[chatSessionId];
}
void DataCenter::resetRecentMessageList(const QString& chatSessionId, std::shared_ptr<bite_im::GetRecentMsgRsp> resp)
{
//拿到chatSessionId 对应的消息列表,并清空
//注意此处务必使用的是引用类型,才是修改哈希表内部的内容
QList<Message>& messageList = (*recentMessages)[chatSessionId];
messageList.clear();
//遍历响应结果列表
for (auto& m : resp->msgList()) {
Message message;
message.load(m);
messageList.push_back(message);
}
}
ChatSessionInfo* DataCenter::findChatSessionById(const QString& chatSessionId)
{
if (chatSessionList == nullptr) {
return nullptr;
}
for (auto& info : *chatSessionList) {
if (info.chatSessionId == chatSessionId) {
return &info;
}
}
return nullptr;
}
void DataCenter::setCurrentChatSessionId(const QString& chatSessionId)
{
this->currentChatSessionId = chatSessionId;
}
const QString& DataCenter::getCurrentSessionId()
{
return currentChatSessionId;
}
} //end namespace model