diff --git a/src/app/commoncomponents/ReplyToRow.qml b/src/app/commoncomponents/ReplyToRow.qml index 08c6c6b7255f3faf9d33fd07b7024dcf995a193d..57d6833f93538c0ca9d4a0039f7297bf1ce678c0 100644 --- a/src/app/commoncomponents/ReplyToRow.qml +++ b/src/app/commoncomponents/ReplyToRow.qml @@ -28,7 +28,15 @@ Item { visible: ReplyTo !== "" width: visible ? replyToRow.width : 0 - height: replyToRow.height + replyToRow.anchors.topMargin + height: replyToRow.height + replyToRow.anchors.topMargin + + Component.onCompleted: { + // Make sure we show the original post + // In the future, we may just want to load the previous interaction of the thread + // and not show it, but for now we can simplify. + if (ReplyTo !== "") + MessagesAdapter.loadConversationUntil(ReplyTo) + } MouseArea { @@ -41,15 +49,6 @@ Item { property bool isSelf: ReplyToAuthor === CurrentAccount.uri || ReplyToAuthor === "" - onVisibleChanged: { - if (visible) { - // Make sure we show the original post - // In the future, we may just want to load the previous interaction of the thread - // and not show it, but for now we can simplify. - MessagesAdapter.loadConversationUntil(ReplyTo) - } - } - Label { id: replyTo diff --git a/src/libclient/messagelistmodel.cpp b/src/libclient/messagelistmodel.cpp index a2c5cb43e08d3c71ac65e258b4c2780a0dbabb9c..e96a258b6a3523c7e0cd62094723a6e0fe14622e 100644 --- a/src/libclient/messagelistmodel.cpp +++ b/src/libclient/messagelistmodel.cpp @@ -290,25 +290,31 @@ MessageListModel::moveMessage(const QString& msgId, const QString& parentId) } void -MessageListModel::insertMessage(int index, item_t& message) +MessageListModel::updateReplies(item_t& message) { - Q_EMIT beginInsertRows(QModelIndex(), index, index); - interactions_.insert(index, message); - Q_EMIT endInsertRows(); auto replyId = message.second.commit["reply-to"]; auto commitId = message.second.commit["id"]; - if (!replyId.isEmpty()) - replyTo_[replyId].append(commitId); + if (!replyId.isEmpty()) { + replyTo_[replyId].insert(commitId); + } for (const auto& msgId : replyTo_[commitId]) { int index = getIndexOfMessage(msgId); if (index == -1) continue; QModelIndex modelIndex = QAbstractListModel::index(index, 0); - Q_EMIT dataChanged(modelIndex, modelIndex, {Role::ReplyToAuthor}); - Q_EMIT dataChanged(modelIndex, modelIndex, {Role::ReplyToBody}); + Q_EMIT dataChanged(modelIndex, modelIndex, {Role::ReplyToAuthor, Role::ReplyToBody}); } } +void +MessageListModel::insertMessage(int index, item_t& message) +{ + Q_EMIT beginInsertRows(QModelIndex(), index, index); + interactions_.insert(index, message); + Q_EMIT endInsertRows(); + updateReplies(message); +} + iterator MessageListModel::insertMessage(iterator it, item_t& message) { @@ -316,6 +322,7 @@ MessageListModel::insertMessage(iterator it, item_t& message) Q_EMIT beginInsertRows(QModelIndex(), index, index); auto insertion = interactions_.insert(it, message); Q_EMIT endInsertRows(); + updateReplies(message); return insertion; } @@ -591,6 +598,15 @@ MessageListModel::editMessage(const QString& msgId, interaction::Info& info) info.body = it->rbegin()->body; editedBodies_.erase(it); emitDataChanged(msgId, {MessageList::Role::Body, MessageList::Role::PreviousBodies}); + + // Body changed, replies should update + for (const auto& replyId : replyTo_[msgId]) { + int index = getIndexOfMessage(replyId); + if (index == -1) + continue; + QModelIndex modelIndex = QAbstractListModel::index(index, 0); + Q_EMIT dataChanged(modelIndex, modelIndex, {Role::ReplyToBody}); + } } } diff --git a/src/libclient/messagelistmodel.h b/src/libclient/messagelistmodel.h index 241e59bd703f5a45c7fc3a1239adbe7b2509a626..fbbf3936f58120dac11ec95210456b870409e80c 100644 --- a/src/libclient/messagelistmodel.h +++ b/src/libclient/messagelistmodel.h @@ -147,7 +147,8 @@ private: // to allow quick access. QMap<QString, QString> lastDisplayedMessageUid_; QMap<QString, QStringList> messageToReaders_; - QMap<QString, QStringList> replyTo_; + QMap<QString, QSet<QString>> replyTo_; + void updateReplies(item_t& message); QMap<QString, QVector<interaction::Body>> editedBodies_; void moveMessage(const QString& msgId, const QString& parentId);