From 027f95c5750b8db3a648e4ff7026bf3a7efc2bd6 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 20 Nov 2020 17:53:06 +0100 Subject: Matrix: display replied-to messages in pinned messages tab --- TODO | 3 --- src/QuickMedia.cpp | 27 +++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/TODO b/TODO index aebc2cd..d8d4209 100644 --- a/TODO +++ b/TODO @@ -50,7 +50,6 @@ Also add a tab for common directories and recently accessed files/directories (t 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. Cleanup keybindings. Some require ctrl, some dont. Add room topic beside room name in matrix (in messages tab). -Move rooms in matrix to previous page instead, then messages can be beside users, pinned messages, settings, etc and they would all be connected to that one room, then beside rooms tab there would be a global settings tab. Add /me to matrix, emoji, reactions... Set the icon of the window to be the icon of the plugin. Nice for KDE, GNOME, etc with titlebars. Set a minimum wrap size for text. We dont want one line of text to fully fill the window vertically when the window size width is small. Its better to cut off the text and add eclipses. @@ -94,7 +93,6 @@ Read image exif into to apply image rotation. This is common in images taken on Handle M_LIMIT_EXCEEDED in matrix Maybe dont clear cache for body items when filtering. Change scroll in body when previous items change size (such as when thumbnail has finished loading). -Load and show replied-to message in the pinned messages tab. Pressing enter on a pinned message should go to the message in the messages tab. Display file list for nyaa. Remove reply formatting for NOTICE in matrix as well. @@ -129,7 +127,6 @@ Make a shader for Text for changing color instead of updating the text geometry. Automatically retry sending messages that fails to send (after timeout). These failed to send messages should be stored on disk and retried when going back to the room or restarting QuickMedia. Also make message deletion provisional (make it gray while its deleting the message). Continue matrix requests when switching room, instead of resetting them when going from chat page to room list page (such as post message request). -Pinned messages authors doesn't seem to be updated when fetching users, if the pinned messages are fetched before the users (by navigating to the pending messages tab quickly). Improve /sync by not removing cached data on initial sync, and also always append data to sync file instead of overwriting sync file on "initial sync". Also cache "since", but take into consideration that not all messages are fetched on the initial sync, then add a gap between old messages from before sync and after sync so we can fetch the messages between the old messages and new messages and remove the gap when the fetched messages contains any of the old messages. Fetching of previous messages should also be saved in the /sync file and messages fetched with get_message_by_id, which would cache embedded items and pinned messages; also cache users. diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 5c88322..c9ab3e1 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -3304,6 +3304,7 @@ namespace QuickMedia { PinnedEventData *event_data = new PinnedEventData(); event_data->event_id = event; event_data->status = FetchStatus::NONE; + event_data->message = nullptr; body->userdata = event_data; tabs[PINNED_TAB_INDEX].body->items.push_back(std::move(body)); } @@ -3567,7 +3568,6 @@ namespace QuickMedia { int fetch_message_tab = -1; // TODO: How about instead fetching all messages we have, not only the visible ones? also fetch with multiple threads. - // TODO: Cancel when going to another room? tabs[PINNED_TAB_INDEX].body->body_item_render_callback = [this, ¤t_room, &fetch_message_future, &tabs, &fetch_message, &find_body_item_by_event_id, &fetch_body_item, &fetch_message_tab](BodyItem *body_item) { if(fetch_message_future.valid() || !current_room) return; @@ -3591,6 +3591,30 @@ namespace QuickMedia { } #endif + if(event_data->status == FetchStatus::FINISHED_LOADING && event_data->message) { + if(event_data->message->related_event_id.empty() || body_item->embedded_item_status != FetchStatus::NONE) + return; + + // Check if we already have the referenced message as a body item, so we dont create a new one. + // 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) { + body_item->embedded_item = related_body_item; + body_item->embedded_item_status = FetchStatus::FINISHED_LOADING; + return; + } + + std::string message_event_id = event_data->message->related_event_id; + fetch_body_item = body_item; + body_item->embedded_item_status = FetchStatus::LOADING; + fetch_message_tab = MESSAGES_TAB_INDEX; + // TODO: Check if the message is already cached before calling async? is this needed? is async creation expensive? + fetch_message_future = [this, ¤t_room, message_event_id]() { + return FetchMessageResult{FetchMessageType::MESSAGE, matrix->get_message_by_id(current_room, message_event_id)}; + }; + return; + } + if(event_data->status != FetchStatus::NONE) return; @@ -3616,7 +3640,6 @@ namespace QuickMedia { }; // TODO: How about instead fetching all messages we have, not only the visible ones? also fetch with multiple threads. - // TODO: Cancel when going to another room? tabs[MESSAGES_TAB_INDEX].body->body_item_render_callback = [this, ¤t_room, &fetch_message_future, &tabs, &fetch_message, &find_body_item_by_event_id, &fetch_body_item, &fetch_message_tab](BodyItem *body_item) { if(fetch_message_future.valid() || !current_room) return; -- cgit v1.2.3