aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-11-09 18:49:00 +0100
committerdec05eba <dec05eba@protonmail.com>2022-11-09 18:49:00 +0100
commit60f37ebeb130bd58adece6bee06420b40c4e5a05 (patch)
tree554fc8839bba69e2a51b4862b292953640ee5eff /src/plugins
parentdeb32bded40c4c46ce57c729c303edcb1915458b (diff)
Matrix: reply body formatting shouldn't have html, formatted body should be pure html. Dont display urls in codeblocks
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Fourchan.cpp2
-rw-r--r--src/plugins/Matrix.cpp38
2 files changed, 26 insertions, 14 deletions
diff --git a/src/plugins/Fourchan.cpp b/src/plugins/Fourchan.cpp
index c58d942..4a9d2d7 100644
--- a/src/plugins/Fourchan.cpp
+++ b/src/plugins/Fourchan.cpp
@@ -291,7 +291,7 @@ namespace QuickMedia {
break;
case CommentPiece::Type::CODEBLOCK:
// TODO: Use a different colored background
- comment_text += Text::formatted_text(std::move(cp.text), mgl::Color(255, 255, 255, 255), FORMATTED_TEXT_FLAG_MONOSPACE);
+ comment_text += Text::formatted_text(std::move(cp.text), mgl::Color(255, 255, 255, 255), FORMATTED_TEXT_FLAG_CODE);
break;
}
});
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 31aab76..82ca583 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -131,7 +131,7 @@ namespace QuickMedia {
return str;
}
- static std::string remove_reply_formatting(const Message *message) {
+ static std::string remove_reply_formatting(const Message *message, bool keep_formatted = false) {
if(!message->body_is_formatted && strncmp(message->body.c_str(), "> <@", 4) == 0) {
size_t index = message->body.find("> ", 4);
if(index != std::string::npos) {
@@ -141,7 +141,10 @@ namespace QuickMedia {
}
return message->body;
} else {
- return formatted_text_to_qm_text(message->body.c_str(), message->body.size(), false);
+ if(keep_formatted)
+ return message->body;
+ else
+ return formatted_text_to_qm_text(message->body.c_str(), message->body.size(), false);
}
}
@@ -2391,9 +2394,9 @@ namespace QuickMedia {
formatted_text_flags |= FORMATTED_TEXT_FLAG_COLOR;
if(parse_userdata.inside_source_highlight || !parse_userdata.supports_syntax_highlight || (parse_userdata.inside_code_tag && parse_userdata.code_tag_language.size() == 0)) {
- formatted_text_flags |= FORMATTED_TEXT_FLAG_MONOSPACE;
+ formatted_text_flags |= FORMATTED_TEXT_FLAG_CODE;
} else if(parse_userdata.inside_code_tag) {
- formatted_text_flags |= FORMATTED_TEXT_FLAG_MONOSPACE;
+ formatted_text_flags |= FORMATTED_TEXT_FLAG_CODE;
// TODO: guess language from code if no language is set.
// TODO: Allow the user to choose style in config file.
@@ -3622,14 +3625,18 @@ namespace QuickMedia {
return result;
}
- static std::string get_reply_message(const Message *message) {
+ static std::string get_reply_message(const Message *message, bool keep_formatted = false) {
std::string related_to_body;
switch(message->type) {
case MessageType::TEXT: {
- if(message->related_event_type != RelatedEventType::NONE)
- related_to_body = remove_reply_formatting(message);
- else
- related_to_body = message->body;
+ if(message->related_event_type != RelatedEventType::NONE) {
+ related_to_body = remove_reply_formatting(message, keep_formatted);
+ } else {
+ if(keep_formatted && message->body_is_formatted)
+ related_to_body = message->body;
+ else
+ related_to_body = message_to_qm_text(message, false);
+ }
break;
}
case MessageType::IMAGE:
@@ -3644,9 +3651,13 @@ namespace QuickMedia {
case MessageType::FILE:
related_to_body = "sent a file";
break;
- case MessageType::REDACTION:
- related_to_body = message->body;
+ case MessageType::REDACTION: {
+ if(keep_formatted && message->body_is_formatted)
+ related_to_body = message->body;
+ else
+ related_to_body = message_to_qm_text(message, false);
break;
+ }
}
return related_to_body;
}
@@ -3664,8 +3675,9 @@ namespace QuickMedia {
std::string Matrix::create_formatted_body_for_message_reply(RoomData *room, const Message *message, const std::string &body) {
std::string formatted_body = body_to_formatted_body(room, body);
- std::string related_to_body = get_reply_message(message);
- html_escape_sequences(related_to_body);
+ std::string related_to_body = get_reply_message(message, true);
+ if(!message->body_is_formatted)
+ html_escape_sequences(related_to_body);
// TODO: Add keybind to navigate to the reply message, which would also depend on this formatting.
// Note: user id and event id is not url escaped here on purpose, because that messes up riot.im replies for certain user ids...
return "<mx-reply>"