summary refs log tree commit diff
path: root/src/timeline/TimelineModel.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2023-03-12 03:46:29 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2023-03-14 18:16:08 +0100
commit703a07fb7d50ed191c20e33720ecf6c05c4c88c2 (patch)
treece2e81e489b01006eee4df5b26ee24679434f297 /src/timeline/TimelineModel.cpp
parentEvaluate ACLs when calculating vias (diff)
downloadnheko-703a07fb7d50ed191c20e33720ecf6c05c4c88c2.tar.xz
Speed up processing UI changes with large syncs
Diffstat (limited to 'src/timeline/TimelineModel.cpp')
-rw-r--r--src/timeline/TimelineModel.cpp58
1 files changed, 44 insertions, 14 deletions
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 25ee71cb..e17c1c59 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -953,11 +953,15 @@ TimelineModel::syncState(const mtx::responses::State &s)
 {
     using namespace mtx::events;
 
+    bool avatarChanged      = false;
+    bool nameChanged        = false;
+    bool memberCountChanged = false;
+
     for (const auto &e : s.events) {
         if (std::holds_alternative<StateEvent<state::Avatar>>(e))
-            emit roomAvatarUrlChanged();
+            avatarChanged = true;
         else if (std::holds_alternative<StateEvent<state::Name>>(e))
-            emit roomNameChanged();
+            nameChanged = true;
         else if (std::holds_alternative<StateEvent<state::Topic>>(e))
             emit roomTopicChanged();
         else if (std::holds_alternative<StateEvent<state::PinnedEvents>>(e))
@@ -968,14 +972,10 @@ TimelineModel::syncState(const mtx::responses::State &s)
             permissions_.invalidate();
             emit permissionsChanged();
         } else if (std::holds_alternative<StateEvent<state::Member>>(e)) {
-            emit roomAvatarUrlChanged();
-            emit roomNameChanged();
-            emit roomMemberCountChanged();
+            avatarChanged      = true;
+            nameChanged        = true;
+            memberCountChanged = true;
 
-            if (roomMemberCount() <= 2) {
-                emit isDirectChanged();
-                emit directChatOtherUserIdChanged();
-            }
         } else if (std::holds_alternative<StateEvent<state::Encryption>>(e)) {
             this->isEncrypted_ = cache::isRoomEncrypted(room_id_.toStdString());
             emit encryptionChanged();
@@ -984,6 +984,19 @@ TimelineModel::syncState(const mtx::responses::State &s)
             emit parentSpaceChanged();
         }
     }
+
+    if (avatarChanged)
+        emit roomAvatarUrlChanged();
+    if (nameChanged)
+        emit roomNameChanged();
+
+    if (memberCountChanged) {
+        emit roomMemberCountChanged();
+        if (roomMemberCount() <= 2) {
+            emit isDirectChanged();
+            emit directChatOtherUserIdChanged();
+        }
+    }
 }
 
 void
@@ -999,6 +1012,10 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline)
 
     using namespace mtx::events;
 
+    bool avatarChanged      = false;
+    bool nameChanged        = false;
+    bool memberCountChanged = false;
+
     for (auto e : timeline.events) {
         if (auto encryptedEvent = std::get_if<EncryptedEvent<msg::Encrypted>>(&e)) {
             MegolmSessionIndex index(room_id_.toStdString(), encryptedEvent->content);
@@ -1033,9 +1050,9 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline)
               },
               e);
         else if (std::holds_alternative<StateEvent<state::Avatar>>(e))
-            emit roomAvatarUrlChanged();
+            avatarChanged = true;
         else if (std::holds_alternative<StateEvent<state::Name>>(e))
-            emit roomNameChanged();
+            nameChanged = true;
         else if (std::holds_alternative<StateEvent<state::Topic>>(e))
             emit roomTopicChanged();
         else if (std::holds_alternative<StateEvent<state::PinnedEvents>>(e))
@@ -1046,9 +1063,9 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline)
             permissions_.invalidate();
             emit permissionsChanged();
         } else if (std::holds_alternative<StateEvent<state::Member>>(e)) {
-            emit roomAvatarUrlChanged();
-            emit roomNameChanged();
-            emit roomMemberCountChanged();
+            avatarChanged      = true;
+            nameChanged        = true;
+            memberCountChanged = true;
         } else if (std::holds_alternative<StateEvent<state::Encryption>>(e)) {
             this->isEncrypted_ = cache::isRoomEncrypted(room_id_.toStdString());
             emit encryptionChanged();
@@ -1067,6 +1084,19 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline)
     if (needsSpecialEffects_)
         emit confetti();
 
+    if (avatarChanged)
+        emit roomAvatarUrlChanged();
+    if (nameChanged)
+        emit roomNameChanged();
+
+    if (memberCountChanged) {
+        emit roomMemberCountChanged();
+        if (roomMemberCount() <= 2) {
+            emit isDirectChanged();
+            emit directChatOtherUserIdChanged();
+        }
+    }
+
     updateLastMessage();
 }