From 3dd837611eef939a1fd54621c523cff4ab48e136 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 4 Nov 2020 21:45:53 +0100 Subject: Matrix: fetch additional messages in the background for all rooms, filter room list when updated after sync --- plugins/Fourchan.hpp | 1 + plugins/Matrix.hpp | 20 +++++++++++++++----- plugins/NyaaSi.hpp | 1 + plugins/Page.hpp | 1 + 4 files changed, 18 insertions(+), 5 deletions(-) (limited to 'plugins') diff --git a/plugins/Fourchan.hpp b/plugins/Fourchan.hpp index 3ee07dd..b9e5b74 100644 --- a/plugins/Fourchan.hpp +++ b/plugins/Fourchan.hpp @@ -8,6 +8,7 @@ namespace QuickMedia { FourchanBoardsPage(Program *program, std::string resources_root) : Page(program), resources_root(std::move(resources_root)) {} const char* get_title() const override { return "Select board"; } PluginResult submit(const std::string &title, const std::string &url, std::vector &result_tabs) override; + bool clear_search_after_submit() override { return true; } void get_boards(BodyItems &result_items); const std::string resources_root; diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp index 78725a5..812c1a0 100644 --- a/plugins/Matrix.hpp +++ b/plugins/Matrix.hpp @@ -259,6 +259,7 @@ namespace QuickMedia { const char* get_title() const override { return title.c_str(); } PluginResult submit(const std::string &title, const std::string &url, std::vector &result_tabs) override; + bool clear_search_after_submit() override { return true; } void on_navigate_to_page(Body *body) override; @@ -274,6 +275,7 @@ namespace QuickMedia { void sort_rooms(); MatrixQuickMedia *matrix_delegate = nullptr; + bool filter_on_update = false; private: std::mutex mutex; std::vector> room_body_items; @@ -289,9 +291,10 @@ namespace QuickMedia { class MatrixRoomTagsPage : public Page { public: - MatrixRoomTagsPage(Program *program, Body *body) : Page(program), body(body) {} + MatrixRoomTagsPage(Program *program, Body *body, SearchBar *search_bar) : Page(program), body(body), search_bar(search_bar) {} const char* get_title() const override { return "Tags"; } PluginResult submit(const std::string &title, const std::string &url, std::vector &result_tabs) override; + bool clear_search_after_submit() override { return true; } void update() override; void add_room_body_item_to_tag(std::shared_ptr body_item, const std::string &tag); @@ -306,6 +309,7 @@ namespace QuickMedia { void sort_rooms(); MatrixQuickMedia *matrix_delegate = nullptr; + bool filter_on_update = false; private: struct TagData { std::shared_ptr tag_item; @@ -319,20 +323,23 @@ namespace QuickMedia { std::map>> remove_room_body_items_by_tags; MatrixRoomsPage *current_rooms_page = nullptr; bool clear_data_on_update = false; + SearchBar *search_bar = nullptr; }; class MatrixInvitesPage : public Page { public: - MatrixInvitesPage(Program *program, Matrix *matrix, Body *body); + MatrixInvitesPage(Program *program, Matrix *matrix, Body *body, SearchBar *search_bar); const char* get_title() const override { return title.c_str(); } PluginResult submit(const std::string &title, const std::string &url, std::vector &result_tabs) override; + bool clear_search_after_submit() override { return true; } void update() override; void add_body_item(std::shared_ptr body_item); void remove_body_item_by_room_id(const std::string &room_id); void clear_data(); + bool filter_on_update = false; private: Matrix *matrix; std::mutex mutex; @@ -342,6 +349,7 @@ namespace QuickMedia { std::string title = "Invites (0)"; size_t prev_invite_count = 0; bool clear_data_on_update = false; + SearchBar *search_bar = nullptr; }; class MatrixInviteDetailsPage : public Page { @@ -446,10 +454,10 @@ namespace QuickMedia { bool use_tor = false; private: - PluginResult parse_sync_response(const rapidjson::Document &root); + PluginResult parse_sync_response(const rapidjson::Document &root, bool is_additional_messages_sync); PluginResult parse_notifications(const rapidjson::Value ¬ifications_json); PluginResult parse_sync_account_data(const rapidjson::Value &account_data_json, std::optional> &dm_rooms); - PluginResult parse_sync_room_data(const rapidjson::Value &rooms_json); + PluginResult parse_sync_room_data(const rapidjson::Value &rooms_json, bool is_additional_messages_sync); PluginResult get_previous_room_messages(RoomData *room_data, bool latest_messages); void events_add_user_info(const rapidjson::Value &events_json, RoomData *room_data); std::shared_ptr parse_user_info(const rapidjson::Value &json, const std::string &user_id, RoomData *room_data); @@ -465,7 +473,8 @@ namespace QuickMedia { PluginResult upload_file(RoomData *room, const std::string &filepath, UploadInfo &file_info, UploadInfo &thumbnail_info, std::string &err_msg); void add_room(std::unique_ptr room); void remove_room(const std::string &room_id); - void set_invite(const std::string &room_id, Invite invite); + // Returns false if an invite to the room already exists + bool set_invite(const std::string &room_id, Invite invite); // Returns true if an invite for |room_id| exists bool remove_invite(const std::string &room_id); void set_next_batch(std::string new_next_batch); @@ -489,6 +498,7 @@ namespace QuickMedia { std::mutex invite_mutex; std::thread sync_thread; + std::thread sync_additional_messages_thread; std::thread notification_thread; bool sync_running = false; bool sync_failed = false; diff --git a/plugins/NyaaSi.hpp b/plugins/NyaaSi.hpp index bad5863..13cc437 100644 --- a/plugins/NyaaSi.hpp +++ b/plugins/NyaaSi.hpp @@ -8,6 +8,7 @@ namespace QuickMedia { NyaaSiCategoryPage(Program *program) : Page(program) {} const char* get_title() const override { return "Select category"; } PluginResult submit(const std::string &title, const std::string &url, std::vector &result_tabs) override; + bool clear_search_after_submit() override { return true; } void get_categories(BodyItems &result_items); }; diff --git a/plugins/Page.hpp b/plugins/Page.hpp index 28c2bd6..54e7383 100644 --- a/plugins/Page.hpp +++ b/plugins/Page.hpp @@ -35,6 +35,7 @@ namespace QuickMedia { (void)result_tabs; return PluginResult::ERR; } + virtual bool clear_search_after_submit() { return false; } // Note: If pagination is done by fetching the next page until we get to |page|, then the "current page" should be reset everytime |search| is called. // Note: the first page is 0 virtual PluginResult get_page(const std::string &str, int page, BodyItems &result_items) { (void)str; (void)page; (void)result_items; return PluginResult::OK; } -- cgit v1.2.3