aboutsummaryrefslogtreecommitdiff
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
parentf3937a874ce08ff9983d922383d86862696b716e (diff)
Matrix: fix emojis not removed from codeblocks when posting a message, clamp emoji size during post not upload
-rw-r--r--TODO5
-rw-r--r--plugins/Matrix.hpp2
-rw-r--r--src/Body.cpp12
-rw-r--r--src/Text.cpp5
-rw-r--r--src/plugins/Matrix.cpp38
5 files changed, 33 insertions, 29 deletions
diff --git a/TODO b/TODO
index c58db45..1b5f85d 100644
--- a/TODO
+++ b/TODO
@@ -245,5 +245,6 @@ Do not render invalid unicode.
Use matrix "from" with proper cache.
Text editing should take into consideration FORMATTED_TEXT_START/FORMATTED_TEXT_END.
4chan code syntax highlight. 4chan doesn't say what language it is so we have to somehow guess the language.
-Matrix autocomplete for emoji (and custom emoji).
-Nicer custom emoji upload options - Selecting name, size, cropping. \ No newline at end of file
+Matrix autocomplete for emoji (and custom emoji) and option show different sizes (for custom emoji).
+Nicer custom emoji upload options - Selecting name, size, cropping.
+Add option to copy somebody else custom emoji in matrix by pressing enter to bring up message option and in that a list of every emoji in the message should be added with "Add (emoji)..." text to add the emoji. \ No newline at end of file
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index 9378a9f..d5fe251 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -708,7 +708,7 @@ namespace QuickMedia {
void trigger_event(RoomData *room, MatrixEventType type, MatrixEventUserInfo user_info);
void trigger_event(RoomData *room, MatrixEventType type, MatrixEventRoomInfo room_info);
- void formatted_body_add_line(RoomData *room, std::string &formatted_body, const std::string &line_str);
+ void formatted_body_add_line(RoomData *room, std::string &formatted_body, const std::string &line_str, const std::unordered_map<std::string, CustomEmoji> &custom_emojis);
void replace_mentions(RoomData *room, std::string &text);
std::string create_formatted_body_for_message_reply(RoomData *room, const Message *message, const std::string &body);
diff --git a/src/Body.cpp b/src/Body.cpp
index 7411a79..adb774c 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -1455,7 +1455,7 @@ namespace QuickMedia {
if(item->author_text && !merge_with_previous) {
item->author_text->set_position(vec2f_floor(item_pos.x + text_offset_x, item_pos.y + padding_y - text_offset_y));
item->author_text->draw(window);
- item_pos.y += item->author_text->getHeight() - 2.0f + std::floor(3.0f * get_config().scale);
+ item_pos.y += item->author_text->getHeight() + std::floor(3.0f * get_config().scale);
}
if(include_embedded_item && item->embedded_item_status != FetchStatus::NONE) {
@@ -1481,14 +1481,14 @@ namespace QuickMedia {
if(item->title_text) {
item->title_text->set_position(vec2f_floor(item_pos.x + text_offset_x, item_pos.y + padding_y - text_offset_y));
item->title_text->draw(window);
- item_pos.y += item->title_text->getHeight() - 2.0f + std::floor(3.0f * get_config().scale);
+ item_pos.y += item->title_text->getHeight() + std::floor(3.0f * get_config().scale);
}
if(item->description_text) {
float height_offset = 0.0f;
item->description_text->set_position(vec2f_floor(item_pos.x + text_offset_x, item_pos.y + padding_y - text_offset_y + height_offset));
item->description_text->draw(window);
- item_pos.y += item->description_text->getHeight() - 2.0f;
+ item_pos.y += item->description_text->getHeight();
}
if(!item->reactions.empty() && include_embedded_item) {
@@ -1705,11 +1705,11 @@ namespace QuickMedia {
float item_height = 0.0f;
bool has_loaded_text = false;
if(item->title_text) {
- item_height += item->title_text->getHeight() - 2.0f + std::floor(3.0f * get_config().scale);
+ item_height += item->title_text->getHeight() + std::floor(3.0f * get_config().scale);
has_loaded_text = true;
}
if(item->author_text && !merge_with_previous) {
- item_height += item->author_text->getHeight() - 2.0f + std::floor(3.0f * get_config().scale);
+ item_height += item->author_text->getHeight() + std::floor(3.0f * get_config().scale);
has_loaded_text = true;
}
if(include_embedded_item && item->embedded_item_status != FetchStatus::NONE) {
@@ -1721,7 +1721,7 @@ namespace QuickMedia {
has_loaded_text = true; // TODO: Remove this
}
if(item->description_text) {
- item_height += item->description_text->getHeight() - 2.0f;
+ item_height += item->description_text->getHeight();
has_loaded_text = true;
}
diff --git a/src/Text.cpp b/src/Text.cpp
index 50db0ee..28247e6 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -785,6 +785,7 @@ namespace QuickMedia
mgl::vec2f glyphPos;
uint32_t prevCodePoint = 0;
+ bool text_contains_images = false;
// TODO: Only do this if dirtyText (then the Text object shouldn't be reset in Body. There should be a cleanup function in text instead)
for(int textElementIndex = 0; textElementIndex < (int)textElements.size(); ++textElementIndex)
{
@@ -807,6 +808,7 @@ namespace QuickMedia
if(!text_format_stack.empty())
text_format_stack.pop();
} else if(textElement.type == TextElement::Type::IMAGE) {
+ text_contains_images = true;
vertices_index = FONT_INDEX_IMAGE;
mgl::Color image_color(255, 255, 255, text_element_color.a);
int vertexStart = vertices[vertices_index].size();
@@ -1118,7 +1120,8 @@ namespace QuickMedia
}
}
vertices_linear_done:;
- move_vertex_lines_by_largest_items(vertices_linear_index);
+ if(text_contains_images)
+ move_vertex_lines_by_largest_items(vertices_linear_index);
// TODO: Optimize
for(TextElement &textElement : textElements) {
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());
}