Improve remove_unallowed_entities.
This commit is contained in:
parent
e3ae8957bb
commit
6383e7f1b1
@ -53,7 +53,7 @@ Result<InputMessageText> process_input_message_text(const Td *td, DialogId dialo
|
|||||||
is_bot || for_draft, for_draft)
|
is_bot || for_draft, for_draft)
|
||||||
.ensure();
|
.ensure();
|
||||||
}
|
}
|
||||||
remove_unallowed_entities(td->stickers_manager_.get(), result.text, dialog_id.get_type() == DialogType::SecretChat);
|
remove_unallowed_entities(td, result.text, dialog_id);
|
||||||
return std::move(result);
|
return std::move(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4663,7 +4663,7 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
|
|||||||
case MessageContentType::Text: {
|
case MessageContentType::Text: {
|
||||||
auto result = make_unique<MessageText>(*static_cast<const MessageText *>(content));
|
auto result = make_unique<MessageText>(*static_cast<const MessageText *>(content));
|
||||||
if (type == MessageContentDupType::Copy || type == MessageContentDupType::ServerCopy) {
|
if (type == MessageContentDupType::Copy || type == MessageContentDupType::ServerCopy) {
|
||||||
remove_unallowed_entities(td->stickers_manager_.get(), result->text, to_secret);
|
remove_unallowed_entities(td, result->text, dialog_id);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "td/telegram/misc.h"
|
#include "td/telegram/misc.h"
|
||||||
#include "td/telegram/SecretChatLayer.h"
|
#include "td/telegram/SecretChatLayer.h"
|
||||||
#include "td/telegram/StickersManager.h"
|
#include "td/telegram/StickersManager.h"
|
||||||
|
#include "td/telegram/Td.h"
|
||||||
|
|
||||||
#include "td/utils/algorithm.h"
|
#include "td/utils/algorithm.h"
|
||||||
#include "td/utils/format.h"
|
#include "td/utils/format.h"
|
||||||
@ -211,20 +212,6 @@ td_api::object_ptr<td_api::formattedText> get_formatted_text_object(const Format
|
|||||||
text.text, get_text_entities_object(text.entities, skip_bot_commands, max_media_timestamp));
|
text.text, get_text_entities_object(text.entities, skip_bot_commands, max_media_timestamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove_unallowed_entities(const StickersManager *stickers_manager, FormattedText &text, bool to_secret) {
|
|
||||||
if (to_secret) {
|
|
||||||
td::remove_if(text.entities, [](const MessageEntity &entity) {
|
|
||||||
return entity.type == MessageEntity::Type::Spoiler || entity.type == MessageEntity::Type::CustomEmoji;
|
|
||||||
});
|
|
||||||
} else if (!G()->shared_config().get_option_boolean("is_premium")) {
|
|
||||||
// remove premium custom emoji
|
|
||||||
td::remove_if(text.entities, [stickers_manager](const MessageEntity &entity) {
|
|
||||||
return entity.type == MessageEntity::Type::CustomEmoji &&
|
|
||||||
stickers_manager->is_premium_custom_emoji(entity.document_id);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool is_word_character(uint32 code) {
|
static bool is_word_character(uint32 code) {
|
||||||
switch (get_unicode_simple_category(code)) {
|
switch (get_unicode_simple_category(code)) {
|
||||||
case UnicodeSimpleCategory::Letter:
|
case UnicodeSimpleCategory::Letter:
|
||||||
@ -4392,4 +4379,36 @@ vector<tl_object_ptr<telegram_api::MessageEntity>> get_input_message_entities(co
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void remove_unallowed_entities(const Td *td, FormattedText &text, DialogId dialog_id) {
|
||||||
|
if (text.entities.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dialog_id.get_type() == DialogType::SecretChat) {
|
||||||
|
auto layer = td->contacts_manager_->get_secret_chat_layer(dialog_id.get_secret_chat_id());
|
||||||
|
td::remove_if(text.entities, [layer](const MessageEntity &entity) {
|
||||||
|
if (layer < static_cast<int32>(SecretChatLayer::NewEntities) &&
|
||||||
|
(entity.type == MessageEntity::Type::Underline || entity.type == MessageEntity::Type::Strikethrough ||
|
||||||
|
entity.type == MessageEntity::Type::BlockQuote)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (entity.type == MessageEntity::Type::Spoiler || entity.type == MessageEntity::Type::CustomEmoji) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (layer < static_cast<int32>(SecretChatLayer::NewEntities)) {
|
||||||
|
sort_entities(text.entities);
|
||||||
|
remove_intersecting_entities(text.entities);
|
||||||
|
}
|
||||||
|
} else if (!G()->shared_config().get_option_boolean("is_premium")) {
|
||||||
|
// remove premium custom emoji
|
||||||
|
td::remove_if(text.entities, [td](const MessageEntity &entity) {
|
||||||
|
return entity.type == MessageEntity::Type::CustomEmoji &&
|
||||||
|
td->stickers_manager_->is_premium_custom_emoji(entity.document_id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -24,7 +24,7 @@ namespace td {
|
|||||||
|
|
||||||
class ContactsManager;
|
class ContactsManager;
|
||||||
class Dependencies;
|
class Dependencies;
|
||||||
class StickersManager;
|
class Td;
|
||||||
|
|
||||||
class MessageEntity {
|
class MessageEntity {
|
||||||
public:
|
public:
|
||||||
@ -151,7 +151,7 @@ vector<tl_object_ptr<td_api::textEntity>> get_text_entities_object(const vector<
|
|||||||
td_api::object_ptr<td_api::formattedText> get_formatted_text_object(const FormattedText &text, bool skip_bot_commands,
|
td_api::object_ptr<td_api::formattedText> get_formatted_text_object(const FormattedText &text, bool skip_bot_commands,
|
||||||
int32 max_media_timestamp);
|
int32 max_media_timestamp);
|
||||||
|
|
||||||
void remove_unallowed_entities(const StickersManager *stickers_manager, FormattedText &text, bool to_secret);
|
void remove_unallowed_entities(const Td *td, FormattedText &text, DialogId dialog_id);
|
||||||
|
|
||||||
vector<MessageEntity> find_entities(Slice text, bool skip_bot_commands, bool skip_media_timestamps);
|
vector<MessageEntity> find_entities(Slice text, bool skip_bot_commands, bool skip_media_timestamps);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user