From 4197fd3d7aaa84197eb17e700fb27093293f228b Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 12 Nov 2022 12:06:47 +0100 Subject: Matrix: fix reply formatted body including reply-to-reply message when it shouldn't --- src/plugins/Matrix.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 65e29a3..515ef7a 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -122,6 +122,14 @@ namespace QuickMedia { return colors[color_hash_code(user_id) % num_colors]; } + std::string formatted_text_remove_reply(const std::string &str) { + size_t last_mx_reply_end = str.rfind(""); + if(last_mx_reply_end == std::string::npos) + return str; + else + return str.substr(last_mx_reply_end + 11); + } + static std::string remove_reply_formatting(Matrix *matrix, const std::string &str) { if(strncmp(str.c_str(), "> <@", 4) == 0) { size_t index = str.find("> ", 4); @@ -147,7 +155,7 @@ namespace QuickMedia { return message->body; } else { if(keep_formatted) - return message->body; + return formatted_text_remove_reply(message->body); else return formatted_text_to_qm_text(matrix, message->body.c_str(), message->body.size(), false); } @@ -2666,7 +2674,7 @@ namespace QuickMedia { FormattedTextParseUserdata &parse_userdata = *(FormattedTextParseUserdata*)userdata; switch(parse_type) { case HTML_PARSE_TAG_START: { - if(html_parser->tag_name.size == 2 && memcmp(html_parser->tag_name.data, "br", 2) == 0) + if(html_parser->tag_name.size == 2 && memcmp(html_parser->tag_name.data, "br", 2) == 0 && parse_userdata.mx_reply_depth == 0) parse_userdata.result += '\n'; else if(html_parser->tag_name.size == 4 && memcmp(html_parser->tag_name.data, "font", 4) == 0) parse_userdata.inside_font_tag = true; @@ -2684,7 +2692,7 @@ namespace QuickMedia { break; } case HTML_PARSE_TAG_END: { - /*if(html_parser->tag_name.size == 2 && memcmp(html_parser->tag_name.data, "br", 2) == 0) { + /*if(html_parser->tag_name.size == 2 && memcmp(html_parser->tag_name.data, "br", 2) == 0 && parse_userdata.mx_reply_depth == 0) { parse_userdata.result += '\n'; } else */if(html_parser->tag_name.size == 4 && memcmp(html_parser->tag_name.data, "font", 4) == 0) { parse_userdata.inside_font_tag = false; @@ -3988,7 +3996,7 @@ namespace QuickMedia { related_to_body = remove_reply_formatting(matrix, message, keep_formatted); } else { if(keep_formatted && message->body_is_formatted) - related_to_body = message->body; + related_to_body = formatted_text_remove_reply(message->body); else related_to_body = message_to_qm_text(matrix, message, false); } @@ -4008,7 +4016,7 @@ namespace QuickMedia { break; case MessageType::REDACTION: { if(keep_formatted && message->body_is_formatted) - related_to_body = message->body; + related_to_body = formatted_text_remove_reply(message->body); else related_to_body = message_to_qm_text(matrix, message, false); break; -- cgit v1.2.3