Remove unallowed reply quote entities.
This commit is contained in:
parent
7f5da4b5c5
commit
b2b665e8d6
@ -1229,7 +1229,7 @@ messageSendingStateFailed error:error can_retry:Bool need_another_sender:Bool re
|
||||
//@description Describes a message replied by a given message
|
||||
//@chat_id The identifier of the chat to which the message belongs; may be 0 if the replied message is in another chat and isn't accessible
|
||||
//@message_id The identifier of the message; may be 0 if the replied message is in another chat and isn't accessible
|
||||
//@quote Manually or automatically chosen quote from the replied message; may be null if none
|
||||
//@quote Manually or automatically chosen quote from the replied message; may be null if none. Only Bold, Italic, Underline, Strikethrough, Spoiler, and CustomEmoji entities can be present in the quote
|
||||
//@is_quote_manual True, if the quote was manually chosen by the message sender
|
||||
//@origin Information about origin of the message if the message was replied from another chat; may be null for messages from the same chat
|
||||
//@origin_send_date Point in time (Unix timestamp) when the message was sent if the message was replied from another chat; 0 for messages from the same chat
|
||||
@ -1247,7 +1247,8 @@ messageReplyToStory story_sender_chat_id:int53 story_id:int32 = MessageReplyTo;
|
||||
//@description Describes a message to be replied
|
||||
//@chat_id The identifier of the chat to which the message to be replied belongs; pass 0 if the replied message is in the same chat. A message can be replied in another chat only if message.can_be_forwarded
|
||||
//@message_id The identifier of the message to be replied in the same chat
|
||||
//@quote Manually chosen quote from the replied message; pass null if none; 0-getOption("message_reply_quote_length_max") characters
|
||||
//@quote Manually chosen quote from the replied message; pass null if none; 0-getOption("message_reply_quote_length_max") characters.
|
||||
//-Only Bold, Italic, Underline, Strikethrough, Spoiler, and CustomEmoji entities are allowed to be kept and must be kept in the quote
|
||||
inputMessageReplyToMessage chat_id:int53 message_id:int53 quote:formattedText = InputMessageReplyTo;
|
||||
|
||||
//@description Describes a story to be replied @story_sender_chat_id The identifier of the sender of the story. Currently, stories can be replied only in the sender's chat @story_id The identifier of the story
|
||||
|
@ -1415,6 +1415,24 @@ void remove_empty_entities(vector<MessageEntity> &entities) {
|
||||
});
|
||||
}
|
||||
|
||||
static bool is_allowed_quote_entity(const MessageEntity &entity) {
|
||||
switch (entity.type) {
|
||||
case MessageEntity::Type::Bold:
|
||||
case MessageEntity::Type::Italic:
|
||||
case MessageEntity::Type::Underline:
|
||||
case MessageEntity::Type::Strikethrough:
|
||||
case MessageEntity::Type::Spoiler:
|
||||
case MessageEntity::Type::CustomEmoji:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void remove_unallowed_quote_entities(FormattedText &text) {
|
||||
td::remove_if(text.entities, [](const auto &entity) { return !is_allowed_quote_entity(entity); });
|
||||
}
|
||||
|
||||
static int32 text_length(Slice text) {
|
||||
return narrow_cast<int32>(utf8_utf16_length(text));
|
||||
}
|
||||
|
@ -183,6 +183,8 @@ vector<std::pair<Slice, int32>> find_media_timestamps(Slice str); // slice + me
|
||||
|
||||
void remove_empty_entities(vector<MessageEntity> &entities);
|
||||
|
||||
void remove_unallowed_quote_entities(FormattedText &text);
|
||||
|
||||
string get_first_url(const FormattedText &text);
|
||||
|
||||
bool is_visible_url(const FormattedText &text, const string &url);
|
||||
|
@ -68,6 +68,7 @@ MessageInputReplyTo::MessageInputReplyTo(Td *td,
|
||||
entities.clear();
|
||||
}
|
||||
quote_ = FormattedText{std::move(reply_to->quote_text_), std::move(entities)};
|
||||
remove_unallowed_quote_entities(quote_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ class MessageInputReplyTo {
|
||||
|
||||
MessageInputReplyTo(MessageId message_id, DialogId dialog_id, FormattedText &"e)
|
||||
: message_id_(message_id), dialog_id_(dialog_id), quote_(std::move(quote)) {
|
||||
remove_unallowed_quote_entities(quote_);
|
||||
}
|
||||
|
||||
explicit MessageInputReplyTo(StoryFullId story_full_id) : story_full_id_(story_full_id) {
|
||||
|
@ -60,6 +60,7 @@ void MessageInputReplyTo::parse(ParserT &parser) {
|
||||
}
|
||||
if (has_quote) {
|
||||
td::parse(quote_, parser);
|
||||
remove_unallowed_quote_entities(quote_);
|
||||
}
|
||||
if (has_dialog_id) {
|
||||
td::parse(dialog_id_, parser);
|
||||
|
@ -144,6 +144,7 @@ RepliedMessageInfo::RepliedMessageInfo(Td *td, tl_object_ptr<telegram_api::messa
|
||||
entities.clear();
|
||||
}
|
||||
quote_ = FormattedText{std::move(reply_header->quote_text_), std::move(entities)};
|
||||
remove_unallowed_quote_entities(quote_);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,6 +84,7 @@ void RepliedMessageInfo::parse(ParserT &parser) {
|
||||
}
|
||||
if (has_quote) {
|
||||
td::parse(quote_, parser);
|
||||
remove_unallowed_quote_entities(quote_);
|
||||
}
|
||||
if (has_content) {
|
||||
parse_message_content(content_, parser);
|
||||
|
Loading…
Reference in New Issue
Block a user