mirror of
https://gitee.com/Zhaoxin59/my-chat_-client.git
synced 2026-08-06 06:04:17 +08:00
add data Items
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
#include <QString>
|
||||
#include <QUuid>
|
||||
|
||||
#include "base.qpb.h"
|
||||
|
||||
// 创建命名空间
|
||||
namespace model {
|
||||
///////////////////////////
|
||||
@@ -87,6 +89,21 @@ public:
|
||||
QString description = ""; //用户签名
|
||||
QString phone = ""; //手机号码
|
||||
QIcon avatar; //用户头像
|
||||
|
||||
//从protobuffer的UserInfo对象,转换为当前代码的UserInfo对象
|
||||
void load(const bite_im::UserInfo& userInfo) {
|
||||
this->userId = userInfo.userId();
|
||||
this->nickname = userInfo.nickname();
|
||||
this->phone = userInfo.phone();
|
||||
this->description = userInfo.description();
|
||||
if (userInfo.avatar().isEmpty()) {
|
||||
//使用默认的头像即可
|
||||
this->avatar = QIcon(":resource/image/defaultAvatar.png");
|
||||
}
|
||||
else {
|
||||
this->avatar = makeIcon(userInfo.avatar());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////
|
||||
@@ -126,6 +143,52 @@ static Message makeMessage(MessageType messageType, const QString& chatSessionId
|
||||
}
|
||||
}
|
||||
|
||||
void load(const bite_im::MessageInfo& messageInfo) {
|
||||
this->messageId = messageInfo.messageId();
|
||||
this->chatSessionId = messageInfo.chatSessionId();
|
||||
this->time = formatTime(messageInfo.timestamp());
|
||||
this->sender.load(messageInfo.sender());
|
||||
|
||||
//设置消息的类型
|
||||
auto type = messageInfo.message().messageType();
|
||||
if (type == bite_im::MessageTypeGadget::MessageType::STRING) {
|
||||
this->messageType = TEXT_TYPE;
|
||||
this->content = messageInfo.message().stringMessage().content().toUtf8();
|
||||
}
|
||||
else if (type == bite_im::MessageTypeGadget::MessageType::IMAGE) {
|
||||
this->messageType = IMAGE_TYPE;
|
||||
if (messageInfo.message().imageMessage().hasImageContent()) {
|
||||
this->content = messageInfo.message().imageMessage().imageContent();
|
||||
}
|
||||
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 {
|
||||
// 错误的类型, 啥都不做了, 只是打印一个日志
|
||||
LOG() << "非法的消息类型! type=" << type;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
static QString makeId() {
|
||||
@@ -215,6 +278,33 @@ public:
|
||||
Message lastMessage; //表示会话的最新消息
|
||||
QIcon avatar; //会话的头像(单聊或群聊)
|
||||
QString userId = ""; //(单聊为对方的id,群聊为"")
|
||||
|
||||
|
||||
void load(bite_im::ChatSessionInfo& chatSessionInfo) {
|
||||
this->chatSessionId = chatSessionInfo.chatSessionId();
|
||||
this->chatSessionName = chatSessionInfo.chatSessionName();
|
||||
if (chatSessionInfo.hasSingleChatFriendId()) {
|
||||
this->userId = chatSessionInfo.singleChatFriendId();
|
||||
}
|
||||
if (chatSessionInfo.hasPrevMessage()) {
|
||||
lastMessage.load(chatSessionInfo.prevMessage());
|
||||
}
|
||||
if (chatSessionInfo.hasAvatar() && !chatSessionInfo.avatar().isEmpty()) {
|
||||
//如果有头像,则设置这个头像
|
||||
this->avatar = makeIcon(chatSessionInfo.avatar());
|
||||
}
|
||||
else {
|
||||
//如果没有,则会根据是单聊还是群聊,使用不同的默认头像
|
||||
if (userId != "") {
|
||||
//单聊
|
||||
this->avatar = QIcon(":/resource/image/defaultAvatar.png");
|
||||
}
|
||||
else {
|
||||
//群聊
|
||||
this->avatar = QIcon(":/resource/image/groupAvatar.png");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} //end namespace model
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "datacenter.h"
|
||||
|
||||
namespace model
|
||||
{
|
||||
DataCenter* DataCenter::instance = nullptr;
|
||||
|
||||
DataCenter* DataCenter::getInstance()
|
||||
{
|
||||
if (instance == nullptr) {
|
||||
instance = new DataCenter();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DataCenter::DataCenter()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "data.h"
|
||||
|
||||
namespace model
|
||||
{
|
||||
|
||||
class DataCenter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static DataCenter* getInstance();
|
||||
|
||||
/// <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>* firendList = nullptr;
|
||||
|
||||
//会话列表
|
||||
QList<ChatSessionInfo>* chatSessionList = nullptr;
|
||||
|
||||
//记录当前选中的会话是哪个
|
||||
QString currentChatSession = "";
|
||||
|
||||
//记录每个会话中,都有哪些成员
|
||||
QHash<QString, QList<UserInfo>>* memberList = nullptr;//unordered_map
|
||||
|
||||
//待处理的好友申请列表
|
||||
QList<UserInfo>* applyList = nullptr;
|
||||
|
||||
signals:
|
||||
};
|
||||
} //end namespace model
|
||||
Reference in New Issue
Block a user