From 0b864d948586d6cc3ef3968376a5b932e06b793e Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Fri, 16 Jul 2021 11:47:49 +0200 Subject: [PATCH] Fix replies not reloading after fetching them --- resources/qml/TimelineRow.qml | 38 +++++++++++++++++----------------- src/timeline/TimelineModel.cpp | 8 +++++++ src/timeline/TimelineModel.h | 5 +---- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/resources/qml/TimelineRow.qml b/resources/qml/TimelineRow.qml index 58e367a0..70db08e7 100644 --- a/resources/qml/TimelineRow.qml +++ b/resources/qml/TimelineRow.qml @@ -86,29 +86,29 @@ Item { // fancy reply, if this is a reply Reply { function fromModel(role) { - return replyTo != "" ? room.dataById(replyTo, role) : null; + return replyTo != "" ? room.dataById(replyTo, role, r.eventId) : null; } visible: replyTo - userColor: TimelineManager.userColor(userId, Nheko.colors.base) - blurhash: fromModel(Room.Blurhash) ?? "" - body: fromModel(Room.Body) ?? "" - formattedBody: fromModel(Room.FormattedBody) ?? "" + userColor: replyTo, TimelineManager.userColor(userId, Nheko.colors.base) + blurhash: replyTo, fromModel(Room.Blurhash) ?? "" + body: replyTo, fromModel(Room.Body) ?? "" + formattedBody: replyTo, fromModel(Room.FormattedBody) ?? "" eventId: fromModel(Room.EventId) ?? "" - filename: fromModel(Room.Filename) ?? "" - filesize: fromModel(Room.Filesize) ?? "" - proportionalHeight: fromModel(Room.ProportionalHeight) ?? 1 - type: fromModel(Room.Type) ?? MtxEvent.UnknownMessage - typeString: fromModel(Room.TypeString) ?? "" - url: fromModel(Room.Url) ?? "" - originalWidth: fromModel(Room.OriginalWidth) ?? 0 - isOnlyEmoji: fromModel(Room.IsOnlyEmoji) ?? false - userId: fromModel(Room.UserId) ?? "" - userName: fromModel(Room.UserName) ?? "" - thumbnailUrl: fromModel(Room.ThumbnailUrl) ?? "" - roomTopic: fromModel(Room.RoomTopic) ?? "" - roomName: fromModel(Room.RoomName) ?? "" - callType: fromModel(Room.CallType) ?? "" + filename: replyTo, fromModel(Room.Filename) ?? "" + filesize: replyTo, fromModel(Room.Filesize) ?? "" + proportionalHeight: replyTo, fromModel(Room.ProportionalHeight) ?? 1 + type: replyTo, fromModel(Room.Type) ?? MtxEvent.UnknownMessage + typeString: replyTo, fromModel(Room.TypeString) ?? "" + url: replyTo, fromModel(Room.Url) ?? "" + originalWidth: replyTo, fromModel(Room.OriginalWidth) ?? 0 + isOnlyEmoji: replyTo, fromModel(Room.IsOnlyEmoji) ?? false + userId: replyTo, fromModel(Room.UserId) ?? "" + userName: replyTo, fromModel(Room.UserName) ?? "" + thumbnailUrl: replyTo, fromModel(Room.ThumbnailUrl) ?? "" + roomTopic: replyTo, fromModel(Room.RoomTopic) ?? "" + roomName: replyTo, fromModel(Room.RoomName) ?? "" + callType: replyTo, fromModel(Room.CallType) ?? "" } // actual message content diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index ab11f99b..5832f56e 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -710,6 +710,14 @@ TimelineModel::data(const QModelIndex &index, int role) const return data(*event, role); } +QVariant +TimelineModel::dataById(QString id, int role, QString relatedTo) +{ + if (auto event = events.get(id.toStdString(), relatedTo.toStdString())) + return data(*event, role); + return QVariant(); +} + bool TimelineModel::canFetchMore(const QModelIndex &) const { diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index a3c973d6..b67234f2 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -215,10 +215,7 @@ public: int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data(const mtx::events::collections::TimelineEvents &event, int role) const; - Q_INVOKABLE QVariant dataById(QString id, int role) - { - return data(index(idToIndex(id)), role); - } + Q_INVOKABLE QVariant dataById(QString id, int role, QString relatedTo); bool canFetchMore(const QModelIndex &) const override; void fetchMore(const QModelIndex &) override;