diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-10-04 22:33:40 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-10-04 22:33:40 +0200 |
commit | 5267b66a8822205187399290f44f27d720b01dda (patch) | |
tree | a96a4fabe7300926243899655195949f36f52965 /src | |
parent | 30d23a4fb9ad20bff7d7d31c914e9900b1bdf94c (diff) |
Matrix: add formatting to replies, fixes reply formatting on element mobile
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/Matrix.cpp | 38 | ||||
-rw-r--r-- | src/plugins/Plugin.cpp | 3 |
2 files changed, 39 insertions, 2 deletions
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 "<mx-reply>" + "<blockquote>" + "<a href=\"https://invalid.url\">In reply to</a>" + "<a href=\"https://matrix.to/#/" + message->user->user_id + "\">" + message->user->user_id + "</a><br>" + std::move(related_to_body) + + "</blockquote>" + "</mx-reply>" + std::move(formatted_body); + } // TODO: Add formatted_body just like element does with <mx-reply><blockquote... and also support greentext with that PluginResult Matrix::post_reply(const std::string &room_id, const std::string &body, void *relates_to) { @@ -1077,6 +1111,8 @@ namespace QuickMedia { Json::Value request_data(Json::objectValue); request_data["msgtype"] = "m.text"; // TODO: Allow image reply? element doesn't do that but we could! request_data["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... + request_data["format"] = "org.matrix.custom.html"; + request_data["formatted_body"] = create_formatted_body_for_message_reply(relates_to_message_raw, body); request_data["m.relates_to"] = std::move(relates_to_json); Json::StreamWriterBuilder builder; diff --git a/src/plugins/Plugin.cpp b/src/plugins/Plugin.cpp index 20c4b0a..c5726f1 100644 --- a/src/plugins/Plugin.cpp +++ b/src/plugins/Plugin.cpp @@ -39,7 +39,8 @@ namespace QuickMedia { HtmlEscapeSequence { '"', """ }, HtmlEscapeSequence { '\'', "'" }, HtmlEscapeSequence { '<', "<" }, - HtmlEscapeSequence { '>', ">" } + HtmlEscapeSequence { '>', ">" }, + HtmlEscapeSequence { '\n', "<br>" } }; for(const HtmlEscapeSequence &escape_sequence : escape_sequences) { |