diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-10-17 18:56:44 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-10-17 18:56:44 +0200 |
commit | 12cdc09759edf506fbafe051895343b20a67798c (patch) | |
tree | 43f561a78eb4869bde1638ab44288ff825265800 /src | |
parent | 4a7b86829025664f6eeef6fcb5fc0894733f2ad6 (diff) |
Matrix: make text that mentions us red
Diffstat (limited to 'src')
-rw-r--r-- | src/Body.cpp | 13 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 30 | ||||
-rw-r--r-- | src/plugins/Matrix.cpp | 7 | ||||
-rw-r--r-- | src/plugins/NyaaSi.cpp | 4 |
4 files changed, 30 insertions, 24 deletions
diff --git a/src/Body.cpp b/src/Body.cpp index 11692aa..73f101f 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -24,11 +24,12 @@ namespace QuickMedia { dirty_author(false), dirty_timestamp(false), thumbnail_is_local(false), - title_color(sf::Color::White), - author_color(sf::Color::White), userdata(nullptr), last_drawn_time(0), - timestamp(0) + timestamp(0), + title_color(sf::Color::White), + author_color(sf::Color::White), + description_color(sf::Color::White) { if(!_title.empty()) set_title(std::move(_title)); @@ -430,7 +431,7 @@ namespace QuickMedia { body_item->title_text->setString(std::move(str)); else body_item->title_text = std::make_unique<Text>(std::move(str), font, cjk_font, 16, size.x - 50 - image_padding_x * 2.0f); - body_item->title_text->setFillColor(body_item->title_color); + body_item->title_text->setFillColor(body_item->get_title_color()); body_item->title_text->updateGeometry(); } @@ -441,6 +442,7 @@ namespace QuickMedia { body_item->description_text->setString(std::move(str)); else body_item->description_text = std::make_unique<Text>(std::move(str), font, cjk_font, 14, size.x - 50 - image_padding_x * 2.0f); + body_item->description_text->setFillColor(body_item->get_description_color()); body_item->description_text->updateGeometry(); } @@ -451,7 +453,7 @@ namespace QuickMedia { body_item->author_text->setString(std::move(str)); else body_item->author_text = std::make_unique<Text>(std::move(str), bold_font, cjk_font, 14, size.x - 50 - image_padding_x * 2.0f); - body_item->author_text->setFillColor(body_item->author_color); + body_item->author_text->setFillColor(body_item->get_author_color()); body_item->author_text->updateGeometry(); } @@ -642,7 +644,6 @@ namespace QuickMedia { //title_text.setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y)); //window.draw(title_text); if(item->title_text) { - item->title_text->setFillColor(item->title_color); item->title_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - 6.0f)); item->title_text->setMaxWidth(size.x - text_offset_x - image_padding_x); item->title_text->draw(window); diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index a2c936f..4f2fa99 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -2889,7 +2889,7 @@ namespace QuickMedia { return str; } - static std::shared_ptr<BodyItem> message_to_body_item(Message *message) { + static std::shared_ptr<BodyItem> message_to_body_item(Message *message, UserInfo *me) { auto body_item = BodyItem::create(""); body_item->set_author(message->user->display_name); std::string text = message->body; @@ -2907,17 +2907,19 @@ namespace QuickMedia { } // TODO: Show image thumbnail inline instead of url to image and showing it as the thumbnail of the body item body_item->url = message->url; - body_item->author_color = message->user->display_name_color; + body_item->set_author_color(message->user->display_name_color); body_item->userdata = (void*)message; // Note: message has to be valid as long as body_item is used! if(message->related_event_type == RelatedEventType::REDACTION || message->related_event_type == RelatedEventType::EDIT) body_item->visible = false; + if(message->mentions_me || (me && message_contains_user_mention(message->body, me->display_name))) + body_item->set_description_color(sf::Color(255, 100, 100)); return body_item; } - static BodyItems messages_to_body_items(const Messages &messages) { + static BodyItems messages_to_body_items(const Messages &messages, UserInfo *me) { BodyItems result_items(messages.size()); for(size_t i = 0; i < messages.size(); ++i) { - result_items[i] = message_to_body_item(messages[i].get()); + result_items[i] = message_to_body_item(messages[i].get(), me); } return result_items; } @@ -2979,7 +2981,7 @@ namespace QuickMedia { for(auto &message : messages) { if(message->mentions_me) { was_mentioned = true; - message->mentions_me = false; + //message->mentions_me = false; // 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) show_notification("QuickMedia matrix - " + matrix->message_get_author_displayname(message.get()) + " (" + room->name + ")", message->body); @@ -3005,7 +3007,7 @@ namespace QuickMedia { room_desc = matrix->message_get_author_displayname(messages.back().get()) + ": " + extract_first_line(messages.back()->body, 150); if(was_mentioned) { room_desc += "\n** You were mentioned **"; // TODO: Better notification? - room_body_item_it->second.body_item->title_color = sf::Color(255, 100, 100); + room_body_item_it->second.body_item->set_title_color(sf::Color(255, 100, 100)); room_body_item_it->second.last_message_read = false; } room_body_item_it->second.body_item->set_description(std::move(room_desc)); @@ -3014,7 +3016,7 @@ namespace QuickMedia { if(was_mentioned) room_desc += "\n** You were mentioned **"; // TODO: Better notification? room_body_item_it->second.body_item->set_description(std::move(room_desc)); - room_body_item_it->second.body_item->title_color = sf::Color(255, 100, 100); + room_body_item_it->second.body_item->set_title_color(sf::Color(255, 100, 100)); room_body_item_it->second.last_message_read = false; } } @@ -3289,12 +3291,12 @@ namespace QuickMedia { return result; }; - auto add_new_messages_to_current_room = [&tabs](Messages &messages) { + auto add_new_messages_to_current_room = [this, &tabs, ¤t_room](Messages &messages) { int num_items = tabs[MESSAGES_TAB_INDEX].body->items.size(); bool scroll_to_end = (num_items == 0 || tabs[MESSAGES_TAB_INDEX].body->is_selected_item_last_visible_item()); BodyItem *selected_item = tabs[MESSAGES_TAB_INDEX].body->get_selected(); - tabs[MESSAGES_TAB_INDEX].body->insert_items_by_timestamps(messages_to_body_items(messages)); + tabs[MESSAGES_TAB_INDEX].body->insert_items_by_timestamps(messages_to_body_items(messages, matrix->get_me(current_room).get())); if(selected_item && !scroll_to_end) { int selected_item_index = tabs[MESSAGES_TAB_INDEX].body->get_index_by_body_item(selected_item); if(selected_item_index != -1) @@ -3359,6 +3361,7 @@ namespace QuickMedia { body_item->embedded_item_status = EmbeddedItemStatus::NONE; body_item->thumbnail_url = message->user->avatar_url; body_item->thumbnail_mask_type = ThumbnailMaskType::NONE; + body_item->set_description_color(sf::Color::White); } it = unreferenced_events.erase(it); } else { @@ -3385,6 +3388,7 @@ namespace QuickMedia { body_item->embedded_item_status = EmbeddedItemStatus::NONE; body_item->thumbnail_url = message->user->avatar_url; body_item->thumbnail_mask_type = ThumbnailMaskType::NONE; + body_item->set_description_color(sf::Color::White); } } else { unreferenced_events.push_back(message); @@ -3642,7 +3646,7 @@ namespace QuickMedia { Messages new_messages; if(matrix->get_all_synced_room_messages(current_room, new_messages) == PluginResult::OK) { - tabs[MESSAGES_TAB_INDEX].body->insert_items_by_timestamps(messages_to_body_items(new_messages)); + tabs[MESSAGES_TAB_INDEX].body->insert_items_by_timestamps(messages_to_body_items(new_messages, matrix->get_me(current_room).get())); tabs[MESSAGES_TAB_INDEX].body->select_last_item(); modify_related_messages_in_current_room(new_messages); } else { @@ -3849,7 +3853,7 @@ namespace QuickMedia { size_t num_new_messages = new_messages.size(); if(num_new_messages > 0 && previous_messages_future_room == current_room) { BodyItem *selected_item = tabs[MESSAGES_TAB_INDEX].body->get_selected(); - BodyItems new_body_items = messages_to_body_items(new_messages); + BodyItems new_body_items = messages_to_body_items(new_messages, matrix->get_me(current_room).get()); size_t num_new_body_items = new_body_items.size(); tabs[MESSAGES_TAB_INDEX].body->insert_items_by_timestamps(std::move(new_body_items)); if(selected_item) { @@ -3869,7 +3873,7 @@ namespace QuickMedia { // Ignore finished fetch of messages if it happened in another room. When we navigate back to the room we will get the messages again if(fetch_reply_future_room == current_room) { if(replied_to_message) { - fetch_reply_body_item->embedded_item = message_to_body_item(replied_to_message.get()); + fetch_reply_body_item->embedded_item = message_to_body_item(replied_to_message.get(), matrix->get_me(current_room).get()); fetch_reply_body_item->embedded_item_status = EmbeddedItemStatus::FINISHED_LOADING; } else { fetch_reply_body_item->embedded_item_status = EmbeddedItemStatus::FAILED_TO_LOAD; @@ -3980,7 +3984,7 @@ namespace QuickMedia { room_desc = room_desc.substr(0, room_desc.size() - 25); current_room_body_data->body_item->set_description(std::move(room_desc)); // TODO: Show a line like nheko instead for unread messages, or something else - current_room_body_data->body_item->title_color = sf::Color::White; + current_room_body_data->body_item->set_title_color(sf::Color::White); current_room_body_data->last_message_read = true; } } else if(!current_room_body_data->last_message_read) { diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index ea5f86c..f9bfe30 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -415,7 +415,7 @@ namespace QuickMedia { } // TODO: Do not show notification if mention is a reply to somebody else that replies to me? also dont show notification everytime a mention is edited - static bool message_contains_user_mention(const std::string &msg, const std::string &username) { + bool message_contains_user_mention(const std::string &msg, const std::string &username) { if(msg.empty()) return false; @@ -447,6 +447,7 @@ namespace QuickMedia { return; std::vector<std::shared_ptr<Message>> new_messages; + auto me = get_me(room_data); for(const rapidjson::Value &event_item_json : events_json.GetArray()) { std::shared_ptr<Message> new_message = parse_message_event(event_item_json, room_data.get()); @@ -454,8 +455,8 @@ namespace QuickMedia { continue; // TODO: Is @room ok? shouldn't we also check if the user has permission to do @room? (only when notifications are limited to @mentions) - if(has_unread_notifications && !username.empty()) - new_message->mentions_me = message_contains_user_mention(new_message->body, username) || message_contains_user_mention(new_message->body, "@room"); + if(has_unread_notifications && me) + new_message->mentions_me = message_contains_user_mention(new_message->body, me->display_name) || message_contains_user_mention(new_message->body, "@room"); new_messages.push_back(std::move(new_message)); } diff --git a/src/plugins/NyaaSi.cpp b/src/plugins/NyaaSi.cpp index 8d0679e..dc6e19f 100644 --- a/src/plugins/NyaaSi.cpp +++ b/src/plugins/NyaaSi.cpp @@ -170,9 +170,9 @@ namespace QuickMedia { body_item->set_description(std::move(description)); body_item->url = "https://nyaa.si" + std::move(view_url); if(is_trusted) - body_item->title_color = sf::Color(43, 255, 47); + body_item->set_title_color(sf::Color(43, 255, 47)); else if(is_remake) - body_item->title_color = sf::Color(255, 45, 47); + body_item->set_title_color(sf::Color(255, 45, 47)); result_items.push_back(std::move(body_item)); } |