summary refs log tree commit diff
path: root/include
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-01-13 17:15:47 +0200
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-01-13 17:15:47 +0200
commit3929261a8e41bd9a716b168269208c08491277a8 (patch)
tree719b8c8927357f5d2b6998778899ea542ddd529f /include
parentAdd qt5.7 on travis ci (diff)
downloadnheko-3929261a8e41bd9a716b168269208c08491277a8.tar.xz
Use QSharedPointer to save RoomStates
Diffstat (limited to 'include')
-rw-r--r--include/Cache.h7
-rw-r--r--include/ChatPage.h11
-rw-r--r--include/RoomInfoListItem.h14
-rw-r--r--include/RoomList.h8
4 files changed, 24 insertions, 16 deletions
diff --git a/include/Cache.h b/include/Cache.h
index ae58e418..761c6060 100644
--- a/include/Cache.h
+++ b/include/Cache.h
@@ -69,7 +69,8 @@ class Cache
 public:
         Cache(const QString &userId);
 
-        void setState(const QString &nextBatchToken, const QMap<QString, RoomState> &states);
+        void setState(const QString &nextBatchToken,
+                      const QMap<QString, QSharedPointer<RoomState>> &states);
         bool isInitialized() const;
 
         QString nextBatchToken() const;
@@ -107,7 +108,9 @@ public:
 
 private:
         void setNextBatchToken(lmdb::txn &txn, const QString &token);
-        void insertRoomState(lmdb::txn &txn, const QString &roomid, const RoomState &state);
+        void insertRoomState(lmdb::txn &txn,
+                             const QString &roomid,
+                             const QSharedPointer<RoomState> &state);
 
         lmdb::env env_;
         lmdb::dbi stateDb_;
diff --git a/include/ChatPage.h b/include/ChatPage.h
index 01fb4c50..93b98a76 100644
--- a/include/ChatPage.h
+++ b/include/ChatPage.h
@@ -97,7 +97,7 @@ private:
         static ChatPage *instance_;
 
         using UserID      = QString;
-        using RoomStates  = QMap<UserID, RoomState>;
+        using RoomStates  = QMap<UserID, QSharedPointer<RoomState>>;
         using Membership  = mtx::events::StateEvent<mtx::events::state::Member>;
         using Memberships = std::map<std::string, Membership>;
 
@@ -107,8 +107,9 @@ private:
         void removeLeftRooms(const LeftRooms &rooms);
         void updateJoinedRooms(const JoinedRooms &rooms);
 
-        RoomStates generateMembershipDifference(const JoinedRooms &rooms,
-                                                const RoomStates &states) const;
+        QMap<QString, QSharedPointer<RoomState>> generateMembershipDifference(
+          const JoinedRooms &rooms,
+          const RoomStates &states) const;
 
         void updateTypingUsers(const QString &roomid, const std::vector<std::string> &user_ids);
 
@@ -165,8 +166,8 @@ private:
 
         UserInfoWidget *user_info_widget_;
 
-        QMap<QString, RoomState> state_manager_;
-        QMap<QString, QSharedPointer<RoomSettings>> settingsManager_;
+        RoomStates roomStates_;
+        QMap<QString, QSharedPointer<RoomSettings>> roomSettings_;
 
         QMap<QString, QSharedPointer<Community>> communityManager_;
 
diff --git a/include/RoomInfoListItem.h b/include/RoomInfoListItem.h
index 5cfea783..8222dc2b 100644
--- a/include/RoomInfoListItem.h
+++ b/include/RoomInfoListItem.h
@@ -61,7 +61,7 @@ class RoomInfoListItem : public QWidget
 
 public:
         RoomInfoListItem(QSharedPointer<RoomSettings> settings,
-                         RoomState state,
+                         QSharedPointer<RoomState> state,
                          QString room_id,
                          QWidget *parent = 0);
 
@@ -71,11 +71,15 @@ public:
 
         void updateUnreadMessageCount(int count);
         void clearUnreadMessageCount();
-        void setState(const RoomState &state);
+        void setState(QSharedPointer<RoomState> state)
+        {
+                state_ = state;
+                update();
+        }
 
         QString roomId();
         bool isPressed() const { return isPressed_; };
-        RoomState state() const { return state_; };
+        QSharedPointer<RoomState> state() const { return state_; }
         int unreadMessageCount() const { return unreadMsgCount_; };
 
         void setAvatar(const QImage &avatar_image);
@@ -127,7 +131,7 @@ private:
         QString roomName()
         {
                 if (roomType_ == RoomType::Joined)
-                        return state_.getName();
+                        return state_->getName();
 
                 return roomName_;
         }
@@ -145,7 +149,7 @@ private:
         RoomType roomType_ = RoomType::Joined;
 
         // State information for the joined rooms.
-        RoomState state_;
+        QSharedPointer<RoomState> state_;
 
         // State information for the invited rooms.
         mtx::responses::InvitedRoom invitedRoom_;
diff --git a/include/RoomList.h b/include/RoomList.h
index d10cf5db..43b95f12 100644
--- a/include/RoomList.h
+++ b/include/RoomList.h
@@ -51,16 +51,16 @@ public:
 
         void setCache(QSharedPointer<Cache> cache) { cache_ = cache; }
         void setInitialRooms(const QMap<QString, QSharedPointer<RoomSettings>> &settings,
-                             const QMap<QString, RoomState> &states);
-        void sync(const QMap<QString, RoomState> &states,
-                  QMap<QString, QSharedPointer<RoomSettings>> &settings);
+                             const QMap<QString, QSharedPointer<RoomState>> &states);
+        void sync(const QMap<QString, QSharedPointer<RoomState>> &states,
+                  const QMap<QString, QSharedPointer<RoomSettings>> &settings);
         void syncInvites(const std::map<std::string, mtx::responses::InvitedRoom> &rooms);
 
         void clear();
         void updateAvatar(const QString &room_id, const QString &url);
 
         void addRoom(const QMap<QString, QSharedPointer<RoomSettings>> &settings,
-                     const RoomState &state,
+                     const QSharedPointer<RoomState> &state,
                      const QString &room_id);
         void addInvitedRoom(const QString &room_id, const mtx::responses::InvitedRoom &room);
         void removeRoom(const QString &room_id, bool reset);