From a6bba48faa091932b5a51a3beb8c9d162c377adf Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 26 Jul 2021 17:35:52 +0200 Subject: Matrix: add /join and /invite commands --- src/QuickMedia.cpp | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'src/QuickMedia.cpp') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 07d6640..f8566fa 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -5045,6 +5045,29 @@ namespace QuickMedia { chat_input.set_editable(false); chat_state = ChatState::NAVIGATING; return true; + } else if(strncmp(text.c_str(), "/join ", 6) == 0) { + text.erase(text.begin(), text.begin() + 6); + text = strip(text); + if(text.empty()) { + return false; + } else { + TaskResult task_result = run_task_with_loading_screen([this, text{std::move(text)}] { + return matrix->join_room(text) == PluginResult::OK; + }); + + if(task_result == TaskResult::TRUE) { + chat_input.set_editable(false); + chat_state = ChatState::NAVIGATING; + return true; + } else { + return false; + } + } + } else if(text == "/invite") { + new_page = PageType::CHAT_INVITE; + chat_input.set_editable(false); + chat_state = ChatState::NAVIGATING; + return true; } else if(text == "/logout") { new_page = PageType::CHAT_LOGIN; chat_input.set_editable(false); @@ -5067,7 +5090,7 @@ namespace QuickMedia { msgtype = "m.reaction"; text.erase(text.begin(), text.begin() + 7); } else { - show_notification("QuickMedia", "Error: invalid command: " + text + ", expected /upload, /logout, /me or /react", Urgency::NORMAL); + show_notification("QuickMedia", "Error: invalid command: " + text + ", expected /upload, /join [room], /invite, /logout, /me [text] or /react [text]", Urgency::NORMAL); return false; } } else if(chat_state == ChatState::REPLYING && text[0] == '/') { @@ -5968,6 +5991,21 @@ namespace QuickMedia { exit(exit_code); break; } + case PageType::CHAT_INVITE: { + new_page = PageType::CHAT; + + for(ChatTab &tab : tabs) { + tab.body->clear_cache(); + } + + std::vector new_tabs; + new_tabs.push_back(Tab{create_body(), std::make_unique(this, matrix, current_room->id), create_search_bar("Search...", 350)}); + page_loop(new_tabs); + + redraw = true; + avatar_applied = false; + break; + } default: break; } -- cgit v1.2.3