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

View File

@ -49,7 +49,7 @@ namespace model
QList<ChatSessionInfo>* chatSessionList = nullptr;
//记录当前选中的会话是哪个
QString currentChatSession = "";
QString currentChatSessionId = "";
//记录每个会话中,都有哪些成员
QHash<QString, QList<UserInfo>>* memberList = nullptr;//unordered_map
@ -107,9 +107,33 @@ namespace model
void getFriendListAsync();
void resetFriendList(std::shared_ptr<bite_im::GetFriendListRsp> resp);
//获取会话列表
QList<ChatSessionInfo>* getChatSessionList();
void getChatSessionListAsync();
void resetChatSessionList(std::shared_ptr<bite_im::GetChatSessionListRsp> resp);
//获取好友申请列表
QList<UserInfo>* getApplyList();
void getApplyListAsync();
void resetApplyList(std::shared_ptr<bite_im::GetPendingFriendEventListRsp> resp);
//获取最近的消息列表
void getRecnetMessageListAsync(const QString& chatSessionId);
QList<Message>* getRecentMessageList(const QString& chatSessionId);
void resetRecentMessageList(const QString& chatSessionId, std::shared_ptr<bite_im::GetRecentMsgRsp> resp);
//根据会话id查询会话信息
ChatSessionInfo* findChatSessionById(const QString& chatSessionId);
//设置/获取当前选中的会话
void setCurrentChatSessionId(const QString& chatSessionId);
const QString& getCurrentSessionId();
signals:
//自定义信号
void getMyselfDone();
void getFriendListDone();
void getChatSessionListDone();
void getApplyListDone();
void getRecentMessageListDone(const QString& chatSessionId);
};
} //end namespace model