From 0b0ab1e5a451cdd6ae5fd2166314037c1997d292 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 21 May 2021 01:36:00 +0200 Subject: Jump to room when submitting notification --- include/QuickMedia.hpp | 2 +- plugins/Matrix.hpp | 18 ++++++++++------- src/QuickMedia.cpp | 53 +++++++++++++++++++++++++++----------------------- src/plugins/Matrix.cpp | 35 ++++++++++++++++++++++++--------- 4 files changed, 67 insertions(+), 41 deletions(-) diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp index 6ab910d..678451d 100644 --- a/include/QuickMedia.hpp +++ b/include/QuickMedia.hpp @@ -118,7 +118,7 @@ namespace QuickMedia { void image_continuous_page(MangaImagesPage *images_page); void image_board_thread_page(ImageBoardThreadPage *thread_page, Body *thread_body); void chat_login_page(); - bool chat_page(MatrixChatPage *matrix_chat_page, RoomData *current_room, std::vector &room_tabs, int room_selected_tab); + bool chat_page(MatrixChatPage *matrix_chat_page, RoomData *current_room); void after_matrix_login_page(); void download_page(const char *url, bool download_use_youtube_dl); // Returns the full path where the file should be saved, or an empty string if the operation was cancelled diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp index bcb4058..1c71733 100644 --- a/plugins/Matrix.hpp +++ b/plugins/Matrix.hpp @@ -213,7 +213,7 @@ namespace QuickMedia { bool message_contains_user_mention(const std::string &msg, const std::string &username); bool message_is_timeline(Message *message); - void body_set_selected_item(Body *body, BodyItem *selected_item); + void body_set_selected_item_by_url(Body *body, const std::string &url); std::string create_transaction_id(); enum class MatrixPageType { @@ -312,7 +312,7 @@ namespace QuickMedia { class MatrixRoomsPage : public Page { public: - MatrixRoomsPage(Program *program, Body *body, std::string title, MatrixRoomTagsPage *room_tags_page); + MatrixRoomsPage(Program *program, Body *body, std::string title, MatrixRoomTagsPage *room_tags_page, SearchBar *search_bar); ~MatrixRoomsPage() override; const char* get_title() const override { return title.c_str(); } @@ -330,14 +330,17 @@ namespace QuickMedia { void set_room_as_read(RoomData *room); + void clear_search(); + void clear_data(); MatrixQuickMedia *matrix_delegate = nullptr; - private: Body *body = nullptr; + private: std::string title; MatrixRoomTagsPage *room_tags_page = nullptr; MatrixChatPage *current_chat_page = nullptr; + SearchBar *search_bar; }; class MatrixRoomTagsPage : public Page { @@ -477,20 +480,21 @@ namespace QuickMedia { class MatrixNotificationsPage : public LazyFetchPage { public: - MatrixNotificationsPage(Program *program, Matrix *matrix, Body *notifications_body); + MatrixNotificationsPage(Program *program, Matrix *matrix, Body *notifications_body, MatrixRoomsPage *all_rooms_page); const char* get_title() const override { return "Notifications"; } - PluginResult submit(const std::string&, const std::string&, std::vector&) override { - return PluginResult::OK; - } + PluginResult submit(const std::string&, const std::string&, std::vector&) override; PluginResult get_page(const std::string &str, int page, BodyItems &result_items) override; PluginResult lazy_fetch(BodyItems &result_items) override; bool is_ready() override; + bool submit_is_async() override { return false; } + bool clear_search_after_submit() override { return true; } void add_notification(MatrixNotification notification); void set_room_as_read(RoomData *room); private: Matrix *matrix; Body *notifications_body; + MatrixRoomsPage *all_rooms_page; }; class Matrix { diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 815ab45..9f21c34 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -1690,29 +1690,33 @@ namespace QuickMedia { int selected_index = tabs[selected_tab].body->get_selected_item(); video_content_page(tabs[selected_tab].page.get(), static_cast(new_tabs[0].page.get()), selected_item->get_title(), false, tabs[selected_tab].body->items, selected_index, &tab_associated_data[selected_tab].fetched_page, tab_associated_data[selected_tab].update_search_text); } else if(new_tabs.size() == 1 && new_tabs[0].page->get_type() == PageTypez::CHAT) { - body_set_selected_item(tabs[selected_tab].body.get(), selected_item.get()); + MatrixChatPage *tmp_matrix_chat_page = static_cast(new_tabs[0].page.get()); + MatrixRoomsPage *rooms_page = tmp_matrix_chat_page->rooms_page; + Body *room_list_body = rooms_page->body; + rooms_page->clear_search(); + + body_set_selected_item_by_url(room_list_body, tmp_matrix_chat_page->room_id); current_page = PageType::CHAT; - current_chat_room = matrix->get_room_by_id(selected_item->url); - MatrixRoomsPage *rooms_page = static_cast(tabs[selected_tab].page.get()); + current_chat_room = matrix->get_room_by_id(tmp_matrix_chat_page->room_id); while(window.isOpen()) { auto matrix_chat_page = std::make_unique(this, current_chat_room->id, rooms_page); - bool move_room = chat_page(matrix_chat_page.get(), current_chat_room, tabs, selected_tab); + bool move_room = chat_page(matrix_chat_page.get(), current_chat_room); matrix_chat_page->messages_tab_visible = false; if(!move_room) break; - BodyItem *selected_item = tabs[selected_tab].body->get_selected(); + BodyItem *selected_item = room_list_body->get_selected(); if(!selected_item) break; current_chat_room = matrix->get_room_by_id(selected_item->url); } - tabs[selected_tab].body->body_item_select_callback = [&submit_handler](BodyItem *body_item) { + room_list_body->body_item_select_callback = [&submit_handler](BodyItem *body_item) { submit_handler(body_item->get_title()); }; - //select_body_item_by_room(tabs[selected_tab].body.get(), current_chat_room); + current_chat_room = nullptr; } else { page_loop(new_tabs, 0, after_submit_handler); @@ -3981,7 +3985,7 @@ namespace QuickMedia { return default_value; } - bool Program::chat_page(MatrixChatPage *matrix_chat_page, RoomData *current_room, std::vector &room_tabs, int room_selected_tab) { + bool Program::chat_page(MatrixChatPage *matrix_chat_page, RoomData *current_room) { assert(current_room); assert(strcmp(plugin_name, "matrix") == 0); if(!current_room) { @@ -4101,7 +4105,7 @@ namespace QuickMedia { sf::Text room_topic_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), room_topic_text_height); room_topic_text.setFillColor(sf::Color(179, 179, 179)); - sf::Text room_label(room_tabs[room_selected_tab].page->get_title(), *FontLoader::get_font(FontLoader::FontType::LATIN_BOLD), std::floor(18 * get_ui_scale())); + sf::Text room_label(matrix_chat_page->rooms_page->get_title(), *FontLoader::get_font(FontLoader::FontType::LATIN_BOLD), std::floor(18 * get_ui_scale())); room_label.setPosition(15.0f, room_name_text_padding_y + 4.0f); sf::Sprite room_avatar_sprite; @@ -5080,7 +5084,7 @@ namespace QuickMedia { float tab_shade_height = 0.0f; SyncData sync_data; - room_tabs[room_selected_tab].body->body_item_select_callback = [&move_room](BodyItem *body_item) { + matrix_chat_page->rooms_page->body->body_item_select_callback = [&move_room](BodyItem *body_item) { move_room = true; }; @@ -5130,33 +5134,33 @@ namespace QuickMedia { } if(draw_room_list) { - if(room_tabs[room_selected_tab].body->on_event(window, event, false)) + if(matrix_chat_page->rooms_page->body->on_event(window, event, false)) idle_active_handler(); } if(event.type == sf::Event::KeyPressed && event.key.control && event.key.alt && (chat_state == ChatState::NAVIGATING || chat_state == ChatState::URL_SELECTION)) { if(event.key.code == sf::Keyboard::Up || (event.key.control && event.key.code == sf::Keyboard::K)) { - room_tabs[room_selected_tab].body->select_previous_item(); + matrix_chat_page->rooms_page->body->select_previous_item(); move_room = true; goto chat_page_end; } else if(event.key.code == sf::Keyboard::Down || (event.key.control && event.key.code == sf::Keyboard::J)) { - room_tabs[room_selected_tab].body->select_next_item(); + matrix_chat_page->rooms_page->body->select_next_item(); move_room = true; goto chat_page_end; } else if(event.key.code == sf::Keyboard::PageUp) { - room_tabs[room_selected_tab].body->select_previous_page(); + matrix_chat_page->rooms_page->body->select_previous_page(); move_room = true; goto chat_page_end; } else if(event.key.code == sf::Keyboard::PageDown) { - room_tabs[room_selected_tab].body->select_next_page(); + matrix_chat_page->rooms_page->body->select_next_page(); move_room = true; goto chat_page_end; } else if(event.key.code == sf::Keyboard::Home) { - room_tabs[room_selected_tab].body->select_first_item(); + matrix_chat_page->rooms_page->body->select_first_item(); move_room = true; goto chat_page_end; } else if(event.key.code == sf::Keyboard::End) { - room_tabs[room_selected_tab].body->select_last_item(); + matrix_chat_page->rooms_page->body->select_last_item(); move_room = true; goto chat_page_end; } else if(event.key.code == sf::Keyboard::Escape) { @@ -5667,7 +5671,7 @@ namespace QuickMedia { window.draw(room_label); const float padding_x = std::floor(10.0f * get_ui_scale()); const float tab_y = std::floor(tab_vertical_offset) + room_name_padding_y; - room_tabs[room_selected_tab].body->draw(window, sf::Vector2f(padding_x, tab_y), sf::Vector2f(this->body_size.x - padding_x * 2.0f, window_size.y - tab_y), Json::Value::nullSingleton()); + matrix_chat_page->rooms_page->body->draw(window, sf::Vector2f(padding_x, tab_y), sf::Vector2f(this->body_size.x - padding_x * 2.0f, window_size.y - tab_y), Json::Value::nullSingleton()); glDisable(GL_SCISSOR_TEST); } @@ -5893,15 +5897,16 @@ namespace QuickMedia { if(!window.isOpen()) exit(exit_code); - auto notifications_body = create_body(); - //notifications_body->attach_side = AttachSide::BOTTOM; - auto matrix_notifications_page = std::make_unique(this, matrix, notifications_body.get()); - auto rooms_tags_body = create_body(); auto matrix_rooms_tag_page = std::make_unique(this, rooms_tags_body.get()); auto rooms_body = create_body(); - auto matrix_rooms_page = std::make_unique(this, rooms_body.get(), "All rooms", nullptr); + auto rooms_page_search_bar = create_search_bar("Search...", SEARCH_DELAY_FILTER); + auto matrix_rooms_page = std::make_unique(this, rooms_body.get(), "All rooms", nullptr, rooms_page_search_bar.get()); + + auto notifications_body = create_body(); + //notifications_body->attach_side = AttachSide::BOTTOM; + auto matrix_notifications_page = std::make_unique(this, matrix, notifications_body.get(), matrix_rooms_page.get()); auto invites_body = create_body(); auto matrix_invites_page = std::make_unique(this, matrix, invites_body.get()); @@ -5936,7 +5941,7 @@ namespace QuickMedia { std::vector tabs; tabs.push_back(Tab{std::move(notifications_body), std::move(matrix_notifications_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); tabs.push_back(Tab{std::move(rooms_tags_body), std::move(matrix_rooms_tag_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); - tabs.push_back(Tab{std::move(rooms_body), std::move(matrix_rooms_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); + tabs.push_back(Tab{std::move(rooms_body), std::move(matrix_rooms_page), std::move(rooms_page_search_bar)}); tabs.push_back(Tab{std::move(invites_body), std::move(matrix_invites_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); tabs.push_back(Tab{std::move(room_directory_body), std::move(matrix_room_directory_page), create_search_bar("Server to search on...", SEARCH_DELAY_FILTER)}); diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 1e1e41b..0577948 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -519,9 +519,9 @@ namespace QuickMedia { body_items.push_back(std::move(new_body_item)); } - void body_set_selected_item(Body *body, BodyItem *selected_item) { + void body_set_selected_item_by_url(Body *body, const std::string &url) { for(size_t i = 0; i < body->items.size(); ++i) { - if(body->items[i]->url == selected_item->url) { + if(body->items[i]->url == url) { body->select_first_item(); body->set_selected_item(i, false); return; @@ -641,7 +641,9 @@ namespace QuickMedia { } } - MatrixRoomsPage::MatrixRoomsPage(Program *program, Body *body, std::string title, MatrixRoomTagsPage *room_tags_page) : Page(program), body(body), title(std::move(title)), room_tags_page(room_tags_page) { + MatrixRoomsPage::MatrixRoomsPage(Program *program, Body *body, std::string title, MatrixRoomTagsPage *room_tags_page, SearchBar *search_bar) : + Page(program), body(body), title(std::move(title)), room_tags_page(room_tags_page), search_bar(search_bar) + { if(room_tags_page) room_tags_page->set_current_rooms_page(this); } @@ -652,8 +654,7 @@ namespace QuickMedia { } PluginResult MatrixRoomsPage::submit(const std::string&, const std::string &url, std::vector &result_tabs) { - auto chat_page = std::make_unique(program, url, this); - result_tabs.push_back(Tab{nullptr, std::move(chat_page), nullptr}); + result_tabs.push_back(Tab{nullptr, std::make_unique(program, url, this), nullptr}); return PluginResult::OK; } @@ -715,6 +716,11 @@ namespace QuickMedia { matrix_delegate->set_room_as_read(room); } + void MatrixRoomsPage::clear_search() { + search_bar->clear(); + body->filter_search_fuzzy(""); + } + void MatrixRoomsPage::clear_data() { body->clear_items(); if(current_chat_page) @@ -729,9 +735,10 @@ namespace QuickMedia { //BodyItem *selected_item = body->get_selected(); sort_room_body_items(body->items); //body_set_selected_item(body.get(), selected_item); - auto rooms_page = std::make_unique(program, body_ptr, tag_data.tag_item->get_title(), this); + auto search_bar = create_search_bar("Search...", SEARCH_DELAY_FILTER); + auto rooms_page = std::make_unique(program, body_ptr, tag_data.tag_item->get_title(), this, search_bar.get()); rooms_page->matrix_delegate = matrix_delegate; - result_tabs.push_back(Tab{std::move(body), std::move(rooms_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); + result_tabs.push_back(Tab{std::move(body), std::move(rooms_page), std::move(search_bar)}); return PluginResult::OK; } @@ -1066,8 +1073,18 @@ namespace QuickMedia { return body_item; } - MatrixNotificationsPage::MatrixNotificationsPage(Program *program, Matrix *matrix, Body *notifications_body) : - LazyFetchPage(program), matrix(matrix), notifications_body(notifications_body) {} + MatrixNotificationsPage::MatrixNotificationsPage(Program *program, Matrix *matrix, Body *notifications_body, MatrixRoomsPage *all_rooms_page) : + LazyFetchPage(program), matrix(matrix), notifications_body(notifications_body), all_rooms_page(all_rooms_page) {} + + PluginResult MatrixNotificationsPage::submit(const std::string&, const std::string&, std::vector &result_tabs) { + BodyItem *selected_item = notifications_body->get_selected(); + if(!selected_item) + return PluginResult::OK; + + NotificationsExtraData *extra_data = static_cast(selected_item->extra.get()); + result_tabs.push_back(Tab{nullptr, std::make_unique(program, extra_data->room->id, all_rooms_page), nullptr}); + return PluginResult::OK; + } PluginResult MatrixNotificationsPage::get_page(const std::string&, int, BodyItems &result_items) { return matrix->get_previous_notifications([this, &result_items](const MatrixNotification ¬ification) { -- cgit v1.2.3