aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-11-11 17:36:44 +0100
committerdec05eba <dec05eba@protonmail.com>2022-11-11 17:36:44 +0100
commit4815b649c09fd461baf0e48306abab7f790f5ca5 (patch)
tree1ec5409164b1028aa8728fb1b909d828bbd56ffc /src/plugins
parentf3937a874ce08ff9983d922383d86862696b716e (diff)
Matrix: fix emojis not removed from codeblocks when posting a message, clamp emoji size during post not upload
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Matrix.cpp38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 17d4735..c366569 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -25,6 +25,7 @@
// Show images/videos inline.
// TODO: Verify if buffer of size 512 is enough for endpoints
// Remove older messages (outside screen) to save memory. Reload them when the selected body item is the top/bottom one.
+// TODO: Custom account data should be in im.qm.*, not qm.*
namespace QuickMedia {
static const mgl::vec2i thumbnail_max_size(600, 337);
@@ -3693,7 +3694,20 @@ namespace QuickMedia {
return std::string::npos;
}
- void Matrix::formatted_body_add_line(RoomData *room, std::string &formatted_body, const std::string &line_str) {
+ static void replace_emoji_references_with_formatted_images(std::string &str, const std::unordered_map<std::string, CustomEmoji> &custom_emojis) {
+ for(const auto &it : custom_emojis) {
+ std::string keybind = ":" + it.first + ":";
+ std::string url = it.second.url;
+ html_escape_sequences(url);
+ mgl::vec2i img_size = clamp_to_size(it.second.size, custom_emoji_max_size);
+ std::string width = std::to_string(img_size.x);
+ std::string height = std::to_string(img_size.y);
+ std::string tag = "<img src=\"" + url + "\" alt=\"" + keybind + "\" width=\"" + width + "\" height=\"" + height + "\" />";
+ string_replace_all(str, keybind, tag);
+ }
+ }
+
+ void Matrix::formatted_body_add_line(RoomData *room, std::string &formatted_body, const std::string &line_str, const std::unordered_map<std::string, CustomEmoji> &custom_emojis) {
size_t index = 0;
while(true) {
size_t backquote_start_index = find_backquote_index_with_escape(line_str, index);
@@ -3713,6 +3727,7 @@ namespace QuickMedia {
std::string str_to_append = line_str.substr(index);
replace_mentions(room, str_to_append);
+ replace_emoji_references_with_formatted_images(str_to_append, custom_emojis);
formatted_body += std::move(str_to_append);
break;
}
@@ -3776,18 +3791,6 @@ namespace QuickMedia {
}
}
- static void replace_emoji_references_with_formatted_images(std::string &str, const std::unordered_map<std::string, CustomEmoji> &custom_emojis) {
- for(const auto &it : custom_emojis) {
- std::string keybind = ":" + it.first + ":";
- std::string url = it.second.url;
- html_escape_sequences(url);
- std::string width = std::to_string(it.second.size.x);
- std::string height = std::to_string(it.second.size.y);
- std::string tag = "<img src=\"" + url + "\" alt=\"" + keybind + "\" width=\"" + width + "\" height=\"" + height + "\" />";
- string_replace_all(str, keybind, tag);
- }
- }
-
// TODO: remove first/last newspace in codeblock.
std::string Matrix::body_to_formatted_body(RoomData *room, const std::string &body) {
@@ -3824,18 +3827,15 @@ namespace QuickMedia {
}
is_first_line = true;
} else {
- if(!is_inside_code_block)
- replace_emoji_references_with_formatted_images(line_str, custom_emojis_copy);
-
if(!is_inside_code_block && size > 0 && str[0] == '>') {
formatted_body += "<font color=\"#789922\">";
- formatted_body_add_line(room, formatted_body, line_str);
+ formatted_body_add_line(room, formatted_body, line_str, custom_emojis_copy);
formatted_body += "</font>";
} else {
if(is_inside_code_block) {
formatted_body += line_str;
} else {
- formatted_body_add_line(room, formatted_body, line_str);
+ formatted_body_add_line(room, formatted_body, line_str, custom_emojis_copy);
}
}
is_first_line = false;
@@ -4400,7 +4400,7 @@ namespace QuickMedia {
rapidjson::Document emoji_obj(rapidjson::kObjectType);
emoji_obj.AddMember("url", rapidjson::Value(mxc_url.c_str(), request_data.GetAllocator()).Move(), request_data.GetAllocator());
if(file_info.dimensions) {
- custom_emoji.size = clamp_to_size(mgl::vec2i(file_info.dimensions->width, file_info.dimensions->height), custom_emoji_max_size);
+ custom_emoji.size = { file_info.dimensions->width, file_info.dimensions->height };
emoji_obj.AddMember("width", custom_emoji.size.x, request_data.GetAllocator());
emoji_obj.AddMember("height", custom_emoji.size.y, request_data.GetAllocator());
}