From d2eba1d91ebd25362364699200421912bd77bb66 Mon Sep 17 00:00:00 2001 From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> Date: Thu, 18 Jul 2024 13:35:06 -0400 Subject: [PATCH] chatview: fix datatransfer messages not showing 99254f8d020c95216d10e4b30f9b4a545711c9d3 introduced 2 issues: - transfer messages not notifying the UI - some file URLs being erased after loading the conversation This commit addresses both of them. Gitlab: #1671 Change-Id: I67a003ea1149c27e749efffe496f4c9ce86615ea --- src/libclient/messagelistmodel.cpp | 37 ++++++++++++++++++------------ 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/libclient/messagelistmodel.cpp b/src/libclient/messagelistmodel.cpp index 04a2ee5cb..75c4299f3 100644 --- a/src/libclient/messagelistmodel.cpp +++ b/src/libclient/messagelistmodel.cpp @@ -201,8 +201,12 @@ MessageListModel::update(const QString& id, const interaction::Info& interaction return true; } } - // Just update bodies notify the view otherwise. - current.body = interaction.body; + // TODO: look into why this update with an empty body is broadcasted just + // after loading the messages. This is a workaround to avoid the empty + // file transfer path. Until then, don't update the body if it's empty. + if (!interaction.body.isEmpty()) { + current.body = interaction.body; + } current.commit = interaction.commit; current.previousBodies = interaction.previousBodies; current.parsedBody = interaction.parsedBody; @@ -253,21 +257,24 @@ MessageListModel::updateTransferStatus(const QString& id, interaction::TransferStatus newStatus, const QString& newBody) { - const std::lock_guard<std::recursive_mutex> lk(mutex_); - auto it = find(id); - if (it == interactions_.end()) { - return false; - } VectorInt roles; - if (it->second.transferStatus == newStatus) { + with(id, [&](const QString&, interaction::Info& interaction) { + if (interaction.transferStatus == newStatus) { + return; + } + interaction.transferStatus = newStatus; + roles.push_back(Role::TransferStatus); + if (!newBody.isEmpty()) { + interaction.body = newBody; + roles.push_back(Role::Body); + } + }); + if (roles.empty()) { return false; } - it->second.transferStatus = newStatus; - roles.push_back(Role::TransferStatus); - if (!newBody.isEmpty()) { - it->second.body = newBody; - roles.push_back(Role::Body); - } + auto idx = indexOfMessage(id); + auto modelIndex = QAbstractListModel::index(idx, 0); + Q_EMIT dataChanged(modelIndex, modelIndex, roles); return true; } @@ -525,7 +532,7 @@ MessageListModel::dataForItem(const item_t& item, int, int role) const auto bestName = item.second.authorUri == account_->profileInfo.uri ? account_->accountModel->bestNameForAccount(account_->id) : account_->contactModel->bestNameForContact( - item.second.authorUri); + item.second.authorUri); return QVariant( interaction::getContactInteractionString(bestName, interaction::to_action( -- GitLab