diff options
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | include/Body.hpp | 40 | ||||
-rw-r--r-- | plugins/Matrix.hpp | 2 | ||||
-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 |
7 files changed, 60 insertions, 37 deletions
@@ -63,7 +63,6 @@ Scroll to bottom when receiving a new message even if the selected message is no Also add a tab for common directories and recently accessed files/directories (the directories would be the directory of used files). Provide a way to go to the first unread message in matrix and also show a marker in the body (maybe a red line?) where the first unread message is. Load already downloaded images/thumbnails in a separate thread, to instantly load them instead of waiting for new downloads... -Make text that mentions us red in matrix. Allow scrolling body item. A body item can be long and we wont be able to read all of it otherwise (such as a message on matrix). Pressing up/down should scroll such a large body item rather than moving to another one. Cleanup keybindings. Some require ctrl, some dont (4chan vs matrix for example). Add room topic beside room name in matrix (in messages tab). diff --git a/include/Body.hpp b/include/Body.hpp index 7032ad8..e430bfb 100644 --- a/include/Body.hpp +++ b/include/Body.hpp @@ -44,11 +44,6 @@ namespace QuickMedia { dirty = true; } - void append_title(std::string str) { - title += str; - dirty = true; - } - void set_description(std::string new_description) { if(description.empty() && new_description.empty()) return; @@ -56,11 +51,6 @@ namespace QuickMedia { dirty_description = true; } - void append_description(std::string str) { - description += str; - dirty_description = true; - } - void set_author(std::string new_author) { if(author.empty() && new_author.empty()) return; @@ -75,11 +65,36 @@ namespace QuickMedia { dirty_timestamp = true; } + void set_title_color(sf::Color new_color) { + if(new_color != title_color) { + title_color = new_color; + dirty = true; + } + } + + void set_description_color(sf::Color new_color) { + if(new_color != description_color) { + description_color = new_color; + dirty_description = true; + } + } + + void set_author_color(sf::Color new_color) { + if(new_color != author_color) { + author_color = new_color; + dirty_author = true; + } + } + const std::string& get_title() const { return title; } const std::string& get_description() const { return description; } const std::string& get_author() const { return author; } time_t get_timestamp() const { return timestamp; } + sf::Color get_title_color() const { return title_color; } + sf::Color get_description_color() const { return description_color; } + sf::Color get_author_color() const { return author_color; } + // TODO: Use a list of strings instead, not all plugins need all of these fields std::string url; std::string thumbnail_url; @@ -97,8 +112,6 @@ namespace QuickMedia { // Used by image boards for example. The elements are indices to other body items std::vector<size_t> replies; std::string post_number; - sf::Color title_color; - sf::Color author_color; void *userdata; // Not managed, should be deallocated by whoever sets this sf::Int32 last_drawn_time; EmbeddedItemStatus embedded_item_status = EmbeddedItemStatus::NONE; @@ -110,6 +123,9 @@ namespace QuickMedia { std::string description; std::string author; time_t timestamp; + sf::Color title_color; + sf::Color author_color; + sf::Color description_color; }; using BodyItems = std::vector<std::shared_ptr<BodyItem>>; diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp index 9f58b24..3cb974f 100644 --- a/plugins/Matrix.hpp +++ b/plugins/Matrix.hpp @@ -123,6 +123,8 @@ namespace QuickMedia { using RoomSyncMessages = std::unordered_map<std::shared_ptr<RoomData>, Messages>; using Rooms = std::vector<std::shared_ptr<RoomData>>; + bool message_contains_user_mention(const std::string &msg, const std::string &username); + class Matrix { public: PluginResult sync(RoomSyncMessages &room_messages); 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)); } |