add sendMessage function

This commit is contained in:
xyz
2025-06-18 18:21:23 +08:00
parent c50f574eed
commit 971ab64769
11 changed files with 319 additions and 9 deletions

View File

@ -268,6 +268,11 @@ namespace model
}
}
void DataCenter::sendTextMessageAsync(const QString& chatSessionId, const QString& content)
{
netClient.sendMessage(loginSessionId, chatSessionId, MessageType::TEXT_TYPE, content.toUtf8(), "");
}
ChatSessionInfo* DataCenter::findChatSessionById(const QString& chatSessionId)
{
if (chatSessionList == nullptr) {
@ -281,6 +286,46 @@ namespace model
return nullptr;
}
ChatSessionInfo* DataCenter::findChatSessionByUserId(const QString& userId)
{
if (chatSessionList == nullptr) {
return nullptr;
}
for (auto& info : *chatSessionList) {
if (info.userId == userId) {
return &info;
}
}
return nullptr;
}
void DataCenter::topCurrentChatSessionId(const ChatSessionInfo& chatSessionInfo)
{
if (chatSessionList == nullptr) {
return;
}
//把这个元素从列表中找到
auto it = chatSessionList->begin();
for (; it != chatSessionList->end(); ++it) {
if (it->chatSessionId == chatSessionInfo.chatSessionId) {
break;
}
}
if (it == chatSessionList->end()) {
//上面的循环没有找到匹配的元素,直接返回,正常来说,不会走这个逻辑
return;
}
//删除并重新插入头部
ChatSessionInfo backup = chatSessionInfo;
chatSessionList->erase(it);
//把备份的元素插入到头部
chatSessionList->push_front(backup);
}
void DataCenter::setCurrentChatSessionId(const QString& chatSessionId)
{
this->currentChatSessionId = chatSessionId;
@ -291,4 +336,10 @@ namespace model
return currentChatSessionId;
}
void DataCenter::addMessage(const Message& message)
{
QList<Message>& messageList = (*recentMessages)[message.chatSessionId];
messageList.push_back(message);
}
} //end namespace model