From 118ea78d95a82d9f943180c8f976befc5d2dc97e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 11 Mar 2023 23:12:25 +0100 Subject: Matrix: allow pressing enter on a message with a room alias to join the room --- src/QuickMedia.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/QuickMedia.cpp') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index fb96dfb..5bdbdb1 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -6064,11 +6064,12 @@ namespace QuickMedia { if(text.empty()) { return false; } else { - TaskResult task_result = run_task_with_loading_screen([this, text{std::move(text)}] { + TaskResult task_result = run_task_with_loading_screen([this, &text] { return matrix->join_room(text) == PluginResult::OK; }); if(task_result == TaskResult::TRUE) { + show_notification("QuickMedia", "You joined " + text, Urgency::NORMAL); chat_input.set_editable(false); chat_state = ChatState::NAVIGATING; return true; @@ -6701,18 +6702,29 @@ namespace QuickMedia { } } + std::vector room_ids = matrix_extract_room_ids(selected->get_description()); + // TODO: If content type is a file, show file-manager prompt where it should be saved and asynchronously save it instead std::vector urls = ranges_get_strings(selected->get_description(), extract_urls(selected->get_description())); - if(urls.size() == 1) { + if(urls.size() == 1 && room_ids.empty()) { launch_url(urls[0]); return true; - } else if(urls.size() > 1) { + } else if(!urls.empty() || !room_ids.empty()) { chat_state = ChatState::URL_SELECTION; url_selection_body.clear_items(); + for(const std::string &url : urls) { auto body_item = BodyItem::create(url); + body_item->url = url; + url_selection_body.append_item(std::move(body_item)); + } + + for(const std::string &room_id : room_ids) { + auto body_item = BodyItem::create("Join " + room_id); + body_item->url = room_id; url_selection_body.append_item(std::move(body_item)); } + return true; } return false; @@ -7285,7 +7297,17 @@ namespace QuickMedia { BodyItem *selected_item = url_selection_body.get_selected(); if(!selected_item) continue; - launch_url(selected_item->get_title()); + + if(!selected_item->url.empty() && (selected_item->url[0] == '#' || selected_item->url[0] == '!')) { + TaskResult task_result = run_task_with_loading_screen([this, selected_item] { + return matrix->join_room(selected_item->url) == PluginResult::OK; + }); + + if(task_result == TaskResult::TRUE) + show_notification("QuickMedia", "You joined " + selected_item->url, Urgency::NORMAL); + } else { + launch_url(selected_item->get_title()); + } } } else if(event.type == mgl::Event::KeyPressed && chat_state == ChatState::REPLYING) { if(selected_tab == MESSAGES_TAB_INDEX) { -- cgit v1.2.3