aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp41
-rw-r--r--src/plugins/Matrix.cpp16
2 files changed, 39 insertions, 18 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index f793559..c2c0004 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -346,7 +346,7 @@ namespace QuickMedia {
plugin_logo_path = resources_root + "images/nyaa_si_logo.png";
} else if(strcmp(argv[i], "matrix") == 0) {
current_plugin = new Matrix();
- //plugin_logo_path = resources_root + "images/matrix_logo.png";
+ plugin_logo_path = resources_root + "images/matrix_logo.png";
} else if(strcmp(argv[i], "file-manager") == 0) {
current_plugin = new FileManager();
} else if(strcmp(argv[i], "dmenu") == 0) {
@@ -3342,17 +3342,6 @@ namespace QuickMedia {
// get_all_room_messages is not needed here because its done in the loop, where the initial timeout is 0ms
- {
- assert(plugin_logo.getNativeHandle() == 0); // Only load once
- std::string plugin_logo_path = resources_root + "images/matrix_logo.png";
- if(!plugin_logo.loadFromFile(plugin_logo_path)) {
- show_notification("QuickMedia", "Failed to load plugin logo, path: " + plugin_logo_path, Urgency::CRITICAL);
- exit(1);
- }
- plugin_logo.generateMipmap();
- plugin_logo.setSmooth(true);
- }
-
SearchBar chat_input(*font, &plugin_logo, "Send a message...");
chat_input.set_background_color(sf::Color::Transparent);
chat_input.padding_vertical = 10.0f;
@@ -3391,6 +3380,20 @@ namespace QuickMedia {
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);
+ return true;
} else {
fprintf(stderr, "Error: invalid command: %s, expected /upload\n", command.c_str());
return false;
@@ -3437,6 +3440,8 @@ namespace QuickMedia {
const double typing_timeout_seconds = 3.0;
bool typing = false;
+ const float tab_vertical_offset = 10.0f;
+
auto typing_async_func = [matrix](bool new_state, std::string room_id) {
if(new_state) {
matrix->on_start_typing(room_id);
@@ -3583,25 +3588,26 @@ namespace QuickMedia {
++it;
}
+ const float tab_shade_height = tab_spacer_height + std::floor(tab_vertical_offset) + tab_height + 10.0f;
+
if(redraw) {
redraw = false;
chat_input.onWindowResize(window_size);
chat_input.set_vertical_position(window_size.y - chat_input.getBottomWithoutShadow());
float body_padding_horizontal = 25.0f;
- float body_padding_vertical = 25.0f;
+ float body_padding_vertical = 5.0f;
float body_width = window_size.x - body_padding_horizontal * 2.0f;
if(body_width <= 480.0f) {
body_width = window_size.x;
body_padding_horizontal = 0.0f;
- body_padding_vertical = 10.0f;
}
float input_bottom = chat_input.getBottomWithoutShadow();
if(tabs[selected_tab].type != ChatTabType::MESSAGES)
input_bottom = 0.0f;
- body_pos = sf::Vector2f(body_padding_horizontal, body_padding_vertical + tab_height);
- body_size = sf::Vector2f(body_width, window_size.y - input_bottom - body_padding_vertical - tab_height);
+ body_pos = sf::Vector2f(body_padding_horizontal, body_padding_vertical + tab_shade_height);
+ body_size = sf::Vector2f(body_width, window_size.y - input_bottom - body_padding_vertical - tab_shade_height);
//get_body_dimensions(window_size, &chat_input, body_pos, body_size, true);
}
@@ -3661,11 +3667,10 @@ namespace QuickMedia {
const float width_per_tab = window_size.x / tabs.size();
tab_background.setSize(sf::Vector2f(std::floor(width_per_tab - tab_margin_x * 2.0f), tab_height));
- float tab_vertical_offset = 10.0f;
+
tabs[selected_tab].body->draw(window, body_pos, body_size);
const float tab_y = tab_spacer_height + std::floor(tab_vertical_offset + tab_height * 0.5f - (tab_text_size + 5.0f) * 0.5f);
- const float tab_shade_height = tab_spacer_height + std::floor(tab_vertical_offset) + tab_height + 10.0f;
tab_shade.setSize(sf::Vector2f(window_size.x, tab_shade_height));
window.draw(tab_shade);
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 2321ff4..8b819a2 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -943,6 +943,22 @@ namespace QuickMedia {
return PluginResult::OK;
}
+ PluginResult Matrix::logout() {
+ Path session_path = get_storage_dir().join(name).join("session.json");
+ remove(session_path.data.c_str());
+
+ std::vector<CommandArg> additional_args = {
+ { "-X", "POST" },
+ { "-H", "Authorization: Bearer " + access_token }
+ };
+
+ std::string server_response;
+ if(download_to_string(homeserver + "/_matrix/client/r0/logout", server_response, std::move(additional_args), use_tor, true) != DownloadResult::OK)
+ return PluginResult::NET_ERR;
+
+ return PluginResult::OK;
+ }
+
PluginResult Matrix::load_and_verify_cached_session() {
Path session_path = get_storage_dir().join(name).join("session.json");
std::string session_json_content;