From 5267b66a8822205187399290f44f27d720b01dda Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 4 Oct 2020 22:33:40 +0200 Subject: Matrix: add formatting to replies, fixes reply formatting on element mobile --- TODO | 2 +- src/plugins/Matrix.cpp | 38 +++++++++++++++++++++++++++++++++++++- src/plugins/Plugin.cpp | 3 ++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index adb2d36..93f7396 100644 --- a/TODO +++ b/TODO @@ -85,7 +85,7 @@ Save the original event message, so when replying for example we can use the ori Remove tidy dependency and use my own html-parser. Add option to sort by other than timestamp for nyaa.si. Add url preview for matrix (using matrix api, fallback to client url preview (using our own url preview project)). -Cleanup old messages in matrix (from matrix plugin), and instead either save them to disk or refetch them from server when going up to read old messages. +IMPORTANT: Cleanup old messages in matrix (from matrix plugin), and instead either save them to disk or refetch them from server when going up to read old messages. (High memory usage, high disk space) Use memberName() instead of key() when iterating json object. key() creates a copy, memberName() doesn't. Do not try to reload/redownload thumbnail that fails to download after its cleared when its no longer visible on screen and then becomes visible. Sort matrix events by timestamp (not messages). This affects the applying of certain actions, such as changing avatar, room name, etc. \ No newline at end of file diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 8f3f679..34c47f1 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -1043,7 +1043,41 @@ namespace QuickMedia { break; } return "> <" + message->user->user_id + "> " + block_quote(std::move(related_to_body)) + "\n\n" + body; - } + } + + static std::string create_formatted_body_for_message_reply(const Message *message, const std::string &body) { + std::string related_to_body; + switch(message->type) { + case MessageType::TEXT: { + if(!message->replaces_event_id.empty() && strncmp(message->body.c_str(), " * ", 3) == 0) + related_to_body = remove_reply_formatting(message->body.substr(3)); + else + related_to_body = remove_reply_formatting(message->body); + break; + } + case MessageType::IMAGE: + related_to_body = "sent an image"; + break; + case MessageType::VIDEO: + related_to_body = "sent a video"; + break; + case MessageType::AUDIO: + related_to_body = "sent an audio file"; + break; + case MessageType::FILE: + related_to_body = "sent a file"; + break; + } + std::string formatted_body = body; + html_escape_sequences(formatted_body); + html_escape_sequences(related_to_body); + return "" + "
" + "In reply to" + "user->user_id + "\">" + message->user->user_id + "
" + std::move(related_to_body) + + "
" + "
" + std::move(formatted_body); + } // TODO: Add formatted_body just like element does with ', ">" } + HtmlEscapeSequence { '>', ">" }, + HtmlEscapeSequence { '\n', "
" } }; for(const HtmlEscapeSequence &escape_sequence : escape_sequences) { -- cgit v1.2.3