From 0b4e30d37a34bde1e3b0416a563897fcb233b429 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 6 Nov 2022 13:11:30 +0100 Subject: Matrix: post reply should use the last edited message in the raw body --- src/plugins/Matrix.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index db37a97..0fcc1c3 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -3483,8 +3483,19 @@ namespace QuickMedia { "" + std::move(formatted_body); } + static Message* get_latest_message_in_edit_chain(Message *message) { + while(message) { + Message *replaced_by = message->replaced_by.get(); + if(!replaced_by) + break; + message = replaced_by; + } + return message; + } + PluginResult Matrix::post_reply(RoomData *room, const std::string &body, void *relates_to, std::string &event_id_response, const std::string &custom_transaction_id, const std::optional &file_info, const std::optional &thumbnail_info) { Message *relates_to_message_raw = (Message*)relates_to; + Message *related_to_text_message = get_latest_message_in_edit_chain(relates_to_message_raw); std::string transaction_id = custom_transaction_id; if(transaction_id.empty()) @@ -3502,8 +3513,8 @@ namespace QuickMedia { rapidjson::Document relates_to_json(rapidjson::kObjectType); relates_to_json.AddMember("m.in_reply_to", std::move(in_reply_to_json), relates_to_json.GetAllocator()); - std::string message_reply_body = create_body_for_message_reply(relates_to_message_raw, body); // Yes, the reply is to the edited message but the event_id reference is to the original message... - std::string formatted_message_reply_body = create_formatted_body_for_message_reply(room, relates_to_message_raw, body); + std::string message_reply_body = create_body_for_message_reply(related_to_text_message, body); // Yes, the reply is to the edited message but the event_id reference is to the original message... + std::string formatted_message_reply_body = create_formatted_body_for_message_reply(room, related_to_text_message, body); rapidjson::Document request_data(rapidjson::kObjectType); request_data.AddMember("msgtype", rapidjson::StringRef(file_info ? content_type_to_message_type(file_info->content_type) : "m.text"), request_data.GetAllocator()); -- cgit v1.2.3