mirror of
https://gitee.com/Zhaoxin59/my-chat_-client.git
synced 2026-02-14 00:51:48 +08:00
add recent session message
This commit is contained in:
@ -144,7 +144,7 @@ namespace network {
|
||||
});
|
||||
}
|
||||
|
||||
void NetClient::getFriendList(const QString loginSessionId)
|
||||
void NetClient::getFriendList(const QString& loginSessionId)
|
||||
{
|
||||
//通过protobuf构造body
|
||||
bite_im::GetFriendListReq req;
|
||||
@ -175,4 +175,112 @@ namespace network {
|
||||
emit dataCenter->getFriendListDone();
|
||||
});
|
||||
}
|
||||
|
||||
void NetClient::getChatSessionList(const QString& loginSessionId)
|
||||
{
|
||||
//通过protobuf构造body
|
||||
bite_im::GetChatSessionListReq req;
|
||||
req.setRequestId(makeRequestId());
|
||||
req.setSessionId(loginSessionId);
|
||||
QByteArray body = req.serialize(&serializer);
|
||||
|
||||
LOG() << "获取会话列表->发送请求 requestId= " << req.requestId() << ", loginSessionId= " << loginSessionId;
|
||||
|
||||
//发送HTTP请求
|
||||
QNetworkReply* resp = this->sendHttpRequest("/service/friend/get_chat_session_list", body);
|
||||
|
||||
//针对响应进行处理
|
||||
connect(resp, &QNetworkReply::finished, this, [=]() {
|
||||
//解析响应
|
||||
bool ok = false;
|
||||
QString reason;
|
||||
auto pbResp = this->handleHttpResponse<bite_im::GetChatSessionListRsp>(resp, &ok, &reason);
|
||||
|
||||
//判断响应是否正确
|
||||
if (!ok) {
|
||||
LOG() << "获取会话列表->失败 reason= " << reason;
|
||||
return;
|
||||
}
|
||||
|
||||
//到这里说明没有问题,把得到的数据,写入到DataCenter中
|
||||
dataCenter->resetChatSessionList(pbResp);
|
||||
|
||||
//通知调用者,响应已经处理完毕了
|
||||
emit dataCenter->getChatSessionListDone();
|
||||
|
||||
//打印日志
|
||||
LOG() << "获取会话列表->处理响应完毕 requestId= " << pbResp->requestId();
|
||||
});
|
||||
}
|
||||
|
||||
void NetClient::getApplyList(const QString& loginSessionId)
|
||||
{
|
||||
//通过protobuf构造body
|
||||
bite_im::GetPendingFriendEventListReq req;
|
||||
req.setRequestId(makeRequestId());
|
||||
req.setSessionId(loginSessionId);
|
||||
QByteArray body = req.serialize(&serializer);
|
||||
LOG() << "获取好友申请列表->发送请求 reason= " << req.requestId() << ", loginSessonId= " << loginSessionId;
|
||||
|
||||
//发送HTTP请求
|
||||
QNetworkReply* resp = this->sendHttpRequest("/service/friend/get_pending_friend_events", body);
|
||||
|
||||
//处理响应
|
||||
connect(resp, &QNetworkReply::finished, this, [=]() {
|
||||
//解析响应
|
||||
bool ok = false;
|
||||
QString reason;
|
||||
auto pbResp = this->handleHttpResponse<bite_im::GetPendingFriendEventListRsp>(resp, &ok, &reason);
|
||||
//判定结果是否正确
|
||||
if (!ok) {
|
||||
LOG() << "获取好友申请列表->失败 reason= " << reason;
|
||||
return;
|
||||
}
|
||||
|
||||
//拿到的数据,写入到DataCenter中
|
||||
dataCenter->resetApplyList(pbResp);
|
||||
|
||||
//发送信号通知界面,已经处理完毕
|
||||
emit dataCenter->getApplyListDone();
|
||||
|
||||
LOG() << "获取好友申请列表->处理响应完成 requestId= " << req.requestId();
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void NetClient::getRecentMessageList(const QString& loginSessionId, const QString& chatSessionId)
|
||||
{
|
||||
//通过protobuf构造请求body
|
||||
bite_im::GetRecentMsgReq req;
|
||||
req.setRequestId(makeRequestId());
|
||||
req.setChatSessionId(chatSessionId);
|
||||
req.setMsgCount(50);
|
||||
req.setSessionId(loginSessionId);
|
||||
QByteArray body = req.serialize(&serializer);
|
||||
LOG() << "获取最近消息->发送请求 requestId= " << req.requestId() << ", loginSessionId= " << loginSessionId;
|
||||
|
||||
//发送http请求
|
||||
QNetworkReply* resp = this->sendHttpRequest("/service/message_storage/get_recent", body);
|
||||
|
||||
//处理响应
|
||||
connect(resp, &QNetworkReply::finished, this, [=]() {
|
||||
//解析响应,反序列化
|
||||
bool ok = false;
|
||||
QString reason;
|
||||
auto pbResp = this->handleHttpResponse<bite_im::GetRecentMsgRsp>(resp, &ok, &reason);
|
||||
|
||||
//判定响应是否出错
|
||||
if (!ok) {
|
||||
LOG() << "获取最近消息->失败 reason= " << reason;
|
||||
return;
|
||||
}
|
||||
|
||||
//把拿到的数据,设置到DataCenter中
|
||||
dataCenter->resetRecentMessageList(chatSessionId, pbResp);
|
||||
|
||||
//发送信号,告知界面进行更新
|
||||
emit dataCenter->getRecentMessageListDone(chatSessionId);
|
||||
});
|
||||
}
|
||||
} //end namespace network
|
||||
@ -80,7 +80,10 @@ namespace network {
|
||||
}
|
||||
|
||||
void getMyself(const QString& loginSessionId);
|
||||
void getFriendList(const QString loginSessionId);
|
||||
void getFriendList(const QString& loginSessionId);
|
||||
void getChatSessionList(const QString& loginSessionId);
|
||||
void getApplyList(const QString& loginSessionId);
|
||||
void getRecentMessageList(const QString& loginSessionId, const QString& chatSessionId);
|
||||
private:
|
||||
model::DataCenter* dataCenter;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user