mirror of
https://gitee.com/Zhaoxin59/my-chat_-client.git
synced 2026-02-14 09:01:50 +08:00
has been completed.
This commit is contained in:
44
model/data.h
44
model/data.h
@ -170,30 +170,30 @@ void load(const bite_im::MessageInfo& messageInfo) {
|
||||
}
|
||||
if (messageInfo.message().imageMessage().hasFileId()) {
|
||||
this->fileId = messageInfo.message().imageMessage().fileId();
|
||||
}else if (type == bite_im::MessageTypeGadget::MessageType::FILE) {
|
||||
this->messageType = FILE_TYPE;
|
||||
if (messageInfo.message().fileMessage().hasFileContents()) {
|
||||
this->content = messageInfo.message().fileMessage().fileContents();
|
||||
}
|
||||
if (messageInfo.message().fileMessage().hasFileId()) {
|
||||
this->fileId = messageInfo.message().fileMessage().fileId();
|
||||
}
|
||||
this->fileName = messageInfo.message().fileMessage().fileName();
|
||||
}
|
||||
else if (type == bite_im::MessageTypeGadget::MessageType::SPEECH) {
|
||||
this->messageType = SPEECH_TYPE;
|
||||
if (messageInfo.message().speechMessage().hasFileContents()) {
|
||||
this->content = messageInfo.message().speechMessage().fileContents();
|
||||
}
|
||||
if (messageInfo.message().speechMessage().hasFileId()) {
|
||||
this->fileId = messageInfo.message().speechMessage().fileId();
|
||||
}
|
||||
}
|
||||
else if (type == bite_im::MessageTypeGadget::MessageType::FILE) {
|
||||
this->messageType = FILE_TYPE;
|
||||
if (messageInfo.message().fileMessage().hasFileContents()) {
|
||||
this->content = messageInfo.message().fileMessage().fileContents();
|
||||
}
|
||||
else {
|
||||
// 错误的类型, 啥都不做了, 只是打印一个日志
|
||||
LOG() << "非法的消息类型! type=" << type;
|
||||
if (messageInfo.message().fileMessage().hasFileId()) {
|
||||
this->fileId = messageInfo.message().fileMessage().fileId();
|
||||
}
|
||||
|
||||
this->fileName = messageInfo.message().fileMessage().fileName();
|
||||
}
|
||||
else if (type == bite_im::MessageTypeGadget::MessageType::SPEECH) {
|
||||
this->messageType = SPEECH_TYPE;
|
||||
if (messageInfo.message().speechMessage().hasFileContents()) {
|
||||
this->content = messageInfo.message().speechMessage().fileContents();
|
||||
}
|
||||
if (messageInfo.message().speechMessage().hasFileId()) {
|
||||
this->fileId = messageInfo.message().speechMessage().fileId();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 错误的类型, 啥都不做了, 只是打印一个日志
|
||||
LOG() << "非法的消息类型! type=" << type;
|
||||
}
|
||||
}
|
||||
|
||||
@ -288,7 +288,7 @@ public:
|
||||
QString userId = ""; //(单聊为对方的id,群聊为"")
|
||||
|
||||
|
||||
void load(bite_im::ChatSessionInfo& chatSessionInfo) {
|
||||
void load(const bite_im::ChatSessionInfo& chatSessionInfo) {
|
||||
this->chatSessionId = chatSessionInfo.chatSessionId();
|
||||
this->chatSessionName = chatSessionInfo.chatSessionName();
|
||||
if (chatSessionInfo.hasSingleChatFriendId()) {
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include <qstandardpaths.h>
|
||||
#include <QDir>
|
||||
#include <QJsonObject>
|
||||
|
||||
//#include <QList>
|
||||
|
||||
#include "data.h"
|
||||
@ -104,6 +105,9 @@ namespace model
|
||||
//验证网络的连通性
|
||||
void ping() { netClient.ping(); }
|
||||
|
||||
//针对netclient中的websocket进行初始化
|
||||
void initWebsocket();
|
||||
|
||||
//通过网络获取到用户的个人信息
|
||||
void getMyselfAsync();
|
||||
|
||||
@ -133,6 +137,9 @@ namespace model
|
||||
|
||||
//发送消息给服务器
|
||||
void sendTextMessageAsync(const QString& chatSessionId, const QString& content);
|
||||
void sendImageMessageAsync(const QString& chatSessionId, const QByteArray& content);
|
||||
void sendFileMessageAsync(const QString& chatSessionId, const QString& fileName, const QByteArray& content);
|
||||
void sendSpeechMessageAsync(const QString& chatSessionId, const QByteArray& content);
|
||||
|
||||
//修改用户昵称
|
||||
void changeNicknameAsync(const QString& nickname);
|
||||
@ -157,6 +164,50 @@ namespace model
|
||||
void changeAvatarAsync(const QByteArray& imageBytes);
|
||||
void resetAvatar(const QByteArray& avatar);
|
||||
|
||||
//删除好友
|
||||
void deleteFriendAsync(const QString& userId);
|
||||
void removeFriend(const QString& userId);
|
||||
void addFriendApplyAsync(const QString& userId);
|
||||
|
||||
//发送同意好友申请操作
|
||||
void acceptFriendApplyAsync(const QString& userId);
|
||||
UserInfo removeFromApplyList(const QString& userId);
|
||||
|
||||
//拒绝好友申请操作
|
||||
void rejectFriendApplyAsync(const QString& userId);
|
||||
|
||||
//创建群聊
|
||||
void createGroupChatSessionAsync(const QList<QString>& userIdList);
|
||||
|
||||
//获取会话成员列表
|
||||
void getMemberListAsync(const QString& chatSessionId);
|
||||
QList<UserInfo>* getMemberList(const QString& chatSessionId);
|
||||
void resetMemberList(const QString& chatSessionId, const QList<bite_im::UserInfo>& memberList);
|
||||
|
||||
//搜索用户
|
||||
void searchUserAsync(const QString& searchKey);
|
||||
QList<UserInfo>* getSearchUserResult();
|
||||
void resetSearchUserResult(const QList<bite_im::UserInfo>& userList);
|
||||
|
||||
//搜索历史消息
|
||||
void searchMessageAsync(const QString& searchKey);
|
||||
void searchMessageByTimeAsync(const QDateTime& begTime, const QDateTime& endTime);
|
||||
QList<Message>* getSearchMessageReuslt();
|
||||
void resetSearchMessageResult(const QList<bite_im::MessageInfo>& msgList);
|
||||
|
||||
//登录注册
|
||||
void userLoginAsync(const QString& username, const QString& password);
|
||||
void resetLoginSessionId(const QString& loginSessionId);
|
||||
void userRegisterAsync(const QString& username, const QString& password);
|
||||
void phoneLoginAsync(const QString& phone, const QString& verifyCode);
|
||||
void phoneRegisterAsync(const QString& phone, const QString& verifyCode);
|
||||
|
||||
//获取单个文件
|
||||
void getSingleFileAsync(const QString& fileId);
|
||||
|
||||
//语音转文字
|
||||
void speechConvertTextAsync(const QString& fileId, const QByteArray& content);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
///辅助函数
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -189,8 +240,26 @@ namespace model
|
||||
void receiveMessageDone(const Message& lastMessage);
|
||||
void changeNicknameDone();
|
||||
void changeDescriptionDone();
|
||||
void getVerifyCodeDone();
|
||||
void getVerifyCodeDone(bool ok);
|
||||
void changePhoneDone();
|
||||
void changeAvatarDone();
|
||||
void deleteFriendDone();
|
||||
void clearCurrentSession();
|
||||
void addFriendApplyDone();
|
||||
void receiveFriendApplyDone();
|
||||
void acceptFriendApplyDone();
|
||||
void rejectFriendApplyDone();
|
||||
void receiveFriendProcessDone(const QString& nickname, bool agree);
|
||||
void createGroupChatSessionDone();
|
||||
void receiveSessionCreateDone();
|
||||
void getMemberListDone(const QString& chatSessionId);
|
||||
void searchUserDone();
|
||||
void searchMessageDone();
|
||||
void userLoginDone(bool ok, const QString& reason);
|
||||
void userRegisterDone(bool ok, const QString& reason);
|
||||
void phoneLoginDone(bool ok, const QString& reason);
|
||||
void phoneRegisterDone(bool ok, const QString& reason);
|
||||
void getSingleFileDone(const QString& fileId, const QByteArray& fileContent);
|
||||
void speechConvertTextDone(const QString& fileId, const QString& text);
|
||||
};
|
||||
} //end namespace model
|
||||
|
||||
Reference in New Issue
Block a user