diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-12-15 12:44:59 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-12-15 12:45:02 +0100 |
commit | ebfd1293acb274a109b63ff331e2c4eeafeff115 (patch) | |
tree | 16052ce2a734c0c090294962d8e5b2419f05f4bc /src | |
parent | 86db163a96e0471c6f49da7c1250cc9bde48fdfb (diff) |
Matrix: more red in replies, or whatever
Diffstat (limited to 'src')
-rw-r--r-- | src/QuickMedia.cpp | 29 | ||||
-rw-r--r-- | src/plugins/Matrix.cpp | 4 |
2 files changed, 22 insertions, 11 deletions
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"); } } |