aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-11-10 11:53:58 +0100
committerdec05eba <dec05eba@protonmail.com>2022-11-10 11:55:24 +0100
commit5d2a7d977f9b0a1604e106f4e2b0c2c9b89c3235 (patch)
tree88622d3dd853a3642ac6f181952af3c7f73aed82
parent60f37ebeb130bd58adece6bee06420b40c4e5a05 (diff)
Matrix: add settings page with join room and logout button
-rw-r--r--TODO2
-rw-r--r--plugins/Matrix.hpp19
-rw-r--r--src/QuickMedia.cpp22
-rw-r--r--src/plugins/Matrix.cpp28
4 files changed, 69 insertions, 2 deletions
diff --git a/TODO b/TODO
index 492b9bf..50571d4 100644
--- a/TODO
+++ b/TODO
@@ -66,7 +66,7 @@ Show images while they download by showing them as scanlines starting from the t
Add functionality to ignore users in matrix. This is done with an ignore request and we wont get messages and invites from that user anymore. Also add option to ignore in the invites page.
Add keybind to go to invites page from any page.
Show marker beside pinned messages tab name if there are new pinned messages.
-Make /logout work everywhere, not only in room message input (or add a logout button to settings tab?).
+Make /logout work everywhere, not only in room message input.
Disable message input in matrix when muted.
Preview rooms?
Handle matrix token being invalidated while running.
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index ac3ca3b..152c292 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -431,6 +431,25 @@ namespace QuickMedia {
const std::string title;
};
+ class MatrixSettingsPage : public Page {
+ public:
+ MatrixSettingsPage(Program *program, Matrix *matrix) : Page(program), matrix(matrix) {}
+ const char* get_title() const override { return "Settings"; }
+ PluginResult submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) override;
+ private:
+ Matrix *matrix;
+ };
+
+ class MatrixRoomInputPage : public Page {
+ public:
+ MatrixRoomInputPage(Program *program, Matrix *matrix) : Page(program), matrix(matrix) {}
+ const char* get_title() const override { return "Enter the id of a room to join"; }
+ PluginResult submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) override;
+ bool allow_submit_no_selection() const override { return true; }
+ private:
+ Matrix *matrix;
+ };
+
// Only play one video. TODO: Play all videos in room, as related videos?
class MatrixVideoPage : public VideoPage {
public:
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index c9c7603..c528056 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -7845,6 +7845,16 @@ namespace QuickMedia {
room_directory_body->set_items(std::move(room_dir_body_items));
auto matrix_room_directory_page = std::make_unique<MatrixRoomDirectoryPage>(this, matrix);
+ auto settings_body = create_body();
+ auto join_body_item = BodyItem::create("Join room");
+ join_body_item->url = "join";
+ settings_body->append_item(std::move(join_body_item));
+ auto logout_body_item = BodyItem::create("Logout");
+ logout_body_item->url = "logout";
+ settings_body->append_item(std::move(logout_body_item));
+ auto matrix_settings_page_search_bar = create_search_bar("Search...", SEARCH_DELAY_FILTER);
+ auto matrix_settings_page = std::make_unique<MatrixSettingsPage>(this, matrix);
+
MatrixQuickMedia matrix_handler(this, matrix, matrix_rooms_page.get(), matrix_rooms_tag_page.get(), matrix_invites_page.get(), matrix_notifications_page.get());
bool sync_cached = false;
if(!matrix->start_sync(&matrix_handler, sync_cached)) {
@@ -7860,9 +7870,19 @@ namespace QuickMedia {
tabs.push_back(Tab{std::move(rooms_body), std::move(matrix_rooms_page), std::move(rooms_page_search_bar)});
tabs.push_back(Tab{std::move(invites_body), std::move(matrix_invites_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
tabs.push_back(Tab{std::move(room_directory_body), std::move(matrix_room_directory_page), create_search_bar("Server to search on...", SEARCH_DELAY_FILTER)});
+ tabs.push_back(Tab{std::move(settings_body), std::move(matrix_settings_page), std::move(matrix_settings_page_search_bar)});
- page_loop(tabs, 2, nullptr, false);
+ const bool go_to_login_page = page_loop(tabs, 2, nullptr, false);
matrix->stop_sync();
+ if(go_to_login_page) {
+ delete matrix;
+ matrix = new Matrix();
+ current_page = PageType::CHAT_LOGIN;
+ chat_login_page();
+ after_matrix_login_page();
+ window.close();
+ exit(exit_code);
+ }
}
static int accumulate_string(char *data, int size, void *userdata) {
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 82ca583..f79b10c 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -966,6 +966,34 @@ namespace QuickMedia {
title = "Invites (0)";
}
+ PluginResult MatrixSettingsPage::submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) {
+ if(args.url == "join") {
+ result_tabs.push_back(Tab{create_body(), std::make_unique<MatrixRoomInputPage>(program, matrix), create_search_bar("Enter room id...", SEARCH_DELAY_FILTER)});
+ return PluginResult::OK;
+ } else if(args.url == "logout") {
+ matrix->logout();
+ program->set_go_to_previous_page();
+ return PluginResult::OK;
+ } else {
+ return PluginResult::ERR;
+ }
+ }
+
+ PluginResult MatrixRoomInputPage::submit(const SubmitArgs &args, std::vector<Tab>&) {
+ if(args.title.empty()) {
+ show_notification("QuickMedia", "Room id can't be empty", Urgency::CRITICAL);
+ return PluginResult::OK;
+ }
+
+ if(matrix->join_room(args.title) == PluginResult::OK) {
+ show_notification("QuickMedia", "You joined " + args.title, Urgency::NORMAL);
+ program->set_go_to_previous_page();
+ } else {
+ show_notification("QuickMedia", "Failed to join " + args.title, Urgency::CRITICAL);
+ }
+ return PluginResult::OK;
+ }
+
MatrixChatPage::MatrixChatPage(Program *program, std::string room_id, MatrixRoomsPage *rooms_page, std::string jump_to_event_id) :
Page(program), room_id(std::move(room_id)), rooms_page(rooms_page), jump_to_event_id(std::move(jump_to_event_id))
{