lrc: avoid excessive copying of conversation info objects

1. Container View api
2. use optional conversation info ref api

Change-Id: I38aa57edc1fbf304ea0ef95d48000e0495c409ee
This commit is contained in:
Mingrui Zhang
2020-12-15 11:55:38 -05:00
committed by Ming Rui Zhang
parent 44ebb170ff
commit 9ef94561a5
14 changed files with 204 additions and 283 deletions

View File

@@ -51,17 +51,17 @@ MessagesAdapter::safeInit()
}
void
MessagesAdapter::setupChatView(const QString& uid)
MessagesAdapter::setupChatView(const QString& convUid)
{
auto* convModel = LRCInstance::getCurrentConversationModel();
if (convModel == nullptr) {
return;
}
if (currentConvUid_ == uid)
if (currentConvUid_ == convUid)
return;
const auto& convInfo = convModel->getConversationForUID(uid);
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid);
if (convInfo.uid.isEmpty() || convInfo.participants.isEmpty()) {
return;
}
@@ -93,11 +93,11 @@ MessagesAdapter::setupChatView(const QString& uid)
contactIsComposing(convInfo.uid, "", false);
connect(LRCInstance::getCurrentConversationModel(),
&ConversationModel::composingStatusChanged,
[this](const QString& uid, const QString& contactUri, bool isComposing) {
[this](const QString& convUid, const QString& contactUri, bool isComposing) {
if (!AppSettingsManager::getValue(Settings::Key::EnableTypingIndicator).toBool()) {
return;
}
contactIsComposing(uid, contactUri, isComposing);
contactIsComposing(convUid, contactUri, isComposing);
});
/*
@@ -110,7 +110,7 @@ MessagesAdapter::setupChatView(const QString& uid)
requestSendMessageContent();
currentConvUid_ = uid;
currentConvUid_ = convUid;
}
void
@@ -167,11 +167,11 @@ void
MessagesAdapter::updateConversationForAddedContact()
{
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto conversation = convModel->getConversationForUID(LRCInstance::getCurrentConvUid());
const auto& convInfo = LRCInstance::getConversationFromConvUid(LRCInstance::getCurrentConvUid());
clear();
setConversationProfileData(conversation);
printHistory(*convModel, conversation.interactions);
setConversationProfileData(convInfo);
printHistory(*convModel, convInfo.interactions);
}
void
@@ -205,7 +205,7 @@ void
MessagesAdapter::slotMessagesCleared()
{
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto convInfo = convModel->getConversationForUID(LRCInstance::getCurrentConvUid());
const auto& convInfo = LRCInstance::getConversationFromConvUid(LRCInstance::getCurrentConvUid());
printHistory(*convModel, convInfo.interactions);
@@ -442,15 +442,13 @@ MessagesAdapter::onComposing(bool isComposing)
void
MessagesAdapter::setConversationProfileData(const lrc::api::conversation::Info& convInfo)
{
auto* convModel = LRCInstance::getCurrentConversationModel();
auto accInfo = &LRCInstance::getCurrentAccountInfo();
const auto conv = convModel->getConversationForUID(convInfo.uid);
if (conv.participants.isEmpty()) {
if (convInfo.participants.isEmpty()) {
return;
}
auto contactUri = conv.participants.front();
auto contactUri = convInfo.participants.front();
if (contactUri.isEmpty()) {
return;
}