mirror of
https://gitee.com/Zhaoxin59/my-chat_-client.git
synced 2026-02-14 00:51:48 +08:00
add data Items
This commit is contained in:
90
model/data.h
90
model/data.h
@ -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
|
||||
|
||||
Reference in New Issue
Block a user