aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Matrix.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-04-18 17:18:31 +0200
committerdec05eba <dec05eba@protonmail.com>2021-04-18 17:18:31 +0200
commit7f0bdeddb79c308ab082a124441f1d69d665dbfc (patch)
tree66428f87349b6bfe6f4d50fec871c358a32717f9 /src/plugins/Matrix.cpp
parent033fbf3f1363c810d115ce9a531aea26ea9e1cf1 (diff)
Fix misc matrix bugs related to leaving a room when side panel is visible and changing room, misc visual changes to manga
Diffstat (limited to 'src/plugins/Matrix.cpp')
-rw-r--r--src/plugins/Matrix.cpp41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index e1f9b58..147dbdf 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -443,8 +443,8 @@ namespace QuickMedia {
}
}
- void MatrixQuickMedia::update(MatrixPageType page_type) {
- update_pending_room_messages(page_type);
+ void MatrixQuickMedia::update(MatrixPageType page_type, Body *chat_body, bool messages_tab_visible) {
+ update_pending_room_messages(page_type, chat_body, messages_tab_visible);
std::lock_guard<std::mutex> room_body_lock(room_body_items_mutex);
for(auto &it : unread_notifications) {
for(auto &unread_notification : it.second) {
@@ -499,7 +499,7 @@ namespace QuickMedia {
return extract_first_line_elipses(message->body, 150);
}
- void MatrixQuickMedia::update_room_description(RoomData *room, Messages &new_messages, bool is_initial_sync, bool sync_is_cache) {
+ void MatrixQuickMedia::update_room_description(RoomData *room, Messages &new_messages, bool is_initial_sync, bool sync_is_cache, Body *chat_body, bool messages_tab_visible) {
time_t read_marker_message_timestamp = 0;
std::shared_ptr<UserInfo> me = matrix->get_me(room);
std::string my_user_read_marker;
@@ -544,16 +544,25 @@ namespace QuickMedia {
return;
if(last_unread_message && !sync_is_cache) {
- std::string room_desc = "Unread: " + matrix->message_get_author_displayname(last_unread_message) + ": " + message_to_room_description_text(last_unread_message);
+ bool is_window_focused = program->is_window_focused();
+ RoomData *current_room = program->get_current_chat_room();
+ bool set_room_as_unread = !is_window_focused || room != current_room || (!chat_body || !chat_body->is_last_item_fully_visible()) || !messages_tab_visible;
+
+ std::string room_desc;
+ if(set_room_as_unread)
+ room_desc += "Unread: ";
+ room_desc += matrix->message_get_author_displayname(last_unread_message) + ": " + message_to_room_description_text(last_unread_message);
+
int unread_notification_count = room->unread_notification_count;
- if(unread_notification_count > 0) {
+ if(unread_notification_count > 0 && set_room_as_unread) {
room_desc += "\n** " + std::to_string(unread_notification_count) + " unread mention(s) **"; // TODO: Better notification?
room->body_item->set_description_color(sf::Color(255, 100, 100));
} else {
room->body_item->set_description_color(sf::Color(179, 179, 179));
}
room->body_item->set_description(std::move(room_desc));
- room->body_item->set_title_color(sf::Color(255, 100, 100));
+ if(set_room_as_unread)
+ room->body_item->set_title_color(sf::Color(255, 100, 100));
room->last_message_read = false;
rooms_page->move_room_to_top(room);
@@ -564,7 +573,7 @@ namespace QuickMedia {
}
}
- void MatrixQuickMedia::update_pending_room_messages(MatrixPageType page_type) {
+ void MatrixQuickMedia::update_pending_room_messages(MatrixPageType page_type, Body *chat_body, bool messages_tab_visible) {
std::lock_guard<std::mutex> lock(pending_room_messages_mutex);
bool is_window_focused = program->is_window_focused();
RoomData *current_room = program->get_current_chat_room();
@@ -580,14 +589,14 @@ namespace QuickMedia {
for(auto &message : messages) {
if(message->notification_mentions_me) {
// TODO: What if the message or username begins with "-"? also make the notification image be the avatar of the user
- if((!is_window_focused || room != current_room || page_type == MatrixPageType::ROOM_LIST) && message->related_event_type != RelatedEventType::EDIT && message->related_event_type != RelatedEventType::REDACTION) {
+ if((!is_window_focused || room != current_room) && message->related_event_type != RelatedEventType::EDIT && message->related_event_type != RelatedEventType::REDACTION) {
show_notification("QuickMedia matrix - " + matrix->message_get_author_displayname(message.get()) + " (" + room->get_name() + ")", message->body);
}
}
}
}
- update_room_description(room, messages, is_initial_sync, it.second.sync_is_cache);
+ update_room_description(room, messages, is_initial_sync, it.second.sync_is_cache, chat_body, messages_tab_visible);
}
pending_room_messages.clear();
}
@@ -605,7 +614,6 @@ namespace QuickMedia {
PluginResult MatrixRoomsPage::submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) {
(void)title;
auto chat_page = std::make_unique<MatrixChatPage>(program, url, this);
- chat_page->matrix_delegate = matrix_delegate;
result_tabs.push_back(Tab{nullptr, std::move(chat_page), nullptr});
return PluginResult::OK;
}
@@ -651,7 +659,7 @@ namespace QuickMedia {
sort_room_body_items(body->items);
//body_set_selected_item(body, selected_item);
}
- matrix_delegate->update(MatrixPageType::ROOM_LIST);
+ matrix_delegate->update(MatrixPageType::ROOM_LIST, nullptr, false);
if(filter_on_update) {
filter_on_update = false;
if(search_bar)
@@ -823,7 +831,7 @@ namespace QuickMedia {
add_room_body_items_by_tags.clear();
body->set_selected_item(prev_selected_item, false);
}
- matrix_delegate->update(MatrixPageType::ROOM_LIST);
+ matrix_delegate->update(MatrixPageType::ROOM_LIST, nullptr, false);
if(filter_on_update) {
filter_on_update = false;
if(search_bar)
@@ -970,17 +978,16 @@ namespace QuickMedia {
}
MatrixChatPage::MatrixChatPage(Program *program, std::string room_id, MatrixRoomsPage *rooms_page) : Page(program), room_id(std::move(room_id)), rooms_page(rooms_page) {
- if(rooms_page)
- rooms_page->set_current_chat_page(this);
+ assert(rooms_page);
+ rooms_page->set_current_chat_page(this);
}
MatrixChatPage::~MatrixChatPage() {
- if(rooms_page)
- rooms_page->set_current_chat_page(nullptr);
+ rooms_page->set_current_chat_page(nullptr);
}
void MatrixChatPage::update() {
- matrix_delegate->update(MatrixPageType::CHAT);
+ rooms_page->matrix_delegate->update(MatrixPageType::CHAT, chat_body, messages_tab_visible);
if(rooms_page)
rooms_page->update();
}