Disallow emoji stickers in secret chats.

This commit is contained in:
levlam 2022-07-22 16:11:33 +03:00
parent 813867eb66
commit 03773d01fd
3 changed files with 17 additions and 2 deletions

View File

@ -2715,8 +2715,7 @@ Status can_send_message_content(DialogId dialog_id, const MessageContent *conten
if (!permissions.can_send_stickers()) { if (!permissions.can_send_stickers()) {
return Status::Error(400, "Not enough rights to send stickers to the chat"); return Status::Error(400, "Not enough rights to send stickers to the chat");
} }
if (td->stickers_manager_->get_sticker_type(static_cast<const MessageSticker *>(content)->file_id) == if (get_message_content_sticker_type(td, content) == StickerType::CustomEmoji) {
StickerType::CustomEmoji) {
return Status::Error(400, "Can't send emoji stickers in messages"); return Status::Error(400, "Can't send emoji stickers in messages");
} }
break; break;
@ -2927,6 +2926,11 @@ int32 get_message_content_index_mask(const MessageContent *content, const Td *td
return get_message_content_text_index_mask(content) | get_message_content_media_index_mask(content, td, is_outgoing); return get_message_content_text_index_mask(content) | get_message_content_media_index_mask(content, td, is_outgoing);
} }
StickerType get_message_content_sticker_type(const Td *td, const MessageContent *content) {
CHECK(content->get_type() == MessageContentType::Sticker);
return td->stickers_manager_->get_sticker_type(static_cast<const MessageSticker *>(content)->file_id);
}
MessageId get_message_content_pinned_message_id(const MessageContent *content) { MessageId get_message_content_pinned_message_id(const MessageContent *content) {
switch (content->get_type()) { switch (content->get_type()) {
case MessageContentType::PinMessage: case MessageContentType::PinMessage:

View File

@ -20,6 +20,7 @@
#include "td/telegram/ReplyMarkup.h" #include "td/telegram/ReplyMarkup.h"
#include "td/telegram/secret_api.h" #include "td/telegram/secret_api.h"
#include "td/telegram/SecretInputMedia.h" #include "td/telegram/SecretInputMedia.h"
#include "td/telegram/StickerType.h"
#include "td/telegram/td_api.h" #include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h" #include "td/telegram/telegram_api.h"
#include "td/telegram/TopDialogCategory.h" #include "td/telegram/TopDialogCategory.h"
@ -131,6 +132,8 @@ bool update_opened_message_content(MessageContent *content);
int32 get_message_content_index_mask(const MessageContent *content, const Td *td, bool is_outgoing); int32 get_message_content_index_mask(const MessageContent *content, const Td *td, bool is_outgoing);
StickerType get_message_content_sticker_type(const Td *td, const MessageContent *content);
MessageId get_message_content_pinned_message_id(const MessageContent *content); MessageId get_message_content_pinned_message_id(const MessageContent *content);
string get_message_content_theme_name(const MessageContent *content); string get_message_content_theme_name(const MessageContent *content);

View File

@ -56,6 +56,7 @@
#include "td/telegram/ReplyMarkup.hpp" #include "td/telegram/ReplyMarkup.hpp"
#include "td/telegram/SecretChatsManager.h" #include "td/telegram/SecretChatsManager.h"
#include "td/telegram/SponsoredMessageManager.h" #include "td/telegram/SponsoredMessageManager.h"
#include "td/telegram/StickerType.h"
#include "td/telegram/Td.h" #include "td/telegram/Td.h"
#include "td/telegram/TdDb.h" #include "td/telegram/TdDb.h"
#include "td/telegram/TdParameters.h" #include "td/telegram/TdParameters.h"
@ -14378,6 +14379,13 @@ std::pair<DialogId, unique_ptr<MessagesManager::Message>> MessagesManager::creat
} }
auto content_type = message_info.content->get_type(); auto content_type = message_info.content->get_type();
if (content_type == MessageContentType::Sticker &&
get_message_content_sticker_type(td_, message_info.content.get()) == StickerType::CustomEmoji) {
LOG(INFO) << "Replace emoji sticker with an empty message";
message_info.content = create_text_message_content("Invalid sticker", {}, WebPageId());
content_type = message_info.content->get_type();
}
if (hide_edit_date && td_->auth_manager_->is_bot()) { if (hide_edit_date && td_->auth_manager_->is_bot()) {
hide_edit_date = false; hide_edit_date = false;
} }