aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-05-21 01:36:00 +0200
committerdec05eba <dec05eba@protonmail.com>2021-05-21 01:36:00 +0200
commit0b0ab1e5a451cdd6ae5fd2166314037c1997d292 (patch)
tree58887c84994572acfeb923445cca46fa7a8eaac7 /src
parentdaa6574a80a37d50dad3c6f5ca94a4f974451729 (diff)
Jump to room when submitting notification
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp53
-rw-r--r--src/plugins/Matrix.cpp35
2 files changed, 55 insertions, 33 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 815ab45..9f21c34 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -1690,29 +1690,33 @@ namespace QuickMedia {
int selected_index = tabs[selected_tab].body->get_selected_item();
video_content_page(tabs[selected_tab].page.get(), static_cast<VideoPage*>(new_tabs[0].page.get()), selected_item->get_title(), false, tabs[selected_tab].body->items, selected_index, &tab_associated_data[selected_tab].fetched_page, tab_associated_data[selected_tab].update_search_text);
} else if(new_tabs.size() == 1 && new_tabs[0].page->get_type() == PageTypez::CHAT) {
- body_set_selected_item(tabs[selected_tab].body.get(), selected_item.get());
+ MatrixChatPage *tmp_matrix_chat_page = static_cast<MatrixChatPage*>(new_tabs[0].page.get());
+ MatrixRoomsPage *rooms_page = tmp_matrix_chat_page->rooms_page;
+ Body *room_list_body = rooms_page->body;
+ rooms_page->clear_search();
+
+ body_set_selected_item_by_url(room_list_body, tmp_matrix_chat_page->room_id);
current_page = PageType::CHAT;
- current_chat_room = matrix->get_room_by_id(selected_item->url);
- MatrixRoomsPage *rooms_page = static_cast<MatrixRoomsPage*>(tabs[selected_tab].page.get());
+ current_chat_room = matrix->get_room_by_id(tmp_matrix_chat_page->room_id);
while(window.isOpen()) {
auto matrix_chat_page = std::make_unique<MatrixChatPage>(this, current_chat_room->id, rooms_page);
- bool move_room = chat_page(matrix_chat_page.get(), current_chat_room, tabs, selected_tab);
+ bool move_room = chat_page(matrix_chat_page.get(), current_chat_room);
matrix_chat_page->messages_tab_visible = false;
if(!move_room)
break;
- BodyItem *selected_item = tabs[selected_tab].body->get_selected();
+ BodyItem *selected_item = room_list_body->get_selected();
if(!selected_item)
break;
current_chat_room = matrix->get_room_by_id(selected_item->url);
}
- tabs[selected_tab].body->body_item_select_callback = [&submit_handler](BodyItem *body_item) {
+ room_list_body->body_item_select_callback = [&submit_handler](BodyItem *body_item) {
submit_handler(body_item->get_title());
};
- //select_body_item_by_room(tabs[selected_tab].body.get(), current_chat_room);
+
current_chat_room = nullptr;
} else {
page_loop(new_tabs, 0, after_submit_handler);
@@ -3981,7 +3985,7 @@ namespace QuickMedia {
return default_value;
}
- bool Program::chat_page(MatrixChatPage *matrix_chat_page, RoomData *current_room, std::vector<Tab> &room_tabs, int room_selected_tab) {
+ bool Program::chat_page(MatrixChatPage *matrix_chat_page, RoomData *current_room) {
assert(current_room);
assert(strcmp(plugin_name, "matrix") == 0);
if(!current_room) {
@@ -4101,7 +4105,7 @@ namespace QuickMedia {
sf::Text room_topic_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), room_topic_text_height);
room_topic_text.setFillColor(sf::Color(179, 179, 179));
- sf::Text room_label(room_tabs[room_selected_tab].page->get_title(), *FontLoader::get_font(FontLoader::FontType::LATIN_BOLD), std::floor(18 * get_ui_scale()));
+ sf::Text room_label(matrix_chat_page->rooms_page->get_title(), *FontLoader::get_font(FontLoader::FontType::LATIN_BOLD), std::floor(18 * get_ui_scale()));
room_label.setPosition(15.0f, room_name_text_padding_y + 4.0f);
sf::Sprite room_avatar_sprite;
@@ -5080,7 +5084,7 @@ namespace QuickMedia {
float tab_shade_height = 0.0f;
SyncData sync_data;
- room_tabs[room_selected_tab].body->body_item_select_callback = [&move_room](BodyItem *body_item) {
+ matrix_chat_page->rooms_page->body->body_item_select_callback = [&move_room](BodyItem *body_item) {
move_room = true;
};
@@ -5130,33 +5134,33 @@ namespace QuickMedia {
}
if(draw_room_list) {
- if(room_tabs[room_selected_tab].body->on_event(window, event, false))
+ if(matrix_chat_page->rooms_page->body->on_event(window, event, false))
idle_active_handler();
}
if(event.type == sf::Event::KeyPressed && event.key.control && event.key.alt && (chat_state == ChatState::NAVIGATING || chat_state == ChatState::URL_SELECTION)) {
if(event.key.code == sf::Keyboard::Up || (event.key.control && event.key.code == sf::Keyboard::K)) {
- room_tabs[room_selected_tab].body->select_previous_item();
+ matrix_chat_page->rooms_page->body->select_previous_item();
move_room = true;
goto chat_page_end;
} else if(event.key.code == sf::Keyboard::Down || (event.key.control && event.key.code == sf::Keyboard::J)) {
- room_tabs[room_selected_tab].body->select_next_item();
+ matrix_chat_page->rooms_page->body->select_next_item();
move_room = true;
goto chat_page_end;
} else if(event.key.code == sf::Keyboard::PageUp) {
- room_tabs[room_selected_tab].body->select_previous_page();
+ matrix_chat_page->rooms_page->body->select_previous_page();
move_room = true;
goto chat_page_end;
} else if(event.key.code == sf::Keyboard::PageDown) {
- room_tabs[room_selected_tab].body->select_next_page();
+ matrix_chat_page->rooms_page->body->select_next_page();
move_room = true;
goto chat_page_end;
} else if(event.key.code == sf::Keyboard::Home) {
- room_tabs[room_selected_tab].body->select_first_item();
+ matrix_chat_page->rooms_page->body->select_first_item();
move_room = true;
goto chat_page_end;
} else if(event.key.code == sf::Keyboard::End) {
- room_tabs[room_selected_tab].body->select_last_item();
+ matrix_chat_page->rooms_page->body->select_last_item();
move_room = true;
goto chat_page_end;
} else if(event.key.code == sf::Keyboard::Escape) {
@@ -5667,7 +5671,7 @@ namespace QuickMedia {
window.draw(room_label);
const float padding_x = std::floor(10.0f * get_ui_scale());
const float tab_y = std::floor(tab_vertical_offset) + room_name_padding_y;
- room_tabs[room_selected_tab].body->draw(window, sf::Vector2f(padding_x, tab_y), sf::Vector2f(this->body_size.x - padding_x * 2.0f, window_size.y - tab_y), Json::Value::nullSingleton());
+ matrix_chat_page->rooms_page->body->draw(window, sf::Vector2f(padding_x, tab_y), sf::Vector2f(this->body_size.x - padding_x * 2.0f, window_size.y - tab_y), Json::Value::nullSingleton());
glDisable(GL_SCISSOR_TEST);
}
@@ -5893,15 +5897,16 @@ namespace QuickMedia {
if(!window.isOpen())
exit(exit_code);
- auto notifications_body = create_body();
- //notifications_body->attach_side = AttachSide::BOTTOM;
- auto matrix_notifications_page = std::make_unique<MatrixNotificationsPage>(this, matrix, notifications_body.get());
-
auto rooms_tags_body = create_body();
auto matrix_rooms_tag_page = std::make_unique<MatrixRoomTagsPage>(this, rooms_tags_body.get());
auto rooms_body = create_body();
- auto matrix_rooms_page = std::make_unique<MatrixRoomsPage>(this, rooms_body.get(), "All rooms", nullptr);
+ auto rooms_page_search_bar = create_search_bar("Search...", SEARCH_DELAY_FILTER);
+ auto matrix_rooms_page = std::make_unique<MatrixRoomsPage>(this, rooms_body.get(), "All rooms", nullptr, rooms_page_search_bar.get());
+
+ auto notifications_body = create_body();
+ //notifications_body->attach_side = AttachSide::BOTTOM;
+ auto matrix_notifications_page = std::make_unique<MatrixNotificationsPage>(this, matrix, notifications_body.get(), matrix_rooms_page.get());
auto invites_body = create_body();
auto matrix_invites_page = std::make_unique<MatrixInvitesPage>(this, matrix, invites_body.get());
@@ -5936,7 +5941,7 @@ namespace QuickMedia {
std::vector<Tab> tabs;
tabs.push_back(Tab{std::move(notifications_body), std::move(matrix_notifications_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
tabs.push_back(Tab{std::move(rooms_tags_body), std::move(matrix_rooms_tag_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
- tabs.push_back(Tab{std::move(rooms_body), std::move(matrix_rooms_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
+ 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)});
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 1e1e41b..0577948 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -519,9 +519,9 @@ namespace QuickMedia {
body_items.push_back(std::move(new_body_item));
}
- void body_set_selected_item(Body *body, BodyItem *selected_item) {
+ void body_set_selected_item_by_url(Body *body, const std::string &url) {
for(size_t i = 0; i < body->items.size(); ++i) {
- if(body->items[i]->url == selected_item->url) {
+ if(body->items[i]->url == url) {
body->select_first_item();
body->set_selected_item(i, false);
return;
@@ -641,7 +641,9 @@ namespace QuickMedia {
}
}
- MatrixRoomsPage::MatrixRoomsPage(Program *program, Body *body, std::string title, MatrixRoomTagsPage *room_tags_page) : Page(program), body(body), title(std::move(title)), room_tags_page(room_tags_page) {
+ MatrixRoomsPage::MatrixRoomsPage(Program *program, Body *body, std::string title, MatrixRoomTagsPage *room_tags_page, SearchBar *search_bar) :
+ Page(program), body(body), title(std::move(title)), room_tags_page(room_tags_page), search_bar(search_bar)
+ {
if(room_tags_page)
room_tags_page->set_current_rooms_page(this);
}
@@ -652,8 +654,7 @@ namespace QuickMedia {
}
PluginResult MatrixRoomsPage::submit(const std::string&, const std::string &url, std::vector<Tab> &result_tabs) {
- auto chat_page = std::make_unique<MatrixChatPage>(program, url, this);
- result_tabs.push_back(Tab{nullptr, std::move(chat_page), nullptr});
+ result_tabs.push_back(Tab{nullptr, std::make_unique<MatrixChatPage>(program, url, this), nullptr});
return PluginResult::OK;
}
@@ -715,6 +716,11 @@ namespace QuickMedia {
matrix_delegate->set_room_as_read(room);
}
+ void MatrixRoomsPage::clear_search() {
+ search_bar->clear();
+ body->filter_search_fuzzy("");
+ }
+
void MatrixRoomsPage::clear_data() {
body->clear_items();
if(current_chat_page)
@@ -729,9 +735,10 @@ namespace QuickMedia {
//BodyItem *selected_item = body->get_selected();
sort_room_body_items(body->items);
//body_set_selected_item(body.get(), selected_item);
- auto rooms_page = std::make_unique<MatrixRoomsPage>(program, body_ptr, tag_data.tag_item->get_title(), this);
+ auto search_bar = create_search_bar("Search...", SEARCH_DELAY_FILTER);
+ auto rooms_page = std::make_unique<MatrixRoomsPage>(program, body_ptr, tag_data.tag_item->get_title(), this, search_bar.get());
rooms_page->matrix_delegate = matrix_delegate;
- result_tabs.push_back(Tab{std::move(body), std::move(rooms_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
+ result_tabs.push_back(Tab{std::move(body), std::move(rooms_page), std::move(search_bar)});
return PluginResult::OK;
}
@@ -1066,8 +1073,18 @@ namespace QuickMedia {
return body_item;
}
- MatrixNotificationsPage::MatrixNotificationsPage(Program *program, Matrix *matrix, Body *notifications_body) :
- LazyFetchPage(program), matrix(matrix), notifications_body(notifications_body) {}
+ MatrixNotificationsPage::MatrixNotificationsPage(Program *program, Matrix *matrix, Body *notifications_body, MatrixRoomsPage *all_rooms_page) :
+ LazyFetchPage(program), matrix(matrix), notifications_body(notifications_body), all_rooms_page(all_rooms_page) {}
+
+ PluginResult MatrixNotificationsPage::submit(const std::string&, const std::string&, std::vector<Tab> &result_tabs) {
+ BodyItem *selected_item = notifications_body->get_selected();
+ if(!selected_item)
+ return PluginResult::OK;
+
+ NotificationsExtraData *extra_data = static_cast<NotificationsExtraData*>(selected_item->extra.get());
+ result_tabs.push_back(Tab{nullptr, std::make_unique<MatrixChatPage>(program, extra_data->room->id, all_rooms_page), nullptr});
+ return PluginResult::OK;
+ }
PluginResult MatrixNotificationsPage::get_page(const std::string&, int, BodyItems &result_items) {
return matrix->get_previous_notifications([this, &result_items](const MatrixNotification &notification) {