summary refs log tree commit diff
path: root/include/ChatPage.h
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-04-21 16:34:50 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-04-21 16:35:03 +0300
commit2f00fc51bf27708a9c0ac1ce186043059f93923e (patch)
tree2e65159dd08fd9576b18f7f1570b41b56029ccda /include/ChatPage.h
parentPopup improvements (diff)
downloadnheko-2f00fc51bf27708a9c0ac1ce186043059f93923e.tar.xz
Cache refactoring
Diffstat (limited to 'include/ChatPage.h')
-rw-r--r--include/ChatPage.h60
1 files changed, 16 insertions, 44 deletions
diff --git a/include/ChatPage.h b/include/ChatPage.h
index 25cd8615..a6789aea 100644
--- a/include/ChatPage.h
+++ b/include/ChatPage.h
@@ -24,16 +24,16 @@
 #include <QTimer>
 #include <QWidget>
 
+#include "Cache.h"
 #include "CommunitiesList.h"
 #include "Community.h"
+
 #include <mtx.hpp>
 
-class Cache;
 class MatrixClient;
 class OverlayModal;
 class QuickSwitcher;
 class RoomList;
-class RoomSettings;
 class RoomState;
 class SideBarActions;
 class Splitter;
@@ -52,6 +52,9 @@ constexpr int CONSENSUS_TIMEOUT      = 1000;
 constexpr int SHOW_CONTENT_TIMEOUT   = 3000;
 constexpr int TYPING_REFRESH_TIMEOUT = 10000;
 
+Q_DECLARE_METATYPE(mtx::responses::Rooms);
+Q_DECLARE_METATYPE(std::vector<std::string>);
+
 class ChatPage : public QWidget
 {
         Q_OBJECT
@@ -88,6 +91,14 @@ signals:
         void showLoginPage(const QString &msg);
         void showUserSettingsPage();
         void showOverlayProgressBar();
+        void startConsesusTimer();
+
+        void initializeRoomList(QMap<QString, RoomInfo>);
+        void initializeViews(const mtx::responses::Rooms &rooms);
+        void initializeEmptyViews(const std::vector<std::string> &rooms);
+        void syncUI(const mtx::responses::Rooms &rooms);
+        void continueSync(const QString &next_batch);
+        void syncRoomlist(const std::map<QString, RoomInfo> &updates);
 
 private slots:
         void showUnreadMessageNotification(int count);
@@ -98,9 +109,9 @@ private slots:
         void syncCompleted(const mtx::responses::Sync &response);
         void changeTopRoomInfo(const QString &room_id);
         void logout();
-        void addRoom(const QString &room_id);
         void removeRoom(const QString &room_id);
-        void removeInvite(const QString &room_id);
+        //! Handles initial sync failures.
+        void retryInitialSync(int status_code = -1);
 
 private:
         static ChatPage *instance_;
@@ -110,28 +121,11 @@ private:
         using Membership  = mtx::events::StateEvent<mtx::events::state::Member>;
         using Memberships = std::map<std::string, Membership>;
 
-        using JoinedRooms  = std::map<std::string, mtx::responses::JoinedRoom>;
-        using LeftRooms    = std::map<std::string, mtx::responses::LeftRoom>;
-        using InvitedRooms = std::map<std::string, mtx::responses::InvitedRoom>;
-
+        using LeftRooms = std::map<std::string, mtx::responses::LeftRoom>;
         void removeLeftRooms(const LeftRooms &rooms);
-        void updateJoinedRooms(const JoinedRooms &rooms);
-        void trackInvites(const InvitedRooms &rooms)
-        {
-                for (const auto &invite : rooms)
-                        roomInvites_[QString::fromStdString(invite.first)] = true;
-        }
-
-        std::map<QString, QSharedPointer<RoomState>> generateMembershipDifference(
-          const JoinedRooms &rooms,
-          const RoomStates &states) const;
 
         void updateTypingUsers(const QString &roomid, const std::vector<std::string> &user_ids);
 
-        using MemberEvent = mtx::events::StateEvent<mtx::events::state::Member>;
-        void updateUserDisplayName(const MemberEvent &event);
-        void updateUserAvatarUrl(const MemberEvent &event);
-
         void loadStateFromCache();
         void deleteConfigs();
         void resetUI();
@@ -141,10 +135,6 @@ private:
         template<class Collection>
         Memberships getMemberships(const std::vector<Collection> &events) const;
 
-        template<class Collection>
-        void updateUserMetadata(const std::vector<Collection> &collection);
-
-        void retryInitialSync(int status_code = -1);
         //! Update the room with the new notification count.
         void updateRoomNotificationCount(const QString &room_id, uint16_t notification_count);
 
@@ -186,8 +176,6 @@ private:
         UserInfoWidget *user_info_widget_;
 
         RoomStates roomStates_;
-        std::map<QString, QSharedPointer<RoomSettings>> roomSettings_;
-        std::map<QString, bool> roomInvites_;
 
         std::map<QString, QSharedPointer<Community>> communities_;
 
@@ -212,22 +200,6 @@ private:
 };
 
 template<class Collection>
-void
-ChatPage::updateUserMetadata(const std::vector<Collection> &collection)
-{
-        using Member = mtx::events::StateEvent<mtx::events::state::Member>;
-
-        for (const auto &event : collection) {
-                if (mpark::holds_alternative<Member>(event)) {
-                        auto member = mpark::get<Member>(event);
-
-                        updateUserAvatarUrl(member);
-                        updateUserDisplayName(member);
-                }
-        }
-}
-
-template<class Collection>
 std::map<std::string, mtx::events::StateEvent<mtx::events::state::Member>>
 ChatPage::getMemberships(const std::vector<Collection> &collection) const
 {