diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-10-23 08:06:22 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-10-23 08:18:08 +0200 |
commit | 8f73d303b96d35ccec9856fc0043a74c8800536b (patch) | |
tree | 8c97971ab356fa5f2b463ba97efd768b0908e0a7 | |
parent | aa9a861c662f7c65cde92fbf133deaca3692bbd2 (diff) |
Cleanup embedded item if embedded item refers to a new item, scroll to bottom when posting message/media and last item is already visible
Also show "Loading..." while checking if our matrix token is still
valid.
-rw-r--r-- | TODO | 3 | ||||
-rw-r--r-- | src/Body.cpp | 6 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 25 |
3 files changed, 26 insertions, 8 deletions
@@ -115,4 +115,5 @@ Load the replied-to message in the pinned messages tab. Pressing enter on a pinned message should go to the message in the messages tab. Cache pinned messages on disk (messages by event id), but take into consider edits? for example if one message is pinned in the room and then edited multiple times (such as room rules). In that case cache the pinned message to quickly display it and then fetch the latest version from the server and then replace the message with the latest version. Display file list for nyaa. -Remove reply formatting for NOTICE in matrix as well.
\ No newline at end of file +Remove reply formatting for NOTICE in matrix as well. +Scroll body when adding new items and the selected item fits after the scroll (needed for matrix where we want to see new messages when the last item is not selected). Or show the last item when its not visible in matrix (at the bottom, just like when replying/editing).
\ No newline at end of file diff --git a/src/Body.cpp b/src/Body.cpp index 20e7404..3fd2324 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -461,9 +461,11 @@ namespace QuickMedia { // TODO: Only do this for items that are not visible, do not loop all items. // TODO: Improve performance! right now it can use up to 5-7% cpu with a lot of items! for(auto &body_item : items) { - if(elapsed_time_sec - body_item->last_drawn_time >= 1.5) { + if(elapsed_time_sec - body_item->last_drawn_time >= 1.5) + clear_body_item_cache(body_item.get()); + // The embedded item might or might not refer to another item in |items|, so we have to make sure we also check it + if(body_item->embedded_item && elapsed_time_sec - body_item->embedded_item->last_drawn_time >= 1.5) clear_body_item_cache(body_item.get()); - } } } diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 6d8f493..7840326 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -621,6 +621,14 @@ namespace QuickMedia { if(matrix) { matrix->use_tor = use_tor; + { + auto window_size = window.getSize(); + sf::Text loading_text("Loading...", *font.get(), 24); + loading_text.setPosition(window_size.x * 0.5f - loading_text.getLocalBounds().width * 0.5f, window_size.y * 0.5f - loading_text.getLocalBounds().height * 0.5f); + window.clear(back_color); + window.draw(loading_text); + window.display(); + } if(matrix->load_and_verify_cached_session() == PluginResult::OK) { current_page = PageType::CHAT; } else { @@ -3277,7 +3285,7 @@ namespace QuickMedia { chat_input.draw_background = false; chat_input.set_editable(false); - chat_input.on_submit_callback = [this, &chat_input, &selected_tab, ¤t_room, &new_page, &chat_state, ¤tly_operating_on_item](const std::string &text) mutable { + chat_input.on_submit_callback = [this, &tabs, &chat_input, &selected_tab, ¤t_room, &new_page, &chat_state, ¤tly_operating_on_item](const std::string &text) mutable { if(!current_room) return false; @@ -3308,6 +3316,8 @@ namespace QuickMedia { if(matrix->post_message(current_room, text, std::nullopt, std::nullopt) == PluginResult::OK) { chat_input.set_editable(false); chat_state = ChatState::NAVIGATING; + if(tabs[MESSAGES_TAB_INDEX].body->is_last_item_fully_visible()) + tabs[MESSAGES_TAB_INDEX].body->select_last_item(); return true; } else { show_notification("QuickMedia", "Failed to post matrix message", Urgency::CRITICAL); @@ -3319,6 +3329,8 @@ namespace QuickMedia { chat_input.set_editable(false); chat_state = ChatState::NAVIGATING; currently_operating_on_item = nullptr; + if(tabs[MESSAGES_TAB_INDEX].body->is_last_item_fully_visible()) + tabs[MESSAGES_TAB_INDEX].body->select_last_item(); return true; } else { show_notification("QuickMedia", "Failed to post matrix reply", Urgency::CRITICAL); @@ -3808,11 +3820,11 @@ namespace QuickMedia { file_manager_page->set_current_directory(get_home_dir().data); auto file_manager_body = create_body(); file_manager_page->get_files_in_directory(file_manager_body->items); - std::vector<Tab> tabs; - tabs.push_back(Tab{std::move(file_manager_body), std::move(file_manager_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); + std::vector<Tab> file_manager_tabs; + file_manager_tabs.push_back(Tab{std::move(file_manager_body), std::move(file_manager_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); selected_files.clear(); - page_loop(std::move(tabs)); + page_loop(std::move(file_manager_tabs)); if(selected_files.empty()) { fprintf(stderr, "No files selected!\n"); @@ -3820,7 +3832,10 @@ namespace QuickMedia { // TODO: Make asynchronous. // TODO: Upload multiple files. std::string err_msg; - if(matrix->post_file(current_room, selected_files[0], err_msg) != PluginResult::OK) { + if(matrix->post_file(current_room, selected_files[0], err_msg) == PluginResult::OK) { + if(tabs[MESSAGES_TAB_INDEX].body->is_last_item_fully_visible()) + tabs[MESSAGES_TAB_INDEX].body->select_last_item(); + } else { std::string desc = "Failed to upload media to room, error: " + err_msg; show_notification("QuickMedia", desc.c_str(), Urgency::CRITICAL); } |