diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Matrix.hpp | 34 | ||||
-rw-r--r-- | plugins/utils/UniqueProcess.hpp | 7 |
2 files changed, 17 insertions, 24 deletions
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp index c1ee3bd..e0e789e 100644 --- a/plugins/Matrix.hpp +++ b/plugins/Matrix.hpp @@ -144,7 +144,6 @@ namespace QuickMedia { mgl::vec2i thumbnail_size; // Set to {0, 0} if not specified RelatedEventType related_event_type = RelatedEventType::NONE; bool notification_mentions_me = false; - bool cache = false; bool body_is_formatted = false; std::string transaction_id; time_t timestamp = 0; // In milliseconds @@ -309,13 +308,13 @@ namespace QuickMedia { virtual ~MatrixDelegate() = default; virtual void join_room(RoomData *room) = 0; - virtual void leave_room(RoomData *room, LeaveType leave_type, const std::string &reason, bool is_cache) = 0; + virtual void leave_room(RoomData *room, LeaveType leave_type, const std::string &reason) = 0; // Note: calling |room| methods inside this function is not allowed virtual void room_add_tag(RoomData *room, const std::string &tag) = 0; // Note: calling |room| methods inside this function is not allowed virtual void room_remove_tag(RoomData *room, const std::string &tag) = 0; - virtual void room_add_new_messages(RoomData *room, const Messages &messages, bool is_initial_sync, bool sync_is_cache, MessageDirection message_dir) = 0; + virtual void room_add_new_messages(RoomData *room, const Messages &messages, bool is_initial_sync, MessageDirection message_dir) = 0; virtual void add_invite(const std::string &room_id, const Invite &invite) = 0; virtual void remove_invite(const std::string &room_id) = 0; @@ -326,8 +325,6 @@ namespace QuickMedia { virtual void remove_user(MatrixEventUserInfo user_info) = 0; virtual void set_user_info(MatrixEventUserInfo user_info) = 0; virtual void set_room_info(MatrixEventRoomInfo room_info) = 0; - - virtual void clear_data() = 0; }; class Matrix; @@ -344,10 +341,10 @@ namespace QuickMedia { MatrixQuickMedia(Program *program, Matrix *matrix, MatrixRoomsPage *rooms_page, MatrixRoomTagsPage *room_tags_page, MatrixInvitesPage *invites_page, MatrixNotificationsPage *notifications_page); void join_room(RoomData *room) override; - void leave_room(RoomData *room, LeaveType leave_type, const std::string &reason, bool is_cache) override; + void leave_room(RoomData *room, LeaveType leave_type, const std::string &reason) override; void room_add_tag(RoomData *room, const std::string &tag) override; void room_remove_tag(RoomData *room, const std::string &tag) override; - void room_add_new_messages(RoomData *room, const Messages &messages, bool is_initial_sync, bool sync_is_cache, MessageDirection message_dir) override; + void room_add_new_messages(RoomData *room, const Messages &messages, bool is_initial_sync, MessageDirection message_dir) override; void add_invite(const std::string &room_id, const Invite &invite) override; void remove_invite(const std::string &room_id) override; @@ -362,8 +359,6 @@ namespace QuickMedia { void set_room_as_read(RoomData *room); - void clear_data() override; - Program *program; Matrix *matrix; MatrixChatPage *chat_page; @@ -372,7 +367,7 @@ namespace QuickMedia { MatrixInvitesPage *invites_page; MatrixNotificationsPage *notifications_page; private: - void update_room_description(RoomData *room, const Messages &new_messages, bool is_initial_sync, bool sync_is_cache); + void update_room_description(RoomData *room, const Messages &new_messages, bool is_initial_sync); private: std::map<RoomData*, std::shared_ptr<BodyItem>> room_body_item_by_room; std::map<RoomData*, std::shared_ptr<Message>> last_message_by_room; @@ -401,8 +396,6 @@ namespace QuickMedia { void clear_search(); - void clear_data(); - MatrixQuickMedia *matrix_delegate = nullptr; Body *body = nullptr; private: @@ -428,8 +421,6 @@ namespace QuickMedia { void set_current_rooms_page(MatrixRoomsPage *rooms_page); - void clear_data(); - MatrixQuickMedia *matrix_delegate = nullptr; private: struct TagData { @@ -453,8 +444,6 @@ namespace QuickMedia { void add_body_item(std::shared_ptr<BodyItem> body_item); void remove_body_item_by_room_id(const std::string &room_id); - - void clear_data(); private: Matrix *matrix; Body *body; @@ -570,7 +559,6 @@ namespace QuickMedia { const std::string room_id; MatrixRoomsPage *rooms_page = nullptr; - bool should_clear_data = false; Body *chat_body = nullptr; bool messages_tab_visible = false; @@ -654,6 +642,7 @@ namespace QuickMedia { class Matrix { public: + Matrix(bool matrix_instance_already_running); // TODO: Make this return the Matrix object instead, to force users to call start_sync bool start_sync(MatrixDelegate *delegate, bool &cached); void stop_sync(); @@ -762,16 +751,16 @@ namespace QuickMedia { PluginResult set_qm_last_read_message_timestamp(RoomData *room, int64_t timestamp); void load_qm_read_markers_from_account_data(); - PluginResult parse_sync_response(const rapidjson::Document &root, bool is_additional_messages_sync, bool initial_sync); + PluginResult parse_sync_response(const rapidjson::Document &root, bool initial_sync); PluginResult parse_notifications(const rapidjson::Value ¬ifications_json, std::function<void(const MatrixNotification&)> callback_func); PluginResult parse_sync_account_data(const rapidjson::Value &account_data_json); - PluginResult parse_sync_room_data(const rapidjson::Value &rooms_json, bool is_additional_messages_sync, bool initial_sync); + PluginResult parse_sync_room_data(const rapidjson::Value &rooms_json, bool initial_sync); void parse_custom_emoji(const rapidjson::Value &custom_emoji_json); void load_custom_emoji_from_cache(); PluginResult get_previous_room_messages(RoomData *room_data, bool latest_messages, size_t &num_new_messages, bool *reached_end = nullptr); void events_add_user_info(const rapidjson::Value &events_json, RoomData *room_data, int64_t timestamp); std::shared_ptr<UserInfo> parse_user_info(const rapidjson::Value &json, const std::string &user_id, RoomData *room_data, int64_t timestamp); - void events_set_user_read_marker(const rapidjson::Value &events_json, RoomData *room_data, std::shared_ptr<UserInfo> &me, bool is_additional_messages_sync); + void events_set_user_read_marker(const rapidjson::Value &events_json, RoomData *room_data, std::shared_ptr<UserInfo> &me); // Returns the number of messages added size_t events_add_messages(const rapidjson::Value &events_json, RoomData *room_data, MessageDirection message_dir, bool has_unread_notifications); void events_set_room_info(const rapidjson::Value &events_json, RoomData *room_data, int64_t timestamp); @@ -793,7 +782,6 @@ namespace QuickMedia { std::string get_next_batch(); void set_next_notifications_token(std::string new_next_token); std::string get_next_notifications_token(); - void clear_sync_cache_for_new_sync(); std::shared_ptr<UserInfo> get_user_by_id(RoomData *room, const std::string &user_id, bool *is_new_user = nullptr, bool create_if_not_found = true); std::string get_filter_cached(); void load_silenced_invites(); @@ -813,6 +801,7 @@ namespace QuickMedia { std::string next_notifications_token; std::mutex next_batch_mutex; bool initial_sync_finished = false; + bool matrix_instance_already_running = false; std::unordered_map<std::string, Invite> invites; std::mutex invite_mutex; @@ -822,12 +811,9 @@ namespace QuickMedia { std::mutex notifications_mutex; std::thread sync_thread; - std::thread sync_additional_messages_thread; std::thread notification_thread; - MessageQueue<bool> additional_messages_queue; bool sync_running = false; bool sync_failed = false; - bool sync_is_cache = false; bool finished_fetching_notifications = false; std::string sync_fail_reason; MatrixDelegate *delegate = nullptr; diff --git a/plugins/utils/UniqueProcess.hpp b/plugins/utils/UniqueProcess.hpp new file mode 100644 index 0000000..f85704f --- /dev/null +++ b/plugins/utils/UniqueProcess.hpp @@ -0,0 +1,7 @@ +#pragma once + +namespace QuickMedia { + bool is_quickmedia_instance_already_running(const char *sock_file_dir, const char *plugin_name); + bool set_quickmedia_instance_unique(const char *sock_file_dir, const char *plugin_name); + void remove_quickmedia_instance_lock(const char *sock_file_dir, const char *plugin_name); +}
\ No newline at end of file |