aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2023-01-10 21:09:44 +0100
committerdec05eba <dec05eba@protonmail.com>2023-01-10 21:09:44 +0100
commite08d5f4fd0a913d49c182c7aebec863da6e6d026 (patch)
treeeaeadd17f39f38a54ee18e10ec08c5c8498b2c20
parenteb6295751d07b8ee173317234daee8acf6b07a5f (diff)
Matrix: show unread notification on initial sync using notifications api (there might be very old messages that we haven't read)
-rw-r--r--plugins/Matrix.hpp4
-rw-r--r--src/plugins/Matrix.cpp18
2 files changed, 20 insertions, 2 deletions
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index 1452af1..7c2103c 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -318,6 +318,8 @@ namespace QuickMedia {
virtual void add_invite(const std::string &room_id, const Invite &invite) = 0;
virtual void remove_invite(const std::string &room_id) = 0;
+ virtual void add_unread_notification(MatrixNotification notification) = 0;
+
virtual void add_user(MatrixEventUserInfo user_info) = 0;
virtual void remove_user(MatrixEventUserInfo user_info) = 0;
virtual void set_user_info(MatrixEventUserInfo user_info) = 0;
@@ -346,6 +348,8 @@ namespace QuickMedia {
void add_invite(const std::string &room_id, const Invite &invite) override;
void remove_invite(const std::string &room_id) override;
+ void add_unread_notification(MatrixNotification notification) override;
+
void add_user(MatrixEventUserInfo user_info) override;
void remove_user(MatrixEventUserInfo user_info) override;
void set_user_info(MatrixEventUserInfo user_info) override;
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 &notification) {
+ 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;
});
}