diff options
-rw-r--r-- | TODO | 3 | ||||
-rw-r--r-- | plugins/Matrix.hpp | 2 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 29 | ||||
-rw-r--r-- | src/plugins/Matrix.cpp | 4 |
4 files changed, 25 insertions, 13 deletions
@@ -151,4 +151,5 @@ Support replying to messages with media, by typing /upload in the reply text. Instead of doing a GET for the first N bytes to check if a video is streamable, start streaming the video and if the first bytes doesn't contain MOOV then wait until the whole video has downloaded before playing it. Create thumbnail when uploading an image in matrix. If a message reply is edited and its a reply to us, then we want the text to be red even if its edited. -Implement matrix spoiler, see: https://github.com/matrix-org/matrix-doc/blob/master/proposals/2010-spoilers.md
\ No newline at end of file +Implement matrix spoiler, see: https://github.com/matrix-org/matrix-doc/blob/master/proposals/2010-spoilers.md. +Make the messages that mention us red using the matrix notification api that we already use. Mark those messages as mentions us.
\ No newline at end of file diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp index f0fe840..be89adb 100644 --- a/plugins/Matrix.hpp +++ b/plugins/Matrix.hpp @@ -74,7 +74,7 @@ namespace QuickMedia { std::string related_event_id; sf::Vector2i thumbnail_size; // Set to {0, 0} if not specified RelatedEventType related_event_type = RelatedEventType::NONE; - bool mentions_me = false; + bool notification_mentions_me = false; bool cache = false; bool provisional = false; time_t timestamp = 0; // In milliseconds diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 480be75..bc66732 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -3220,7 +3220,12 @@ namespace QuickMedia { }; // TODO: Optimize with hash map? - auto resolve_unreferenced_events_with_body_items = [&set_body_as_deleted, &unreferenced_events, &find_body_item_by_event_id](std::shared_ptr<BodyItem> *body_items, size_t num_body_items) { + auto resolve_unreferenced_events_with_body_items = [this, ¤t_room, &set_body_as_deleted, &unreferenced_events, &find_body_item_by_event_id](std::shared_ptr<BodyItem> *body_items, size_t num_body_items) { + if(num_body_items == 0) + return; + + auto me = matrix->get_me(current_room); + auto my_display_name = current_room->get_user_display_name(me); for(auto it = unreferenced_events.begin(); it != unreferenced_events.end(); ) { auto &message = *it; // TODO: Make redacted/edited events as (redacted)/(edited) in the body @@ -3233,7 +3238,10 @@ namespace QuickMedia { set_body_as_deleted(message.get(), body_item.get()); } else { body_item->set_description(message_get_body_remove_formatting(message.get())); - body_item->set_description_color(sf::Color::White); + if(message_contains_user_mention(message->body, my_display_name) || message_contains_user_mention(message->body, me->user_id)) + body_item->set_description_color(sf::Color(255, 100, 100)); + else + body_item->set_description_color(sf::Color::White); } it = unreferenced_events.erase(it); } else { @@ -3246,10 +3254,12 @@ namespace QuickMedia { }; // TODO: Optimize find_body_item_by_event_id hash map? - auto modify_related_messages_in_current_room = [&set_body_as_deleted, &unreferenced_events, &find_body_item_by_event_id, &tabs](Messages &messages) { + auto modify_related_messages_in_current_room = [this, ¤t_room, &set_body_as_deleted, &unreferenced_events, &find_body_item_by_event_id, &tabs](Messages &messages) { if(messages.empty()) return; + auto me = matrix->get_me(current_room); + auto my_display_name = current_room->get_user_display_name(me); auto &body_items = tabs[MESSAGES_TAB_INDEX].body->items; for(auto &message : messages) { // TODO: Make redacted/edited events as (redacted)/(edited) in the body @@ -3262,7 +3272,10 @@ namespace QuickMedia { set_body_as_deleted(message.get(), body_item.get()); } else { body_item->set_description(message_get_body_remove_formatting(message.get())); - body_item->set_description_color(sf::Color::White); + if(message_contains_user_mention(message->body, my_display_name) || message_contains_user_mention(message->body, me->user_id)) + body_item->set_description_color(sf::Color(255, 100, 100)); + else + body_item->set_description_color(sf::Color::White); } } else { unreferenced_events.push_back(message); @@ -3659,7 +3672,7 @@ namespace QuickMedia { // TODO: Optimize from linear search to hash map auto related_body_item = find_body_item_by_event_id(tabs[MESSAGES_TAB_INDEX].body->items.data(), tabs[MESSAGES_TAB_INDEX].body->items.size(), event_data->message->related_event_id); if(related_body_item) { - if(related_body_item->userdata && static_cast<Message*>(related_body_item->userdata)->user == me) + if((related_body_item->userdata && static_cast<Message*>(related_body_item->userdata)->user == me) || message_contains_user_mention(event_data->message->body, current_room->get_user_display_name(me)) || message_contains_user_mention(event_data->message->body, me->user_id)) body_item->set_description_color(sf::Color(255, 100, 100)); body_item->embedded_item = std::make_shared<BodyItem>(""); *body_item->embedded_item = *related_body_item; @@ -3686,7 +3699,7 @@ namespace QuickMedia { // TODO: Optimize from linear search to hash map auto related_body_item = find_body_item_by_event_id(tabs[MESSAGES_TAB_INDEX].body->items.data(), tabs[MESSAGES_TAB_INDEX].body->items.size(), event_data->event_id); if(related_body_item) { - if(related_body_item->userdata && static_cast<Message*>(related_body_item->userdata)->user == me) + if((related_body_item->userdata && static_cast<Message*>(related_body_item->userdata)->user == me) || message_contains_user_mention(event_data->message->body, current_room->get_user_display_name(me)) || message_contains_user_mention(event_data->message->body, me->user_id)) body_item->set_description_color(sf::Color(255, 100, 100)); *body_item = *related_body_item; body_item->reactions.clear(); @@ -3739,7 +3752,7 @@ namespace QuickMedia { // TODO: Optimize from linear search to hash map auto related_body_item = find_body_item_by_event_id(tabs[MESSAGES_TAB_INDEX].body->items.data(), tabs[MESSAGES_TAB_INDEX].body->items.size(), message->related_event_id); if(related_body_item) { - if(related_body_item->userdata && static_cast<Message*>(related_body_item->userdata)->user == me) + if((related_body_item->userdata && static_cast<Message*>(related_body_item->userdata)->user == me) || message_contains_user_mention(message->body, current_room->get_user_display_name(me)) || message_contains_user_mention(message->body, me->user_id)) body_item->set_description_color(sf::Color(255, 100, 100)); body_item->embedded_item = std::make_shared<BodyItem>(""); *body_item->embedded_item = *related_body_item; @@ -4524,8 +4537,6 @@ namespace QuickMedia { } } else if(fetch_message_tab == MESSAGES_TAB_INDEX) { if(fetch_message_result.message) { - if(fetch_message_result.message->user == me) - fetch_body_item->set_description_color(sf::Color(255, 100, 100)); fetch_body_item->embedded_item = message_to_body_item(current_room, fetch_message_result.message.get(), current_room->get_user_display_name(me), me->user_id); fetch_body_item->embedded_item_status = FetchStatus::FINISHED_LOADING; } else { diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 44dfa3a..003cf46 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -517,7 +517,7 @@ namespace QuickMedia { if(!it.second.sync_is_cache && it.second.message_dir == MessageDirection::AFTER && !is_initial_sync) { for(auto &message : messages) { - if(message->mentions_me) { + 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) show_notification("QuickMedia matrix - " + matrix->message_get_author_displayname(message.get()) + " (" + room->get_name() + ")", message->body); @@ -1711,7 +1711,7 @@ namespace QuickMedia { // 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) - message->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"); + 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"); } } |