summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-07-10 16:12:38 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2021-07-10 16:12:38 +0200
commitc755d54243b7408bdf204bc32226c53ae5314e75 (patch)
tree4e349d2c02be87e5787e6c3f8d6d604f95f0138f /src/timeline
parentAdd additional device verification logging (diff)
downloadnheko-c755d54243b7408bdf204bc32226c53ae5314e75.tar.xz
Remove db bottleneck by caching ro txn for 100 requests
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/TimelineModel.cpp12
-rw-r--r--src/timeline/TimelineModel.h5
2 files changed, 11 insertions, 6 deletions
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index caa40353..4cb97e07 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -323,6 +323,7 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
         if (auto create =
               cache::client()->getStateEvent<mtx::events::state::Create>(room_id.toStdString()))
                 this->isSpace_ = create->content.type == mtx::events::state::room_type::space;
+        this->isEncrypted_ = cache::isRoomEncrypted(room_id_.toStdString());
 
         connect(
           this,
@@ -435,7 +436,6 @@ TimelineModel::roleNames() const
           {IsEditable, "isEditable"},
           {IsEncrypted, "isEncrypted"},
           {Trustlevel, "trustlevel"},
-          {IsRoomEncrypted, "isRoomEncrypted"},
           {ReplyTo, "replyTo"},
           {Reactions, "reactions"},
           {RoomId, "roomId"},
@@ -622,9 +622,6 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
                 return crypto::Trust::Unverified;
         }
 
-        case IsRoomEncrypted: {
-                return cache::isRoomEncrypted(room_id_.toStdString());
-        }
         case ReplyTo:
                 return QVariant(QString::fromStdString(relations(event).reply_to().value_or("")));
         case Reactions: {
@@ -672,7 +669,6 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
                 m.insert(names[IsEdited], data(event, static_cast<int>(IsEdited)));
                 m.insert(names[IsEditable], data(event, static_cast<int>(IsEditable)));
                 m.insert(names[IsEncrypted], data(event, static_cast<int>(IsEncrypted)));
-                m.insert(names[IsRoomEncrypted], data(event, static_cast<int>(IsRoomEncrypted)));
                 m.insert(names[ReplyTo], data(event, static_cast<int>(ReplyTo)));
                 m.insert(names[RoomName], data(event, static_cast<int>(RoomName)));
                 m.insert(names[RoomTopic], data(event, static_cast<int>(RoomTopic)));
@@ -785,6 +781,9 @@ TimelineModel::syncState(const mtx::responses::State &s)
                         emit roomAvatarUrlChanged();
                         emit roomNameChanged();
                         emit roomMemberCountChanged();
+                } else if (std::holds_alternative<StateEvent<state::Encryption>>(e)) {
+                        this->isEncrypted_ = cache::isRoomEncrypted(room_id_.toStdString());
+                        emit encryptionChanged();
                 }
         }
 }
@@ -842,6 +841,9 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline)
                         emit roomAvatarUrlChanged();
                         emit roomNameChanged();
                         emit roomMemberCountChanged();
+                } else if (std::holds_alternative<StateEvent<state::Encryption>>(e)) {
+                        this->isEncrypted_ = cache::isRoomEncrypted(room_id_.toStdString());
+                        emit encryptionChanged();
                 }
         }
         updateLastMessage();
diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h
index 3392d474..f093acb4 100644
--- a/src/timeline/TimelineModel.h
+++ b/src/timeline/TimelineModel.h
@@ -162,6 +162,7 @@ class TimelineModel : public QAbstractListModel
         Q_PROPERTY(QString roomAvatarUrl READ roomAvatarUrl NOTIFY roomAvatarUrlChanged)
         Q_PROPERTY(QString roomTopic READ roomTopic NOTIFY roomTopicChanged)
         Q_PROPERTY(int roomMemberCount READ roomMemberCount NOTIFY roomMemberCountChanged)
+        Q_PROPERTY(bool isEncrypted READ isEncrypted NOTIFY encryptionChanged)
         Q_PROPERTY(bool isSpace READ isSpace CONSTANT)
         Q_PROPERTY(InputBar *input READ input CONSTANT)
         Q_PROPERTY(Permissions *permissions READ permissions NOTIFY permissionsChanged)
@@ -200,7 +201,6 @@ public:
                 IsEditable,
                 IsEncrypted,
                 Trustlevel,
-                IsRoomEncrypted,
                 ReplyTo,
                 Reactions,
                 RoomId,
@@ -265,6 +265,7 @@ public:
 
         DescInfo lastMessage() const { return lastMessage_; }
         bool isSpace() const { return isSpace_; }
+        bool isEncrypted() const { return isEncrypted_; }
         int roomMemberCount() const;
 
 public slots:
@@ -349,6 +350,7 @@ signals:
         void addPendingMessageToStore(mtx::events::collections::TimelineEvents event);
         void updateFlowEventId(std::string event_id);
 
+        void encryptionChanged();
         void roomNameChanged();
         void roomTopicChanged();
         void roomAvatarUrlChanged();
@@ -394,6 +396,7 @@ private:
         bool decryptDescription     = true;
         bool m_paginationInProgress = false;
         bool isSpace_               = false;
+        bool isEncrypted_           = false;
 };
 
 template<class T>