Prepare for removing premium custom emoji if have no premium.
This commit is contained in:
parent
680cce2f6d
commit
97ab564e07
@ -66,7 +66,7 @@ unique_ptr<DraftMessage> get_draft_message(ContactsManager *contacts_manager,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<unique_ptr<DraftMessage>> get_draft_message(ContactsManager *contacts_manager, DialogId dialog_id,
|
Result<unique_ptr<DraftMessage>> get_draft_message(Td *td, DialogId dialog_id,
|
||||||
td_api::object_ptr<td_api::draftMessage> &&draft_message) {
|
td_api::object_ptr<td_api::draftMessage> &&draft_message) {
|
||||||
if (draft_message == nullptr) {
|
if (draft_message == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -85,7 +85,7 @@ Result<unique_ptr<DraftMessage>> get_draft_message(ContactsManager *contacts_man
|
|||||||
return Status::Error(400, "Input message content type must be InputMessageText");
|
return Status::Error(400, "Input message content type must be InputMessageText");
|
||||||
}
|
}
|
||||||
TRY_RESULT(message_content,
|
TRY_RESULT(message_content,
|
||||||
process_input_message_text(contacts_manager, dialog_id, std::move(input_message_content), false, true));
|
process_input_message_text(td, dialog_id, std::move(input_message_content), false, true));
|
||||||
result->input_message_text = std::move(message_content);
|
result->input_message_text = std::move(message_content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
class ContactsManager;
|
class ContactsManager;
|
||||||
|
class Td;
|
||||||
|
|
||||||
class DraftMessage {
|
class DraftMessage {
|
||||||
public:
|
public:
|
||||||
@ -31,7 +32,7 @@ td_api::object_ptr<td_api::draftMessage> get_draft_message_object(const unique_p
|
|||||||
unique_ptr<DraftMessage> get_draft_message(ContactsManager *contacts_manager,
|
unique_ptr<DraftMessage> get_draft_message(ContactsManager *contacts_manager,
|
||||||
telegram_api::object_ptr<telegram_api::DraftMessage> &&draft_message_ptr);
|
telegram_api::object_ptr<telegram_api::DraftMessage> &&draft_message_ptr);
|
||||||
|
|
||||||
Result<unique_ptr<DraftMessage>> get_draft_message(ContactsManager *contacts_manager, DialogId dialog_id,
|
Result<unique_ptr<DraftMessage>> get_draft_message(Td *td, DialogId dialog_id,
|
||||||
td_api::object_ptr<td_api::draftMessage> &&draft_message);
|
td_api::object_ptr<td_api::draftMessage> &&draft_message);
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -353,8 +353,7 @@ Result<tl_object_ptr<telegram_api::InputBotInlineMessage>> InlineQueriesManager:
|
|||||||
|
|
||||||
auto constructor_id = input_message_content->get_id();
|
auto constructor_id = input_message_content->get_id();
|
||||||
if (constructor_id == td_api::inputMessageText::ID) {
|
if (constructor_id == td_api::inputMessageText::ID) {
|
||||||
TRY_RESULT(input_message_text, process_input_message_text(td_->contacts_manager_.get(), DialogId(),
|
TRY_RESULT(input_message_text, process_input_message_text(td_, DialogId(), std::move(input_message_content), true));
|
||||||
std::move(input_message_content), true));
|
|
||||||
int32 flags = 0;
|
int32 flags = 0;
|
||||||
if (input_reply_markup != nullptr) {
|
if (input_reply_markup != nullptr) {
|
||||||
flags |= telegram_api::inputBotInlineMessageText::REPLY_MARKUP_MASK;
|
flags |= telegram_api::inputBotInlineMessageText::REPLY_MARKUP_MASK;
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "td/telegram/ConfigShared.h"
|
#include "td/telegram/ConfigShared.h"
|
||||||
#include "td/telegram/Global.h"
|
#include "td/telegram/Global.h"
|
||||||
#include "td/telegram/MessageEntity.h"
|
#include "td/telegram/MessageEntity.h"
|
||||||
|
#include "td/telegram/Td.h"
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
|
|
||||||
@ -23,7 +24,7 @@ bool operator!=(const InputMessageText &lhs, const InputMessageText &rhs) {
|
|||||||
return !(lhs == rhs);
|
return !(lhs == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<InputMessageText> process_input_message_text(const ContactsManager *contacts_manager, DialogId dialog_id,
|
Result<InputMessageText> process_input_message_text(const Td *td, DialogId dialog_id,
|
||||||
tl_object_ptr<td_api::InputMessageContent> &&input_message_content,
|
tl_object_ptr<td_api::InputMessageContent> &&input_message_content,
|
||||||
bool is_bot, bool for_draft) {
|
bool is_bot, bool for_draft) {
|
||||||
CHECK(input_message_content != nullptr);
|
CHECK(input_message_content != nullptr);
|
||||||
@ -38,8 +39,9 @@ Result<InputMessageText> process_input_message_text(const ContactsManager *conta
|
|||||||
return Status::Error(400, "Message text can't be empty");
|
return Status::Error(400, "Message text can't be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
TRY_RESULT(entities, get_message_entities(contacts_manager, std::move(input_message_text->text_->entities_)));
|
TRY_RESULT(entities,
|
||||||
auto need_skip_bot_commands = need_always_skip_bot_commands(contacts_manager, dialog_id, is_bot);
|
get_message_entities(td->contacts_manager_.get(), std::move(input_message_text->text_->entities_)));
|
||||||
|
auto need_skip_bot_commands = need_always_skip_bot_commands(td->contacts_manager_.get(), dialog_id, is_bot);
|
||||||
bool parse_markdown = G()->shared_config().get_option_boolean("always_parse_markdown");
|
bool parse_markdown = G()->shared_config().get_option_boolean("always_parse_markdown");
|
||||||
TRY_STATUS(fix_formatted_text(input_message_text->text_->text_, entities, for_draft, parse_markdown,
|
TRY_STATUS(fix_formatted_text(input_message_text->text_->text_, entities, for_draft, parse_markdown,
|
||||||
need_skip_bot_commands, is_bot || for_draft || parse_markdown, for_draft));
|
need_skip_bot_commands, is_bot || for_draft || parse_markdown, for_draft));
|
||||||
@ -51,7 +53,7 @@ Result<InputMessageText> process_input_message_text(const ContactsManager *conta
|
|||||||
is_bot || for_draft, for_draft)
|
is_bot || for_draft, for_draft)
|
||||||
.ensure();
|
.ensure();
|
||||||
}
|
}
|
||||||
remove_unallowed_entities(result.text, dialog_id.get_type() == DialogType::SecretChat);
|
remove_unallowed_entities(td->stickers_manager_.get(), result.text, dialog_id.get_type() == DialogType::SecretChat);
|
||||||
return std::move(result);
|
return std::move(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
class ContactsManager;
|
class Td;
|
||||||
|
|
||||||
class InputMessageText {
|
class InputMessageText {
|
||||||
public:
|
public:
|
||||||
@ -30,7 +30,7 @@ class InputMessageText {
|
|||||||
bool operator==(const InputMessageText &lhs, const InputMessageText &rhs);
|
bool operator==(const InputMessageText &lhs, const InputMessageText &rhs);
|
||||||
bool operator!=(const InputMessageText &lhs, const InputMessageText &rhs);
|
bool operator!=(const InputMessageText &lhs, const InputMessageText &rhs);
|
||||||
|
|
||||||
Result<InputMessageText> process_input_message_text(const ContactsManager *contacts_manager, DialogId dialog_id,
|
Result<InputMessageText> process_input_message_text(const Td *td, DialogId dialog_id,
|
||||||
tl_object_ptr<td_api::InputMessageContent> &&input_message_content,
|
tl_object_ptr<td_api::InputMessageContent> &&input_message_content,
|
||||||
bool is_bot, bool for_draft = false) TD_WARN_UNUSED_RESULT;
|
bool is_bot, bool for_draft = false) TD_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
|
@ -1761,8 +1761,8 @@ static Result<InputMessageContent> create_input_message_content(
|
|||||||
bool is_bot = td->auth_manager_->is_bot();
|
bool is_bot = td->auth_manager_->is_bot();
|
||||||
switch (input_message_content->get_id()) {
|
switch (input_message_content->get_id()) {
|
||||||
case td_api::inputMessageText::ID: {
|
case td_api::inputMessageText::ID: {
|
||||||
TRY_RESULT(input_message_text, process_input_message_text(td->contacts_manager_.get(), dialog_id,
|
TRY_RESULT(input_message_text,
|
||||||
std::move(input_message_content), is_bot));
|
process_input_message_text(td, dialog_id, std::move(input_message_content), is_bot));
|
||||||
disable_web_page_preview = input_message_text.disable_web_page_preview;
|
disable_web_page_preview = input_message_text.disable_web_page_preview;
|
||||||
clear_draft = input_message_text.clear_draft;
|
clear_draft = input_message_text.clear_draft;
|
||||||
|
|
||||||
@ -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(result->text, to_secret);
|
remove_unallowed_entities(td->stickers_manager_.get(), result->text, to_secret);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,13 @@
|
|||||||
//
|
//
|
||||||
#include "td/telegram/MessageEntity.h"
|
#include "td/telegram/MessageEntity.h"
|
||||||
|
|
||||||
|
#include "td/telegram/ConfigShared.h"
|
||||||
#include "td/telegram/ContactsManager.h"
|
#include "td/telegram/ContactsManager.h"
|
||||||
#include "td/telegram/Dependencies.h"
|
#include "td/telegram/Dependencies.h"
|
||||||
#include "td/telegram/LinkManager.h"
|
#include "td/telegram/LinkManager.h"
|
||||||
#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/utils/algorithm.h"
|
#include "td/utils/algorithm.h"
|
||||||
#include "td/utils/format.h"
|
#include "td/utils/format.h"
|
||||||
@ -209,11 +211,17 @@ 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(FormattedText &text, bool to_secret) {
|
void remove_unallowed_entities(const StickersManager *stickers_manager, FormattedText &text, bool to_secret) {
|
||||||
if (to_secret) {
|
if (to_secret) {
|
||||||
td::remove_if(text.entities, [](const MessageEntity &entity) {
|
td::remove_if(text.entities, [](const MessageEntity &entity) {
|
||||||
return entity.type == MessageEntity::Type::Spoiler || entity.type == MessageEntity::Type::CustomEmoji;
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ namespace td {
|
|||||||
|
|
||||||
class ContactsManager;
|
class ContactsManager;
|
||||||
class Dependencies;
|
class Dependencies;
|
||||||
|
class StickersManager;
|
||||||
|
|
||||||
class MessageEntity {
|
class MessageEntity {
|
||||||
public:
|
public:
|
||||||
@ -150,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(FormattedText &text, bool to_secret);
|
void remove_unallowed_entities(const StickersManager *stickers_manager, FormattedText &text, bool to_secret);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
@ -19748,7 +19748,7 @@ Status MessagesManager::set_dialog_draft_message(DialogId dialog_id, MessageId t
|
|||||||
}
|
}
|
||||||
TRY_STATUS(can_send_message(dialog_id));
|
TRY_STATUS(can_send_message(dialog_id));
|
||||||
|
|
||||||
TRY_RESULT(new_draft_message, get_draft_message(td_->contacts_manager_.get(), dialog_id, std::move(draft_message)));
|
TRY_RESULT(new_draft_message, get_draft_message(td_, dialog_id, std::move(draft_message)));
|
||||||
if (new_draft_message != nullptr) {
|
if (new_draft_message != nullptr) {
|
||||||
new_draft_message->reply_to_message_id =
|
new_draft_message->reply_to_message_id =
|
||||||
get_reply_to_message_id(d, top_thread_message_id, new_draft_message->reply_to_message_id, true);
|
get_reply_to_message_id(d, top_thread_message_id, new_draft_message->reply_to_message_id, true);
|
||||||
@ -26906,8 +26906,8 @@ void MessagesManager::edit_message_text(FullMessageId full_message_id,
|
|||||||
return promise.set_error(Status::Error(400, "There is no text in the message to edit"));
|
return promise.set_error(Status::Error(400, "There is no text in the message to edit"));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto r_input_message_text = process_input_message_text(
|
auto r_input_message_text =
|
||||||
td_->contacts_manager_.get(), dialog_id, std::move(input_message_content), td_->auth_manager_->is_bot());
|
process_input_message_text(td_, dialog_id, std::move(input_message_content), td_->auth_manager_->is_bot());
|
||||||
if (r_input_message_text.is_error()) {
|
if (r_input_message_text.is_error()) {
|
||||||
return promise.set_error(r_input_message_text.move_as_error());
|
return promise.set_error(r_input_message_text.move_as_error());
|
||||||
}
|
}
|
||||||
@ -27272,8 +27272,8 @@ void MessagesManager::edit_inline_message_text(const string &inline_message_id,
|
|||||||
return promise.set_error(Status::Error(400, "Input message content type must be InputMessageText"));
|
return promise.set_error(Status::Error(400, "Input message content type must be InputMessageText"));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto r_input_message_text = process_input_message_text(
|
auto r_input_message_text =
|
||||||
td_->contacts_manager_.get(), DialogId(), std::move(input_message_content), td_->auth_manager_->is_bot());
|
process_input_message_text(td_, DialogId(), std::move(input_message_content), td_->auth_manager_->is_bot());
|
||||||
if (r_input_message_text.is_error()) {
|
if (r_input_message_text.is_error()) {
|
||||||
return promise.set_error(r_input_message_text.move_as_error());
|
return promise.set_error(r_input_message_text.move_as_error());
|
||||||
}
|
}
|
||||||
|
@ -1692,6 +1692,11 @@ StickerType StickersManager::get_sticker_type(FileId file_id) const {
|
|||||||
return sticker->type;
|
return sticker->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool StickersManager::is_premium_custom_emoji(int64 custom_emoji_id) const {
|
||||||
|
// TODO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
vector<td_api::object_ptr<td_api::closedVectorPath>> StickersManager::get_sticker_minithumbnail(
|
vector<td_api::object_ptr<td_api::closedVectorPath>> StickersManager::get_sticker_minithumbnail(
|
||||||
CSlice path, StickerSetId sticker_set_id, int64 document_id, double zoom) {
|
CSlice path, StickerSetId sticker_set_id, int64 document_id, double zoom) {
|
||||||
if (path.empty()) {
|
if (path.empty()) {
|
||||||
|
@ -61,6 +61,8 @@ class StickersManager final : public Actor {
|
|||||||
|
|
||||||
StickerType get_sticker_type(FileId file_id) const;
|
StickerType get_sticker_type(FileId file_id) const;
|
||||||
|
|
||||||
|
bool is_premium_custom_emoji(int64 custom_emoji_id) const;
|
||||||
|
|
||||||
tl_object_ptr<td_api::sticker> get_sticker_object(FileId file_id, bool for_animated_emoji = false,
|
tl_object_ptr<td_api::sticker> get_sticker_object(FileId file_id, bool for_animated_emoji = false,
|
||||||
bool for_clicked_animated_emoji = false) const;
|
bool for_clicked_animated_emoji = false) const;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user