From 90c13efab1fd1b67625ec23815ccc195803e230e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 28 Sep 2020 00:21:23 +0200 Subject: Matrix: fix login with pantalaimon proxy, fix logout crash, show real login error --- src/QuickMedia.cpp | 76 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 32 deletions(-) (limited to 'src/QuickMedia.cpp') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index c2c0004..e07c30a 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -3172,7 +3172,6 @@ namespace QuickMedia { // so you dont have to retype a post that was in the middle of being posted when returning. } - // TODO: Provide a way to logout void Program::chat_login_page() { assert(current_plugin->name == "matrix"); @@ -3351,9 +3350,11 @@ namespace QuickMedia { // TODO: Filer for rooms and settings chat_input.onTextUpdateCallback = nullptr; + Page new_page = Page::CHAT; + // TODO: Show post message immediately, instead of waiting for sync. Otherwise it can take a while until we receive the message, // which happens when uploading an image. - chat_input.onTextSubmitCallback = [this, matrix, &tabs, &selected_tab, ¤t_room_id](const std::string &text) -> bool { + chat_input.onTextSubmitCallback = [matrix, &tabs, &selected_tab, ¤t_room_id, &new_page](const std::string &text) -> bool { if(tabs[selected_tab].type == ChatTabType::MESSAGES) { if(text.empty()) return false; @@ -3362,37 +3363,10 @@ namespace QuickMedia { std::string command = text; strip(command); if(command == "/upload") { - if(!file_manager) - file_manager = new FileManager(); - page_stack.push(Page::CHAT); - current_page = Page::FILE_MANAGER; - file_manager_page(); - if(selected_files.empty()) { - fprintf(stderr, "No files selected!\n"); - return true; - } else { - // TODO: Make asynchronous. - // TODO: Upload multiple files. - if(matrix->post_file(current_room_id, selected_files[0]) != PluginResult::OK) { - show_notification("QuickMedia", "Failed to upload image to room", Urgency::CRITICAL); - return false; - } else { - return true; - } - } + new_page = Page::FILE_MANAGER; + return true; } else if(command == "/logout") { - matrix->logout(); - tabs[MESSAGES_TAB_INDEX].body->clear_thumbnails(); - // TODO: Instead of doing this, exit this current function and navigate to chat login page instead. - // This doesn't currently work because at the end of this function there are futures that need to wait - // and one of them is /sync, which has a timeout of 30 seconds. That timeout has to be killed somehow. - delete current_plugin; - current_plugin = new Matrix(); - current_page = Page::CHAT_LOGIN; - chat_login_page(); - if(current_page == Page::CHAT) - chat_page(); - exit(0); + new_page = Page::CHAT_LOGIN; return true; } else { fprintf(stderr, "Error: invalid command: %s, expected /upload\n", command.c_str()); @@ -3567,6 +3541,44 @@ namespace QuickMedia { } } + switch(new_page) { + case Page::FILE_MANAGER: { + new_page = Page::CHAT; + if(!file_manager) + file_manager = new FileManager(); + page_stack.push(Page::CHAT); + current_page = Page::FILE_MANAGER; + file_manager_page(); + if(selected_files.empty()) { + fprintf(stderr, "No files selected!\n"); + } else { + // TODO: Make asynchronous. + // TODO: Upload multiple files. + if(matrix->post_file(current_room_id, selected_files[0]) != PluginResult::OK) + show_notification("QuickMedia", "Failed to upload image to room", Urgency::CRITICAL); + } + break; + } + case Page::CHAT_LOGIN: { + new_page = Page::CHAT; + matrix->logout(); + tabs[MESSAGES_TAB_INDEX].body->clear_thumbnails(); + // TODO: Instead of doing this, exit this current function and navigate to chat login page instead. + // This doesn't currently work because at the end of this function there are futures that need to wait + // and one of them is /sync, which has a timeout of 30 seconds. That timeout has to be killed somehow. + //delete current_plugin; + //current_plugin = new Matrix(); + current_page = Page::CHAT_LOGIN; + chat_login_page(); + if(current_page == Page::CHAT) + chat_page(); + exit(0); + break; + } + default: + break; + } + if(typing && start_typing_timer.getElapsedTime().asSeconds() >= typing_timeout_seconds) { fprintf(stderr, "Stopped typing\n"); typing = false; -- cgit v1.2.3