From e08d5f4fd0a913d49c182c7aebec863da6e6d026 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 10 Jan 2023 21:09:44 +0100 Subject: Matrix: show unread notification on initial sync using notifications api (there might be very old messages that we haven't read) --- src/plugins/Matrix.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index de49409..0da73eb 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -693,6 +693,11 @@ namespace QuickMedia { invites_page->remove_body_item_by_room_id(room_id); } + void MatrixQuickMedia::add_unread_notification(MatrixNotification notification) { + if(notifications_shown.insert(notification.event_id).second) + show_notification("QuickMedia matrix - " + notification.sender_user_id + " (" + notification.room->get_name() + ")", notification.body); + } + void MatrixQuickMedia::add_user(MatrixEventUserInfo user_info) { auto &users = users_by_room[user_info.room]; const bool new_user = users.insert(std::make_pair(user_info.user_id, user_info)).second; @@ -1783,13 +1788,22 @@ namespace QuickMedia { } if(first_sync) { + bool initial_sync_show_notifications = initial_sync; first_sync = false; initial_sync = false; filter_encoded = url_param_encode(CONTINUE_FILTER); // TODO: limit messages in this continue filter? // TODO: This ignores new rooms that are not part of the previous sync message. Fix this. - notification_thread = std::thread([this]() { - get_previous_notifications([](const MatrixNotification&) {}); + notification_thread = std::thread([this, initial_sync_show_notifications]() { + get_previous_notifications([this, initial_sync_show_notifications](const MatrixNotification ¬ification) { + if(!initial_sync_show_notifications || notification.read) + return; + + MatrixDelegate *delegate = this->delegate; + ui_thread_tasks.push([delegate, notification] { + delegate->add_unread_notification(std::move(notification)); + }); + }); finished_fetching_notifications = true; }); } -- cgit v1.2.3