diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-07-26 17:35:52 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-07-26 17:35:52 +0200 |
commit | a6bba48faa091932b5a51a3beb8c9d162c377adf (patch) | |
tree | 9b7e2de493e04e8eaf291f981f70d273b2dd7baf /src/QuickMedia.cpp | |
parent | 9775a6bb77930a6e3b60445675990a8c01777aea (diff) |
Matrix: add /join and /invite commands
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r-- | src/QuickMedia.cpp | 40 |
1 files changed, 39 insertions, 1 deletions
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<Tab> new_tabs; + new_tabs.push_back(Tab{create_body(), std::make_unique<MatrixInviteUserPage>(this, matrix, current_room->id), create_search_bar("Search...", 350)}); + page_loop(new_tabs); + + redraw = true; + avatar_applied = false; + break; + } default: break; } |