aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-05-20 05:20:49 +0200
committerdec05eba <dec05eba@protonmail.com>2021-05-20 05:34:59 +0200
commit3609429b3d8fccd99994dde015b6516376e6835b (patch)
tree2155b1f3f60897a21ca29dbdf150b8ba6bb95376 /plugins
parent8e79b2e10827f42d76ec61621f2c484f9cdc2551 (diff)
Move chat page room list logic to matrix delegate
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Matrix.hpp74
1 files changed, 30 insertions, 44 deletions
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index 9d6f0b6..bff89b2 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -58,41 +58,16 @@ namespace QuickMedia {
};
struct MatrixEventUserInfo {
+ RoomData *room;
std::string user_id;
std::optional<std::string> display_name;
std::optional<std::string> avatar_url;
};
- class MatrixEvent {
- public:
- enum class Type {
- ADD_USER,
- REMOVE_USER,
- USER_INFO
- };
-
- MatrixEvent(Type type) : type(type) {}
- virtual ~MatrixEvent() = default;
-
- const Type type;
- };
-
- class MatrixAddUserEvent : public MatrixEvent {
- public:
- MatrixAddUserEvent(MatrixEventUserInfo user_info) : MatrixEvent(Type::ADD_USER), user_info(std::move(user_info)) {}
- const MatrixEventUserInfo user_info;
- };
-
- class MatrixRemoveUserEvent : public MatrixEvent {
- public:
- MatrixRemoveUserEvent(MatrixEventUserInfo user_info) : MatrixEvent(Type::REMOVE_USER), user_info(std::move(user_info)) {}
- const MatrixEventUserInfo user_info;
- };
-
- class MatrixUserInfoEvent : public MatrixEvent {
- public:
- MatrixUserInfoEvent(MatrixEventUserInfo user_info) : MatrixEvent(Type::USER_INFO), user_info(std::move(user_info)) {}
- const MatrixEventUserInfo user_info;
+ enum class MatrixEventType {
+ ADD_USER,
+ REMOVE_USER,
+ USER_INFO
};
struct Message {
@@ -271,6 +246,10 @@ namespace QuickMedia {
virtual void add_unread_notification(RoomData *room, std::string event_id, std::string sender, std::string body) = 0;
+ virtual void add_user(MatrixEventUserInfo user_info) = 0;
+ virtual void remove_user(MatrixEventUserInfo user_info) = 0;
+ virtual void set_user_info(MatrixEventUserInfo user_info) = 0;
+
virtual void clear_data() = 0;
};
@@ -280,6 +259,8 @@ namespace QuickMedia {
class MatrixInvitesPage;
class MatrixChatPage;
+ using UsersByRoom = std::unordered_multimap<RoomData*, MatrixEventUserInfo>;
+
class MatrixQuickMedia : public MatrixDelegate {
public:
MatrixQuickMedia(Program *program, Matrix *matrix, MatrixRoomsPage *rooms_page, MatrixRoomTagsPage *room_tags_page, MatrixInvitesPage *invites_page);
@@ -295,6 +276,11 @@ namespace QuickMedia {
void add_unread_notification(RoomData *room, std::string event_id, std::string sender, std::string body) override;
+ void add_user(MatrixEventUserInfo user_info) override;
+ void remove_user(MatrixEventUserInfo user_info) override;
+ void set_user_info(MatrixEventUserInfo user_info) override;
+ void for_each_user_in_room(RoomData *room, std::function<void(const MatrixEventUserInfo&)> callback);
+
void clear_data() override;
Program *program;
@@ -308,6 +294,7 @@ namespace QuickMedia {
private:
std::map<RoomData*, std::shared_ptr<BodyItem>> room_body_item_by_room;
std::map<RoomData*, std::shared_ptr<Message>> last_message_by_room;
+ UsersByRoom users_by_room;
};
class MatrixRoomsPage : public Page {
@@ -319,6 +306,7 @@ namespace QuickMedia {
PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
bool submit_is_async() override { return false; }
bool clear_search_after_submit() override { return true; }
+ void on_navigate_to_page(Body *body) override;
void add_body_item(std::shared_ptr<BodyItem> body_item);
@@ -344,6 +332,7 @@ namespace QuickMedia {
PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
bool submit_is_async() override { return false; }
bool clear_search_after_submit() override { return true; }
+ void on_navigate_to_page(Body *body) override;
void add_room_body_item_to_tag(std::shared_ptr<BodyItem> body_item, const std::string &tag);
void remove_room_body_item_from_tag(std::shared_ptr<BodyItem> body_item, const std::string &tag);
@@ -423,12 +412,22 @@ namespace QuickMedia {
const char* get_title() const override { return ""; }
PageTypez get_type() const override { return PageTypez::CHAT; }
+ void add_user(MatrixEventUserInfo user_info);
+ void remove_user(MatrixEventUserInfo user_info);
+ void set_user_info(MatrixEventUserInfo user_info);
+
+ void set_current_room(RoomData *room, Body *users_body);
+ size_t get_num_users_in_current_room() const;
+
const std::string room_id;
MatrixRoomsPage *rooms_page = nullptr;
bool should_clear_data = false;
Body *chat_body = nullptr;
bool messages_tab_visible = false;
+ private:
+ RoomData *current_room = nullptr;
+ Body *users_body = nullptr;
};
class MatrixRoomDirectoryPage : public Page {
@@ -533,21 +532,11 @@ namespace QuickMedia {
RoomData* get_room_by_id(const std::string &id);
void update_room_users(RoomData *room);
- // Only one room can have event queue enabled at once
- void enable_event_queue(RoomData *room);
- // Also clears the event queue
- void disable_event_queue();
-
// Calls the |MatrixDelegate| pending events.
// Should be called from the main (ui) thread
void update();
-
- // Has to be called in the main thread.
- // Returns nullptr if there are no new events.
- std::unique_ptr<MatrixEvent> pop_event();
private:
- // No-op if sync is cache or if |room| is not the currently enabled event queue room
- void trigger_event(RoomData *room, std::unique_ptr<MatrixEvent> event);
+ void trigger_event(RoomData *room, MatrixEventType type, MatrixEventUserInfo user_info);
void formatted_body_add_line(RoomData *room, std::string &formatted_body, const std::string &line_str);
void replace_mentions(RoomData *room, std::string &text);
@@ -587,9 +576,6 @@ namespace QuickMedia {
std::string get_filter_cached();
private:
MessageQueue<std::function<void()>> ui_thread_tasks;
- std::deque<std::unique_ptr<MatrixEvent>> event_queue;
- std::mutex event_queue_mutex;
- RoomData *current_event_queue_room = nullptr;
std::vector<std::unique_ptr<RoomData>> rooms;
std::unordered_map<std::string, size_t> room_data_by_id; // value is an index into |rooms|
std::recursive_mutex room_data_mutex;