aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-23 08:06:22 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-23 08:18:08 +0200
commit8f73d303b96d35ccec9856fc0043a74c8800536b (patch)
tree8c97971ab356fa5f2b463ba97efd768b0908e0a7 /src
parentaa9a861c662f7c65cde92fbf133deaca3692bbd2 (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.
Diffstat (limited to 'src')
-rw-r--r--src/Body.cpp6
-rw-r--r--src/QuickMedia.cpp25
2 files changed, 24 insertions, 7 deletions
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, &current_room, &new_page, &chat_state, &currently_operating_on_item](const std::string &text) mutable {
+ chat_input.on_submit_callback = [this, &tabs, &chat_input, &selected_tab, &current_room, &new_page, &chat_state, &currently_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);
}