diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/QuickMedia.cpp | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 4489194..f94601c 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -3811,6 +3811,19 @@ namespace QuickMedia { user_update_display_info(body_item->embedded_item.get(), room, (Message*)body_item->embedded_item->userdata); } + static Message* get_original_message(Message *message) { + if(!message) + return nullptr; + + Message *replaces = message->replaces; + while(replaces) { + if(!replaces->replaces) + return replaces; + replaces = replaces->replaces; + } + return nullptr; + } + bool Program::chat_page(MatrixChatPage *matrix_chat_page, RoomData *current_room, std::vector<Tab> &room_tabs, int room_selected_tab) { assert(current_room); assert(strcmp(plugin_name, "matrix") == 0); @@ -3973,13 +3986,15 @@ namespace QuickMedia { if(message->related_event_type == RelatedEventType::REDACTION) { set_body_as_deleted(message.get(), body_item.get()); } else { - Message *orig_message = static_cast<Message*>(body_item->userdata); + Message *reply_to_message = static_cast<Message*>(body_item->userdata); + Message *orig_message = get_original_message(reply_to_message); body_item->set_description(strip(message_get_body_remove_formatting(message.get()))); if(message->user != me && (message_contains_user_mention(body_item->get_description(), my_display_name) || message_contains_user_mention(body_item->get_description(), me->user_id) || (orig_message && orig_message->user == me))) body_item->set_description_color(sf::Color(255, 100, 100)); else body_item->set_description_color(sf::Color::White); - orig_message->replaced_by = message; + message->replaces = reply_to_message; + reply_to_message->replaced_by = message; } it = unreferenced_events.erase(it); } else { @@ -4009,13 +4024,15 @@ namespace QuickMedia { if(message->related_event_type == RelatedEventType::REDACTION) { set_body_as_deleted(message.get(), body_item.get()); } else { - Message *orig_message = static_cast<Message*>(body_item->userdata); + Message *reply_to_message = static_cast<Message*>(body_item->userdata); + Message *orig_message = get_original_message(reply_to_message); body_item->set_description(strip(message_get_body_remove_formatting(message.get()))); if(message->user != me && (message_contains_user_mention(body_item->get_description(), my_display_name) || message_contains_user_mention(body_item->get_description(), me->user_id) || (orig_message && orig_message->user == me))) body_item->set_description_color(sf::Color(255, 100, 100)); else body_item->set_description_color(sf::Color::White); - orig_message->replaced_by = message; + message->replaces = reply_to_message; + reply_to_message->replaced_by = message; } } else { unreferenced_events.push_back(message); @@ -4190,12 +4207,13 @@ namespace QuickMedia { if(message->related_event_type == RelatedEventType::EDIT) { auto 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(body_item) { - Message *orig_message = static_cast<Message*>(body_item->userdata); - if(!orig_message) { + Message *reply_to_message = static_cast<Message*>(body_item->userdata); + if(!reply_to_message) { show_notification("QuickMedia", "Unexpected error, failed to set replaced by message", Urgency::CRITICAL); return; } - orig_message->replaced_by = message; + message->replaces = reply_to_message; + reply_to_message->replaced_by = message; } } else if(message->related_event_type == RelatedEventType::REPLY) { auto pending_sent_reply_it = pending_sent_replies.find(message->transaction_id); |