aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Fourchan.cpp19
-rw-r--r--src/plugins/Matrix.cpp39
2 files changed, 37 insertions, 21 deletions
diff --git a/src/plugins/Fourchan.cpp b/src/plugins/Fourchan.cpp
index 4cfaeaa..c58d942 100644
--- a/src/plugins/Fourchan.cpp
+++ b/src/plugins/Fourchan.cpp
@@ -260,35 +260,38 @@ namespace QuickMedia {
comment_text += std::move(cp.text);
break;
case CommentPiece::Type::QUOTE:
- comment_text += std::move(cp.text);
+ comment_text += Text::formatted_text(std::move(cp.text), mgl::Color(120, 153, 34), FORMATTED_TEXT_FLAG_COLOR);
break;
case CommentPiece::Type::QUOTE_CONTINUE:
- comment_text += std::move(cp.text);
+ comment_text += Text::formatted_text(std::move(cp.text), mgl::Color(120, 153, 34), FORMATTED_TEXT_FLAG_COLOR);
break;
case CommentPiece::Type::QUOTELINK: {
- comment_text += std::move(cp.text);
auto it = comment_by_postno.find(cp.quote_postnumber);
if(it == comment_by_postno.end()) {
// TODO: Link this quote to a 4chan archive that still has the quoted comment (if available)
- comment_text += " (Dead)";
+ comment_text += Text::formatted_text(std::move(cp.text) + " (DEAD)", get_theme().attention_alert_text_color, FORMATTED_TEXT_FLAG_COLOR);
} else {
result_items[body_item_index]->replies_to.push_back(it->second);
result_items[it->second]->replies.push_back(body_item_index);
result_items[it->second]->add_reaction(">>" + result_items[body_item_index]->post_number, nullptr, get_theme().replies_text_color);
+ if(it->second == 0)
+ comment_text += Text::formatted_text(std::move(cp.text) + " (OP)", get_theme().attention_alert_text_color, FORMATTED_TEXT_FLAG_COLOR);
+ else
+ comment_text += Text::formatted_text(std::move(cp.text), get_theme().attention_alert_text_color, FORMATTED_TEXT_FLAG_COLOR);
}
break;
}
case CommentPiece::Type::DEADLINK:
// TODO: Link this quote to a 4chan archive that still has the quoted comment (if available)
- comment_text += std::move(cp.text) + " (Dead)";
+ comment_text += Text::formatted_text(std::move(cp.text) + " (DEAD)", get_theme().attention_alert_text_color, FORMATTED_TEXT_FLAG_COLOR);
break;
case CommentPiece::Type::CROSSBOARD_LINK:
// TODO: Link this to another thread and allow navigating to it
- comment_text += std::move(cp.text) + " (Cross-thread)";
+ comment_text += Text::formatted_text(std::move(cp.text) + " (Cross-thread)", get_theme().attention_alert_text_color, FORMATTED_TEXT_FLAG_COLOR);
break;
case CommentPiece::Type::CODEBLOCK:
- // TODO: Use a different colored background and use a monospace font
- comment_text += std::move(cp.text);
+ // 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);
break;
}
});
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 14a5bbe..a9284f5 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -599,7 +599,7 @@ namespace QuickMedia {
}
static std::string message_to_room_description_text(Message *message) {
- std::string body = strip(formatted_text_to_qm_text(message->body.c_str(), message->body.size()));
+ std::string body = strip(formatted_text_to_qm_text(message->body.c_str(), message->body.size(), true));
if(message->type == MessageType::REACTION)
return "Reacted with: " + body;
else if(message->related_event_type == RelatedEventType::REPLY)
@@ -2102,7 +2102,7 @@ namespace QuickMedia {
}
// TODO: Do not show notification if mention is a reply to somebody else that replies to me? also dont show notification everytime a mention is edited
- bool message_contains_user_mention(const std::string &msg, const std::string &username) {
+ static bool message_contains_user_mention(const std::string &msg, const std::string &username) {
if(msg.empty() || username.empty())
return false;
@@ -2129,6 +2129,16 @@ namespace QuickMedia {
return false;
}
+ bool message_contains_user_mention(const Message *message, const std::string &username, const std::string &user_id) {
+ const std::string formatted_text = formatted_text_to_qm_text(message->body.c_str(), message->body.size(), false);
+ return message_contains_user_mention(formatted_text, username) || message_contains_user_mention(formatted_text, user_id);
+ }
+
+ bool message_contains_user_mention(const BodyItem *body_item, const std::string &username, const std::string &user_id) {
+ const std::string formatted_text = Text::to_printable_string(body_item->get_description());
+ return message_contains_user_mention(formatted_text, username) || message_contains_user_mention(formatted_text, user_id);
+ }
+
bool message_is_timeline(Message *message) {
return message->type >= MessageType::TEXT && message->type <= MessageType::FILE;
}
@@ -2186,8 +2196,10 @@ namespace QuickMedia {
for(auto &message : new_messages) {
// TODO: Is @room ok? shouldn't we also check if the user has permission to do @room? (only when notifications are limited to @mentions)
// TODO: Is comparing against read marker timestamp ok enough?
- if(me && message->timestamp > read_marker_message_timestamp)
- message->notification_mentions_me = message_contains_user_mention(message->body, my_display_name) || message_contains_user_mention(message->body, me->user_id) || message_contains_user_mention(message->body, "@room");
+ if(me && message->timestamp > read_marker_message_timestamp) {
+ std::string message_str = formatted_text_to_qm_text(message->body.c_str(), message->body.size(), false);
+ message->notification_mentions_me = message_contains_user_mention(message_str, my_display_name) || message_contains_user_mention(message_str, me->user_id) || message_contains_user_mention(message_str, "@room");
+ }
}
}
@@ -2277,6 +2289,7 @@ namespace QuickMedia {
bool inside_font_tag = false;
bool font_tag_has_custom_color = false;
bool inside_code_tag = false;
+ bool allow_formatted_text = false;
mgl::Color font_color = mgl::Color(255, 255, 255, 255);
};
@@ -2327,7 +2340,7 @@ namespace QuickMedia {
if(parse_userdata.inside_code_tag)
formatted_text_flags |= FORMATTED_TEXT_FLAG_MONOSPACE;
- if(formatted_text_flags != FORMATTED_TEXT_FLAG_NONE)
+ if(formatted_text_flags != FORMATTED_TEXT_FLAG_NONE && parse_userdata.allow_formatted_text)
parse_userdata.result += Text::formatted_text(text_to_add, parse_userdata.font_color, formatted_text_flags);
else
parse_userdata.result += std::move(text_to_add);
@@ -2338,8 +2351,9 @@ namespace QuickMedia {
return 0;
}
- std::string formatted_text_to_qm_text(const char *str, size_t size) {
+ std::string formatted_text_to_qm_text(const char *str, size_t size, bool allow_formatted_text) {
FormattedTextParseUserdata parse_userdata;
+ parse_userdata.allow_formatted_text = allow_formatted_text;
html_parser_parse(str, size, formattext_text_parser_callback, &parse_userdata);
return std::move(parse_userdata.result);
}
@@ -3429,6 +3443,10 @@ namespace QuickMedia {
return formatted_body;
}
+ void Matrix::on_exit_room(RoomData *room) {
+ my_events_transaction_ids.clear();
+ }
+
PluginResult Matrix::post_message(RoomData *room, const std::string &body, std::string &event_id_response, const std::optional<UploadInfo> &file_info, const std::optional<UploadInfo> &thumbnail_info, const std::string &msgtype) {
std::string transaction_id = create_transaction_id();
if(transaction_id.empty())
@@ -3520,17 +3538,12 @@ namespace QuickMedia {
if(msg_begin != std::string::npos)
return str.substr(msg_begin + 2);
}
+ } else {
+ return formatted_text_to_qm_text(str.c_str(), str.size(), false);
}
return str;
}
- std::string message_get_body_remove_formatting(Message *message) {
- if(message->related_event_type == RelatedEventType::REPLY || message->related_event_type == RelatedEventType::EDIT)
- return remove_reply_formatting(message->body);
- else
- return message->body;
- }
-
static std::string block_quote(const std::string &str) {
std::string result;
for(char c : str) {