aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-11-12 12:06:47 +0100
committerdec05eba <dec05eba@protonmail.com>2022-11-12 12:06:47 +0100
commit4197fd3d7aaa84197eb17e700fb27093293f228b (patch)
tree53d1b75f0d15d9476952c1ee6cedf0f4125db887 /src/plugins
parent68528e19c46946e1a7e03353893b59b2e2a49559 (diff)
Matrix: fix reply formatted body including reply-to-reply message when it shouldn't
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Matrix.cpp18
1 files changed, 13 insertions, 5 deletions
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("</mx-reply>");
+ 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;