mirror of
https://gitee.com/Zhaoxin59/my-chat_-client.git
synced 2026-02-14 00:51:48 +08:00
refactor: 大规模调整项目目录结构,将ChatClient和ChatServer整合为Monorepo结构,并分为两个独立文件夹:chatclient/ 和 chatserver/。更新了ChatClient的CMakeLists.txt配置以适配新结构。
This commit is contained in:
265
ChatClient/include/model/datacenter.h
Normal file
265
ChatClient/include/model/datacenter.h
Normal file
@ -0,0 +1,265 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <qstandardpaths.h>
|
||||
#include <QDir>
|
||||
#include <QJsonObject>
|
||||
|
||||
//#include <QList>
|
||||
|
||||
#include "data.h"
|
||||
#include "../network/netclient.h"
|
||||
|
||||
namespace model
|
||||
{
|
||||
|
||||
class DataCenter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static DataCenter* getInstance();
|
||||
|
||||
~DataCenter();
|
||||
/// <summary>
|
||||
/// 计算两个整数的和。
|
||||
/// </summary>
|
||||
/// <param name="a">第一个加数</param>
|
||||
/// <param name="b">第二个加数</param>
|
||||
/// <returns>返回 a + b 的结果</returns>
|
||||
/*int add(int a, int b) {
|
||||
return a + b;
|
||||
}*/
|
||||
|
||||
private:
|
||||
DataCenter();
|
||||
|
||||
static DataCenter* instance;
|
||||
|
||||
//列出DataCenter中要组织管理的所有数据
|
||||
|
||||
//当前客户端登录到服务器对应的登录会话Id
|
||||
QString loginSessionId;
|
||||
|
||||
//当前的用户信息
|
||||
UserInfo* myself = nullptr;
|
||||
|
||||
//好友列表
|
||||
QList<UserInfo>* friendList = nullptr;
|
||||
|
||||
//会话列表
|
||||
QList<ChatSessionInfo>* chatSessionList = nullptr;
|
||||
|
||||
//记录当前选中的会话是哪个
|
||||
QString currentChatSessionId = "";
|
||||
|
||||
//记录每个会话中,都有哪些成员
|
||||
QHash<QString, QList<UserInfo>>* memberList = nullptr;//unordered_map
|
||||
|
||||
//待处理的好友申请列表
|
||||
QList<UserInfo>* applyList = nullptr;
|
||||
|
||||
//每个会话最近消息的列表,key为chatSessionId,value为消息列表
|
||||
QHash<QString, QList<Message>>* recentMessages = nullptr;
|
||||
|
||||
//存储每个会话,表示未读消息的数量
|
||||
QHash<QString, int>* unreadMessageCount = nullptr;
|
||||
|
||||
// 用户的好友搜索结果
|
||||
QList<UserInfo>* searchUserResult = nullptr;
|
||||
|
||||
//保存一个历史消息搜索结果
|
||||
QList<Message>* searchMessageResult = nullptr;
|
||||
|
||||
//短信(邮箱)验证码的验证Id
|
||||
QString currentVerifyCodeId = "";
|
||||
|
||||
//让dataCenter持有Netclient实例
|
||||
network::NetClient netClient;
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// 初始化数据文件
|
||||
/// </summary>
|
||||
void initDataFile();
|
||||
|
||||
//存储数据到文件中
|
||||
void saveDataFile();
|
||||
|
||||
//从数据文件中加载数据到内存
|
||||
void loadDataFile();
|
||||
|
||||
//清空未读消息数目
|
||||
void clearUnread(const QString& chatSessionId);
|
||||
|
||||
//增加未读消息的数目
|
||||
void addUnread(const QString& chatSessionId);
|
||||
|
||||
//获取未读消息的数目
|
||||
int getUnread(const QString& chatSessionId);
|
||||
|
||||
//获取到当前的登录会话Id
|
||||
const QString& getLoginSessionId() const{
|
||||
return loginSessionId;
|
||||
}
|
||||
|
||||
//验证网络的连通性
|
||||
void ping() { netClient.ping(); }
|
||||
|
||||
//针对netclient中的websocket进行初始化
|
||||
void initWebsocket();
|
||||
|
||||
//通过网络获取到用户的个人信息
|
||||
void getMyselfAsync();
|
||||
|
||||
UserInfo* getMyselfsync();
|
||||
//
|
||||
void resetMyself(std::shared_ptr<bite_im::GetUserInfoRsp> resp);
|
||||
|
||||
//通过网络获取好友列表
|
||||
QList<UserInfo>* getFriendList();
|
||||
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, bool updateUI);
|
||||
QList<Message>* getRecentMessageList(const QString& chatSessionId);
|
||||
void resetRecentMessageList(const QString& chatSessionId, std::shared_ptr<bite_im::GetRecentMsgRsp> resp);
|
||||
|
||||
//发送消息给服务器
|
||||
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);
|
||||
void resetNickname(const QString& nickname);
|
||||
|
||||
//修改用户签名
|
||||
void changeDescriptionAsync(const QString& desc);
|
||||
void resetDescription(const QString& desc);
|
||||
|
||||
//获取邮箱验证码
|
||||
void getVerifyCodeAsync(const QString& email);
|
||||
void resetVerifyCodeId(const QString& verifyCodeId);
|
||||
|
||||
//获取verifyCodeId
|
||||
const QString& getVerifyCodeId() const;
|
||||
|
||||
//修改邮箱号码
|
||||
void changePhoneAsync(const QString& email, const QString& verifyCodeId, const QString& verifyCode);
|
||||
void resetPhone(const QString& email);
|
||||
|
||||
//修改头像
|
||||
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);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
///辅助函数
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//根据会话id查询会话信息
|
||||
ChatSessionInfo* findChatSessionById(const QString& chatSessionId);
|
||||
//根据用户ID查询会话信息
|
||||
ChatSessionInfo* findChatSessionByUserId(const QString& userId);
|
||||
//把指定的会话信息,放到列表头部
|
||||
void topCurrentChatSessionId(const ChatSessionInfo& chatSessionInfo);
|
||||
//根据用户id查询好友信息
|
||||
UserInfo* findFriendById(const QString& userId);
|
||||
|
||||
//设置/获取当前选中的会话
|
||||
void setCurrentChatSessionId(const QString& chatSessionId);
|
||||
const QString& getCurrentSessionId();
|
||||
|
||||
//添加消息到DataCenter中
|
||||
void addMessage(const Message& message);
|
||||
signals:
|
||||
//自定义信号
|
||||
void getMyselfDone();
|
||||
void getFriendListDone();
|
||||
void getChatSessionListDone();
|
||||
void getApplyListDone();
|
||||
void getRecentMessageListDone(const QString& chatSessionId);
|
||||
void getRecentMessageListDoneNoUI(const QString& chatSessionId);
|
||||
void sendMessageDone(MessageType messageType, const QByteArray& content, const QString& extraInfo);
|
||||
void updateLastMessage(const QString& chatSessionId);
|
||||
void receiveMessageDone(const Message& lastMessage);
|
||||
void changeNicknameDone();
|
||||
void changeDescriptionDone();
|
||||
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