From 6beaa000d590db342bc0198590686cbbd6304eb4 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 19 May 2021 00:24:27 +0200 Subject: Disable mention formatting in single line code blocks --- plugins/Matrix.hpp | 1 + src/plugins/Matrix.cpp | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp index 0e96fd7..0c90587 100644 --- a/plugins/Matrix.hpp +++ b/plugins/Matrix.hpp @@ -585,6 +585,7 @@ namespace QuickMedia { // No-op if sync is cache or if |room| is not the currently enabled event queue room void trigger_event(RoomData *room, std::unique_ptr event); + void formatted_body_add_line(RoomData *room, std::string &formatted_body, const std::string &line_str); void replace_mentions(RoomData *room, std::string &text); std::string body_to_formatted_body(RoomData *room, const std::string &body); std::string create_formatted_body_for_message_reply(RoomData *room, const Message *message, const std::string &body); diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index bf988ca..4328888 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -2751,14 +2751,16 @@ namespace QuickMedia { return std::string::npos; } - static void formatted_body_add_line(std::string &formatted_body, const std::string &line_str) { + void Matrix::formatted_body_add_line(RoomData *room, std::string &formatted_body, const std::string &line_str) { size_t index = 0; while(true) { size_t backquote_start_index = find_backquote_index_with_escape(line_str, index); if(backquote_start_index != std::string::npos) { size_t backquote_end_index = find_backquote_index_with_escape(line_str, backquote_start_index + 1); if(backquote_end_index != std::string::npos) { - formatted_body += line_str.substr(index, backquote_start_index - index); + std::string str_to_append = line_str.substr(index, backquote_start_index - index); + replace_mentions(room, str_to_append); + formatted_body += std::move(str_to_append); formatted_body += ""; formatted_body += line_str.substr(backquote_start_index + 1, backquote_end_index - (backquote_start_index + 1)); formatted_body += ""; @@ -2767,7 +2769,9 @@ namespace QuickMedia { } } - formatted_body += line_str.substr(index); + std::string str_to_append = line_str.substr(index); + replace_mentions(room, str_to_append); + formatted_body += std::move(str_to_append); break; } } @@ -2856,15 +2860,13 @@ namespace QuickMedia { } else { if(!is_inside_code_block && size > 0 && str[0] == '>') { formatted_body += ""; - replace_mentions(room, line_str); - formatted_body_add_line(formatted_body, line_str); + formatted_body_add_line(room, formatted_body, line_str); formatted_body += ""; } else { if(is_inside_code_block) { formatted_body += line_str; } else { - replace_mentions(room, line_str); - formatted_body_add_line(formatted_body, line_str); + formatted_body_add_line(room, formatted_body, line_str); } } is_first_line = false; -- cgit v1.2.3