summary refs log tree commit diff
path: root/include
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-10-28 20:46:34 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-10-28 20:46:34 +0300
commitc18a49915b4b98ac7f837a1feca3e243ac44940d (patch)
tree98fda5a56640689bebf7b6294722f4151731a156 /include
parentClean up headers (diff)
downloadnheko-c18a49915b4b98ac7f837a1feca3e243ac44940d.tar.xz
Save the changes between syncs in cache
- Fixes high cpu issues caused by the serialization of the whole
  in-memory state.
- Display name changes are now visible in the timeline.
Diffstat (limited to 'include')
-rw-r--r--include/ChatPage.h24
-rw-r--r--include/RoomState.h6
2 files changed, 28 insertions, 2 deletions
diff --git a/include/ChatPage.h b/include/ChatPage.h
index d3790f78..416f7870 100644
--- a/include/ChatPage.h
+++ b/include/ChatPage.h
@@ -23,6 +23,10 @@
 #include <QTimer>
 #include <QWidget>
 
+#include "MemberEventContent.h"
+#include "MessageEvent.h"
+#include "StateEvent.h"
+
 class Cache;
 class MatrixClient;
 class OverlayModal;
@@ -38,6 +42,8 @@ class TimelineViewManager;
 class TopRoomBar;
 class TypingDisplay;
 class UserInfoWidget;
+class JoinedRoom;
+class LeftRoom;
 
 constexpr int CONSENSUS_TIMEOUT    = 1000;
 constexpr int SHOW_CONTENT_TIMEOUT = 3000;
@@ -76,8 +82,24 @@ private slots:
         void removeRoom(const QString &room_id);
 
 private:
+        using UserID      = QString;
+        using RoomStates  = QMap<UserID, RoomState>;
+        using JoinedRooms = QMap<UserID, JoinedRoom>;
+        using LeftRooms   = QMap<UserID, LeftRoom>;
+        using Membership  = matrix::events::StateEvent<matrix::events::MemberEventContent>;
+        using Memberships = QMap<UserID, Membership>;
+
+        void removeLeftRooms(const LeftRooms &rooms);
+        void updateJoinedRooms(const JoinedRooms &rooms);
+
+        Memberships getMemberships(const QJsonArray &events) const;
+        RoomStates generateMembershipDifference(const JoinedRooms &rooms,
+                                                const RoomStates &states) const;
+
         void updateTypingUsers(const QString &roomid, const QList<QString> &user_ids);
-        void updateDisplayNames(const RoomState &state);
+        void updateUserMetadata(const QJsonArray &events);
+        void updateUserDisplayName(const Membership &event);
+        void updateUserAvatarUrl(const Membership &event);
         void loadStateFromCache();
         void deleteConfigs();
         void resetUI();
diff --git a/include/RoomState.h b/include/RoomState.h
index 57955e56..db1cdc68 100644
--- a/include/RoomState.h
+++ b/include/RoomState.h
@@ -41,6 +41,9 @@ namespace events = matrix::events;
 class RoomState
 {
 public:
+        RoomState();
+        RoomState(const QJsonArray &events);
+
         // Calculate room data that are not immediatly accessible. Like room name and
         // avatar.
         //
@@ -71,7 +74,8 @@ public:
         events::StateEvent<events::TopicEventContent> topic;
 
         // Contains the m.room.member events for all the joined users.
-        QMap<QString, events::StateEvent<events::MemberEventContent>> memberships;
+        using UserID = QString;
+        QMap<UserID, events::StateEvent<events::MemberEventContent>> memberships;
 
 private:
         QUrl avatar_;