diff options
author | dec05eba <dec05eba@protonmail.com> | 2023-01-10 21:09:44 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2023-01-10 21:09:44 +0100 |
commit | e08d5f4fd0a913d49c182c7aebec863da6e6d026 (patch) | |
tree | eaeadd17f39f38a54ee18e10ec08c5c8498b2c20 /src/plugins | |
parent | eb6295751d07b8ee173317234daee8acf6b07a5f (diff) |
Matrix: show unread notification on initial sync using notifications api (there might be very old messages that we haven't read)
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/Matrix.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
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; }); } |