aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Matrix.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/Matrix.cpp')
-rw-r--r--src/plugins/Matrix.cpp62
1 files changed, 36 insertions, 26 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index df4fa52..21375e7 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -406,7 +406,7 @@ namespace QuickMedia {
bool is_window_focused = program->is_window_focused();
RoomData *current_room = program->get_current_chat_room();
- if(!sync_is_cache && message_dir == MessageDirection::AFTER && !is_initial_sync) {
+ if(!sync_is_cache && message_dir == MessageDirection::AFTER) {
for(auto &message : messages) {
if(message->notification_mentions_me) {
std::string body = remove_reply_formatting(message->body);
@@ -1026,7 +1026,7 @@ namespace QuickMedia {
bool read;
};
- static std::shared_ptr<BodyItem> notification_to_body_item(Body *body, const MatrixNotification &notification) {
+ static std::shared_ptr<BodyItem> notification_to_body_item(const MatrixNotification &notification) {
auto body_item = BodyItem::create("");
body_item->set_author(notification.room->get_name());
body_item->set_description(notification.sender_user_id + ":\n" + notification.body);
@@ -1065,16 +1065,16 @@ namespace QuickMedia {
PluginResult MatrixNotificationsPage::get_page(const std::string&, int, BodyItems &result_items) {
return matrix->get_previous_notifications([this, &result_items](const MatrixNotification &notification) {
- auto body_item = notification_to_body_item(notifications_body, notification);
- room_notifications[notification.room].push_back(body_item);
+ auto body_item = notification_to_body_item(notification);
+ room_notifications[notification.room->id].push_back(body_item);
result_items.push_back(body_item);
});
}
PluginResult MatrixNotificationsPage::lazy_fetch(BodyItems &result_items) {
matrix->get_cached_notifications([this, &result_items](const MatrixNotification &notification) {
- auto body_item = notification_to_body_item(notifications_body, notification);
- room_notifications[notification.room].push_back(body_item);
+ auto body_item = notification_to_body_item(notification);
+ room_notifications[notification.room->id].push_back(body_item);
result_items.push_back(body_item);
});
return PluginResult::OK;
@@ -1085,25 +1085,20 @@ namespace QuickMedia {
}
void MatrixNotificationsPage::add_notification(MatrixNotification notification) {
- //int prev_selected_item = notifications_body->get_selected_item();
- //notifications_body->items.push_back(notification_to_body_item(notifications_body, notification));
- //notifications_body->set_selected_item(prev_selected_item - 1);
- auto body_item = notification_to_body_item(notifications_body, notification);
- room_notifications[notification.room].push_back(body_item);
- notifications_body->prepend_item(body_item);
- if(notifications_body->get_selected_item() > 0)
- notifications_body->select_next_item();
+ auto body_item = notification_to_body_item(notification);
+ room_notifications[notification.room->id].push_back(body_item);
+ notifications_body->insert_item_by_timestamp(body_item);
}
// TODO: Only loop unread items
void MatrixNotificationsPage::set_room_as_read(RoomData *room) {
- auto it = room_notifications.find(room);
+ auto it = room_notifications.find(room->id);
if(it == room_notifications.end())
return;
for(const auto &room_notification : it->second) {
NotificationsExtraData *extra_data = static_cast<NotificationsExtraData*>(room_notification->extra.get());
- if(!extra_data->read && extra_data->room == room) {
+ if(!extra_data->read) {
extra_data->read = true;
room_notification->set_author_color(get_current_theme().text_color);
room_notification->set_description_color(get_current_theme().text_color);
@@ -1622,15 +1617,18 @@ namespace QuickMedia {
continue;
}
- MatrixNotification notification;
- notification.room = room;
- notification.event_id.assign(event_id_json.GetString(), event_id_json.GetStringLength());
- notification.sender_user_id.assign(sender_json.GetString(), sender_json.GetStringLength());
- notification.body = remove_reply_formatting(body_json.GetString());
- notification.timestamp = timestamp;
- notification.read = read_json.GetBool();
- callback_func(notification);
- notifications.push_back(std::move(notification));
+ std::string event_id(event_id_json.GetString(), event_id_json.GetStringLength());
+ if(notifications_by_event_id.insert(event_id).second) {
+ MatrixNotification notification;
+ notification.room = room;
+ notification.event_id = std::move(event_id);
+ notification.sender_user_id.assign(sender_json.GetString(), sender_json.GetStringLength());
+ notification.body = remove_reply_formatting(body_json.GetString());
+ notification.timestamp = timestamp;
+ notification.read = read_json.GetBool();
+ callback_func(notification);
+ notifications.push_back(std::move(notification));
+ }
}
return PluginResult::OK;
}
@@ -2078,11 +2076,23 @@ namespace QuickMedia {
if(read_marker_message_timestamp == 0 || read_marker_message_timestamp < qm_read_marker)
read_marker_message_timestamp = qm_read_marker;
+ std::lock_guard<std::mutex> lock(notifications_mutex);
for(auto &message : new_messages) {
// TODO: Is @room ok? shouldn't we also check if the user has permission to do @room? (only when notifications are limited to @mentions)
// TODO: Is comparing against read marker timestamp ok enough?
- if(me && message->timestamp > read_marker_message_timestamp)
+ if(me && message->timestamp > read_marker_message_timestamp) {
message->notification_mentions_me = message_contains_user_mention(message->body, my_display_name) || message_contains_user_mention(message->body, me->user_id) || message_contains_user_mention(message->body, "@room");
+ if(notifications_by_event_id.insert(message->event_id).second) {
+ MatrixNotification notification;
+ notification.room = room_data;
+ notification.event_id = message->event_id;
+ notification.sender_user_id = message->user->user_id;
+ notification.body = remove_reply_formatting(message->body);;
+ notification.timestamp = message->timestamp;
+ notification.read = false;
+ notifications.insert(notifications.begin(), std::move(notification));
+ }
+ }
}
}