Skip to content
Snippets Groups Projects
Commit 9195cb0b authored by Sébastien Blin's avatar Sébastien Blin
Browse files

replytorow: correctly update row if original post is editted

Change-Id: I2a76104b96d5eba554113e5aace1661170bbbb5d
parent 838591cb
Branches
Tags
No related merge requests found
......@@ -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
......
......@@ -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});
}
}
}
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment