mirror of
https://gitee.com/Zhaoxin59/my-chat_-client.git
synced 2026-02-14 17:11:48 +08:00
has been completed.
This commit is contained in:
@ -163,6 +163,11 @@ namespace model
|
||||
return (*unreadMessageCount)[chatSessionId];
|
||||
}
|
||||
|
||||
void DataCenter::initWebsocket()
|
||||
{
|
||||
netClient.initWebSocket();
|
||||
}
|
||||
|
||||
void DataCenter::getMyselfAsync()
|
||||
{
|
||||
//DataCenter 只是负责“处理数据”,
|
||||
@ -294,6 +299,21 @@ namespace model
|
||||
netClient.sendMessage(loginSessionId, chatSessionId, MessageType::TEXT_TYPE, content.toUtf8(), "");
|
||||
}
|
||||
|
||||
void DataCenter::sendImageMessageAsync(const QString& chatSessionId, const QByteArray& content)
|
||||
{
|
||||
netClient.sendMessage(loginSessionId, chatSessionId, MessageType::IMAGE_TYPE, content, "");
|
||||
}
|
||||
|
||||
void DataCenter::sendFileMessageAsync(const QString& chatSessionId, const QString& fileName, const QByteArray& content)
|
||||
{
|
||||
netClient.sendMessage(loginSessionId, chatSessionId, MessageType::FILE_TYPE, content, fileName);
|
||||
}
|
||||
|
||||
void DataCenter::sendSpeechMessageAsync(const QString& chatSessionId, const QByteArray& content)
|
||||
{
|
||||
netClient.sendMessage(loginSessionId, chatSessionId, MessageType::SPEECH_TYPE, content, "");
|
||||
}
|
||||
|
||||
void DataCenter::changeNicknameAsync(const QString& nickname)
|
||||
{
|
||||
netClient.changeNickname(loginSessionId, nickname);
|
||||
@ -350,6 +370,195 @@ namespace model
|
||||
myself->phone = email;
|
||||
}
|
||||
|
||||
void DataCenter::deleteFriendAsync(const QString& userId)
|
||||
{
|
||||
netClient.deleteFriend(loginSessionId, userId);
|
||||
}
|
||||
|
||||
void DataCenter::removeFriend(const QString& userId)
|
||||
{
|
||||
//遍历friendList 找到要删除的匹配的好友元素
|
||||
if (friendList == nullptr || chatSessionList == nullptr) {
|
||||
return;
|
||||
}
|
||||
friendList->removeIf([=](const UserInfo& userInfo) {
|
||||
//说明就是这个
|
||||
return userInfo.userId == userId;
|
||||
});
|
||||
|
||||
//考虑到会话列表
|
||||
//删除会话操作,客户端和服务器都会删除
|
||||
chatSessionList->removeIf([=](const ChatSessionInfo& chatSessionInfo) {
|
||||
if (chatSessionInfo.userId == "") {
|
||||
//群聊,不受影响
|
||||
return false;
|
||||
}
|
||||
if (chatSessionInfo.userId == userId) {
|
||||
//此处如果删除的会话正是用户正在选中的会话,此时就需要把当前选中会话的内容都清空
|
||||
if (chatSessionInfo.chatSessionId == this->currentChatSessionId) {
|
||||
emit this->clearCurrentSession();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
void DataCenter::addFriendApplyAsync(const QString& userId)
|
||||
{
|
||||
netClient.addFriendApply(loginSessionId, userId);
|
||||
}
|
||||
|
||||
void DataCenter::acceptFriendApplyAsync(const QString& userId)
|
||||
{
|
||||
netClient.acceptFriendApply(loginSessionId, userId);
|
||||
}
|
||||
|
||||
UserInfo DataCenter::removeFromApplyList(const QString& userId)
|
||||
{
|
||||
if (applyList == nullptr) {
|
||||
return UserInfo();
|
||||
}
|
||||
|
||||
for (auto it = applyList->begin(); it != applyList->end(); ++it) {
|
||||
if (it->userId == userId) {
|
||||
//复制要删除的对象,进行返回
|
||||
UserInfo toDelete = *it;
|
||||
applyList->erase(it);
|
||||
return toDelete;
|
||||
}
|
||||
}
|
||||
return UserInfo();
|
||||
}
|
||||
|
||||
void DataCenter::rejectFriendApplyAsync(const QString& userId)
|
||||
{
|
||||
netClient.rejectFriendApply(loginSessionId, userId);
|
||||
}
|
||||
|
||||
void DataCenter::createGroupChatSessionAsync(const QList<QString>& userIdList)
|
||||
{
|
||||
netClient.createGroupChatSession(loginSessionId, userIdList);
|
||||
}
|
||||
|
||||
void DataCenter::getMemberListAsync(const QString& chatSessionId)
|
||||
{
|
||||
netClient.getMemberList(loginSessionId, chatSessionId);
|
||||
}
|
||||
|
||||
QList<UserInfo>* DataCenter::getMemberList(const QString& chatSessionId)
|
||||
{
|
||||
if (!this->memberList->contains(chatSessionId)) return nullptr;
|
||||
return &(*this->memberList)[chatSessionId];
|
||||
}
|
||||
|
||||
void DataCenter::resetMemberList(const QString& chatSessionId, const QList<bite_im::UserInfo>& memberList)
|
||||
{
|
||||
//根据chatSessionId,这个key,得到对应的value(QList)
|
||||
QList<UserInfo>& currentMemberList = (*this->memberList)[chatSessionId];
|
||||
currentMemberList.clear();
|
||||
|
||||
for (const auto& m : memberList) {
|
||||
UserInfo userInfo;
|
||||
userInfo.load(m);
|
||||
currentMemberList.push_back(userInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void DataCenter::searchUserAsync(const QString& searchKey)
|
||||
{
|
||||
netClient.searchUser(loginSessionId, searchKey);
|
||||
}
|
||||
|
||||
QList<UserInfo>* DataCenter::getSearchUserResult()
|
||||
{
|
||||
return searchUserResult;
|
||||
}
|
||||
|
||||
void DataCenter::resetSearchUserResult(const QList<bite_im::UserInfo>& userList)
|
||||
{
|
||||
if (searchUserResult == nullptr) {
|
||||
searchUserResult = new QList<UserInfo>();
|
||||
}
|
||||
searchUserResult->clear();
|
||||
|
||||
for (const auto& u : userList) {
|
||||
UserInfo userInfo;
|
||||
userInfo.load(u);
|
||||
searchUserResult->push_back(userInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void DataCenter::searchMessageAsync(const QString& searchKey)
|
||||
{
|
||||
//搜索历史消息,根据会话来组织
|
||||
netClient.searchMessage(loginSessionId, this->currentChatSessionId, searchKey);
|
||||
}
|
||||
|
||||
void DataCenter::searchMessageByTimeAsync(const QDateTime& begTime, const QDateTime& endTime)
|
||||
{
|
||||
netClient.searchMessageByTime(loginSessionId, currentChatSessionId, begTime, endTime);
|
||||
}
|
||||
|
||||
QList<Message>* DataCenter::getSearchMessageReuslt()
|
||||
{
|
||||
return searchMessageResult;
|
||||
}
|
||||
|
||||
void DataCenter::resetSearchMessageResult(const QList<bite_im::MessageInfo>& msgList)
|
||||
{
|
||||
if (this->searchMessageResult == nullptr) {
|
||||
this->searchMessageResult = new QList<Message>();
|
||||
}
|
||||
this->searchMessageResult->clear();
|
||||
|
||||
for (const auto& m : msgList) {
|
||||
Message message;
|
||||
message.load(m);
|
||||
searchMessageResult->push_back(message);
|
||||
}
|
||||
}
|
||||
|
||||
void DataCenter::userLoginAsync(const QString& username, const QString& password)
|
||||
{
|
||||
//登录操作,没有loginSessionId
|
||||
//登录成功之后,服务器才会返回loginSessionId
|
||||
netClient.userLogin(username, password);
|
||||
}
|
||||
|
||||
void DataCenter::resetLoginSessionId(const QString& loginSessionId)
|
||||
{
|
||||
this->loginSessionId = loginSessionId;
|
||||
|
||||
//一旦会话id更改,就保存到硬盘上
|
||||
saveDataFile();
|
||||
}
|
||||
|
||||
void DataCenter::userRegisterAsync(const QString& username, const QString& password)
|
||||
{
|
||||
netClient.userRegister(username, password);
|
||||
}
|
||||
|
||||
void DataCenter::phoneLoginAsync(const QString& phone, const QString& verifyCode)
|
||||
{
|
||||
netClient.phoneLogin(phone, this->currentVerifyCodeId, verifyCode);
|
||||
}
|
||||
|
||||
void DataCenter::phoneRegisterAsync(const QString& phone, const QString& verifyCode)
|
||||
{
|
||||
netClient.phoneRegister(phone, this->currentVerifyCodeId, verifyCode);
|
||||
}
|
||||
|
||||
void DataCenter::getSingleFileAsync(const QString& fileId)
|
||||
{
|
||||
netClient.getSingleFile(loginSessionId, fileId);
|
||||
}
|
||||
|
||||
void DataCenter::speechConvertTextAsync(const QString& fileId, const QByteArray& content)
|
||||
{
|
||||
netClient.speechConvertText(loginSessionId, fileId, content);
|
||||
}
|
||||
|
||||
void DataCenter::changeAvatarAsync(const QByteArray& imageBytes)
|
||||
{
|
||||
netClient.changeAvatar(loginSessionId, imageBytes);
|
||||
|
||||
Reference in New Issue
Block a user