aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-04 22:33:40 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-04 22:33:40 +0200
commit5267b66a8822205187399290f44f27d720b01dda (patch)
treea96a4fabe7300926243899655195949f36f52965
parent30d23a4fb9ad20bff7d7d31c914e9900b1bdf94c (diff)
Matrix: add formatting to replies, fixes reply formatting on element mobile
-rw-r--r--TODO2
-rw-r--r--src/plugins/Matrix.cpp38
-rw-r--r--src/plugins/Plugin.cpp3
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 "<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 { '"', "&quot;" },
HtmlEscapeSequence { '\'', "&#39;" },
HtmlEscapeSequence { '<', "&lt;" },
- HtmlEscapeSequence { '>', "&gt;" }
+ HtmlEscapeSequence { '>', "&gt;" },
+ HtmlEscapeSequence { '\n', "<br>" }
};
for(const HtmlEscapeSequence &escape_sequence : escape_sequences) {