From 9d6bc706ff1a4fd035516ab04d3f762325dfff83 Mon Sep 17 00:00:00 2001
From: Nicolas Werner <nicolas.werner@hotmail.de>
Date: Mon, 12 Jul 2021 22:28:01 +0200
Subject: [PATCH] Don't use full dump for replies

---
 resources/qml/TimelineRow.qml        | 42 +++++++++++++++-------------
 src/timeline/TimelineModel.h         |  5 ++++
 src/timeline/TimelineViewManager.cpp |  2 ++
 3 files changed, 29 insertions(+), 20 deletions(-)

diff --git a/resources/qml/TimelineRow.qml b/resources/qml/TimelineRow.qml
index 53453e992..58e367a0b 100644
--- a/resources/qml/TimelineRow.qml
+++ b/resources/qml/TimelineRow.qml
@@ -71,8 +71,6 @@ Item {
     RowLayout {
         id: row
 
-        property var replyData: chat.model.getDump(replyTo, eventId)
-
         anchors.rightMargin: 1
         anchors.leftMargin: Nheko.avatarSize + 16
         anchors.left: parent.left
@@ -87,26 +85,30 @@ Item {
 
             // fancy reply, if this is a reply
             Reply {
+                function fromModel(role) {
+                    return replyTo != "" ? room.dataById(replyTo, role) : null;
+                }
+
                 visible: replyTo
                 userColor: TimelineManager.userColor(userId, Nheko.colors.base)
-                blurhash: row.replyData.blurhash ?? ""
-                body: row.replyData.body ?? ""
-                formattedBody: row.replyData.formattedBody ?? ""
-                eventId: row.replyData.eventId ?? ""
-                filename: row.replyData.filename ?? ""
-                filesize: row.replyData.filesize ?? ""
-                proportionalHeight: row.replyData.proportionalHeight ?? 1
-                type: row.replyData.type ?? MtxEvent.UnknownMessage
-                typeString: row.replyData.typeString ?? ""
-                url: row.replyData.url ?? ""
-                originalWidth: row.replyData.originalWidth ?? 0
-                isOnlyEmoji: row.replyData.isOnlyEmoji ?? false
-                userId: row.replyData.userId ?? ""
-                userName: row.replyData.userName ?? ""
-                thumbnailUrl: row.replyData.thumbnailUrl ?? ""
-                roomTopic: row.replyData.roomTopic ?? ""
-                roomName: row.replyData.roomName ?? ""
-                callType: row.replyData.callType ?? ""
+                blurhash: fromModel(Room.Blurhash) ?? ""
+                body: fromModel(Room.Body) ?? ""
+                formattedBody: 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) ?? ""
             }
 
             // actual message content
diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h
index 46153732c..a3c973d63 100644
--- a/src/timeline/TimelineModel.h
+++ b/src/timeline/TimelineModel.h
@@ -209,11 +209,16 @@ public:
                 CallType,
                 Dump,
         };
+        Q_ENUM(Roles);
 
         QHash<int, QByteArray> roleNames() const override;
         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);
+        }
 
         bool canFetchMore(const QModelIndex &) const override;
         void fetchMore(const QModelIndex &) override;
diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp
index a45294d1e..a6fc674e3 100644
--- a/src/timeline/TimelineViewManager.cpp
+++ b/src/timeline/TimelineViewManager.cpp
@@ -178,6 +178,8 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
           0,
           "RoomSettingsModel",
           "Room Settings needs to be instantiated on the C++ side");
+        qmlRegisterUncreatableType<TimelineModel>(
+          "im.nheko", 1, 0, "Room", "Room needs to be instantiated on the C++ side");
 
         static auto self = this;
         qmlRegisterSingletonType<MainWindow>(
-- 
GitLab