aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp27
1 files changed, 25 insertions, 2 deletions
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, &current_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, &current_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, &current_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;