From 555f0e7e910b2231073734816727379e1276aa6c Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 29 Oct 2022 19:31:22 +0200 Subject: Matrix: add media reply with ctrl+u --- src/QuickMedia.cpp | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'src/QuickMedia.cpp') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 57c5489..13931d2 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -5864,15 +5864,19 @@ namespace QuickMedia { } }; - auto upload_file = [this, ¤t_room](const std::string &filepath, const std::string &filename) { - run_task_with_loading_screen([this, ¤t_room, filepath, filename]() { + auto upload_file = [this, ¤t_room, &tabs, &ui_tabs, &chat_state](const std::string &filepath, const std::string &filename) { + const int selected_tab = ui_tabs.get_selected(); + std::shared_ptr selected = tabs[selected_tab].body->get_selected_shared(); + void *message_to_reply_to = chat_state == ChatState::REPLYING ? selected->userdata : nullptr; + + run_task_with_loading_screen([this, ¤t_room, filepath, filename, message_to_reply_to]() { std::string filepath_mod = filepath; if(string_starts_with(filepath_mod, "file://")) filepath_mod.erase(filepath_mod.begin(), filepath_mod.begin() + 7); std::string event_id_response; std::string err_msg; - if(matrix->post_file(current_room, filepath_mod, filename, event_id_response, err_msg) == PluginResult::OK) { + if(matrix->post_file(current_room, filepath_mod, filename, event_id_response, err_msg, message_to_reply_to) == PluginResult::OK) { return true; } else { show_notification("QuickMedia", "Failed to upload media to room, error: " + err_msg, Urgency::CRITICAL); @@ -7102,6 +7106,14 @@ namespace QuickMedia { continue; launch_url(selected_item->get_title()); } + } else if(event.type == mgl::Event::KeyPressed && chat_state == ChatState::REPLYING) { + if(selected_tab == MESSAGES_TAB_INDEX) { + if(event.key.code == mgl::Keyboard::U && event.key.control) { + frame_skip_text_entry = true; + new_page = PageType::FILE_MANAGER; + chat_input.set_editable(false); + } + } } if((chat_state == ChatState::TYPING_MESSAGE || chat_state == ChatState::REPLYING || chat_state == ChatState::EDITING) && selected_tab == MESSAGES_TAB_INDEX && !frame_skip_text_entry) { @@ -7190,6 +7202,22 @@ namespace QuickMedia { } redraw = true; avatar_applied = false; + + if(selected_files.empty()) { + if(chat_state == ChatState::REPLYING) + chat_input.set_editable(true); + } else { + mention.hide(); + chat_input.set_editable(false); + chat_input.set_text(""); + chat_state = ChatState::NAVIGATING; + currently_operating_on_item = nullptr; + if(typing && current_room) { + fprintf(stderr, "Stopped typing\n"); + typing = false; + typing_state_queue.push(false); + } + } break; } case PageType::CHAT_LOGIN: { -- cgit v1.2.3