mirror of
https://gitee.com/Zhaoxin59/my-chat_-client.git
synced 2026-02-13 16:41:48 +08:00
197 lines
5.6 KiB
C++
197 lines
5.6 KiB
C++
#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(); }
|
||
|
||
//通过网络获取到用户的个人信息
|
||
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 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);
|
||
|
||
///////////////////////////////////////////////////////////////////////////////////
|
||
///辅助函数
|
||
///////////////////////////////////////////////////////////////////////////////
|
||
|
||
//根据会话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();
|
||
void changePhoneDone();
|
||
void changeAvatarDone();
|
||
};
|
||
} //end namespace model
|