Return messageAnimatedEmoji for single custom emoji.

This commit is contained in:
levlam 2022-08-05 17:58:16 +03:00
parent edaff2eba5
commit 3c863517ba
4 changed files with 54 additions and 14 deletions

View File

@ -329,7 +329,7 @@ videoNote duration:int32 length:int32 minithumbnail:minithumbnail thumbnail:thum
voiceNote duration:int32 waveform:bytes mime_type:string speech_recognition_result:SpeechRecognitionResult voice:file = VoiceNote;
//@description Describes an animated representation of an emoji
//@sticker Animated sticker for the emoji
//@sticker Animated sticker for the emoji; may be null if yet unknown for a custom emoji
//@fitzpatrick_type Emoji modifier fitzpatrick type; 0-6; 0 if none
//@sound File containing the sound to be played when the animated emoji is clicked; may be null. The sound is encoded with the Opus codec, and stored inside an OGG container
animatedEmoji sticker:sticker fitzpatrick_type:int32 sound:file = AnimatedEmoji;

View File

@ -3797,7 +3797,22 @@ bool merge_message_content_file_id(Td *td, MessageContent *message_content, File
}
static bool can_be_animated_emoji(const FormattedText &text) {
return text.entities.empty() && is_emoji(text.text);
if (!is_emoji(text.text)) {
return false;
}
if (text.entities.empty()) {
return true;
}
if (text.entities.size() == 1 && text.entities[0].type == MessageEntity::Type::CustomEmoji &&
text.entities[0].offset == 0 && static_cast<size_t>(text.entities[0].length) == utf8_utf16_length(text.text) &&
text.entities[0].document_id != 0) {
return true;
}
return false;
}
static int64 get_custom_emoji_id(const FormattedText &text) {
return text.entities.empty() ? 0 : text.entities[0].document_id;
}
void register_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id,
@ -3808,7 +3823,8 @@ void register_message_content(Td *td, const MessageContent *content, FullMessage
if (text->web_page_id.is_valid()) {
td->web_pages_manager_->register_web_page(text->web_page_id, full_message_id, source);
} else if (can_be_animated_emoji(text->text)) {
td->stickers_manager_->register_emoji(text->text.text, full_message_id, source);
td->stickers_manager_->register_emoji(text->text.text, get_custom_emoji_id(text->text), full_message_id,
source);
}
return;
}
@ -3888,7 +3904,8 @@ void unregister_message_content(Td *td, const MessageContent *content, FullMessa
if (text->web_page_id.is_valid()) {
td->web_pages_manager_->unregister_web_page(text->web_page_id, full_message_id, source);
} else if (can_be_animated_emoji(text->text)) {
td->stickers_manager_->unregister_emoji(text->text.text, full_message_id, source);
td->stickers_manager_->unregister_emoji(text->text.text, get_custom_emoji_id(text->text), full_message_id,
source);
}
return;
}
@ -5112,7 +5129,8 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
case MessageContentType::Text: {
const auto *m = static_cast<const MessageText *>(content);
if (can_be_animated_emoji(m->text) && !m->web_page_id.is_valid()) {
auto animated_emoji = td->stickers_manager_->get_animated_emoji_object(m->text.text);
auto animated_emoji =
td->stickers_manager_->get_animated_emoji_object(m->text.text, get_custom_emoji_id(m->text));
if (animated_emoji != nullptr) {
return td_api::make_object<td_api::messageAnimatedEmoji>(std::move(animated_emoji), m->text.text);
}

View File

@ -1992,8 +1992,12 @@ tl_object_ptr<td_api::sticker> StickersManager::get_sticker_object(FileId file_i
int32 width = sticker->dimensions.width;
int32 height = sticker->dimensions.height;
double zoom = 1.0;
if (is_sticker_format_vector(sticker->format) && (for_animated_emoji || for_clicked_animated_emoji)) {
if ((is_sticker_format_vector(sticker->format) || sticker->type == StickerType::CustomEmoji) &&
(for_animated_emoji || for_clicked_animated_emoji)) {
zoom = for_clicked_animated_emoji ? 3 * animated_emoji_zoom_ : animated_emoji_zoom_;
if (sticker->type == StickerType::CustomEmoji) {
zoom *= 5.12;
}
width = static_cast<int32>(width * zoom + 0.5);
height = static_cast<int32>(height * zoom + 0.5);
}
@ -2378,7 +2382,13 @@ FileId StickersManager::get_animated_emoji_sound_file_id(const string &emoji) co
return it->second;
}
td_api::object_ptr<td_api::animatedEmoji> StickersManager::get_animated_emoji_object(const string &emoji) {
td_api::object_ptr<td_api::animatedEmoji> StickersManager::get_animated_emoji_object(const string &emoji,
int64 custom_emoji_id) {
if (custom_emoji_id != 0) {
auto sticker_id = custom_emoji_to_sticker_id_.get(custom_emoji_id);
return td_api::make_object<td_api::animatedEmoji>(get_sticker_object(sticker_id, true), 0, nullptr);
}
auto it = emoji_messages_.find(emoji);
if (it == emoji_messages_.end()) {
return get_animated_emoji_object(get_animated_emoji_sticker(emoji), get_animated_emoji_sound_file_id(emoji));
@ -5039,13 +5049,19 @@ void StickersManager::unregister_dice(const string &emoji, int32 value, FullMess
}
}
void StickersManager::register_emoji(const string &emoji, FullMessageId full_message_id, const char *source) {
void StickersManager::register_emoji(const string &emoji, int64 custom_emoji_id, FullMessageId full_message_id,
const char *source) {
CHECK(!emoji.empty());
if (td_->auth_manager_->is_bot()) {
return;
}
LOG(INFO) << "Register emoji " << emoji << " from " << full_message_id << " from " << source;
LOG(INFO) << "Register emoji " << emoji << " with custom emoji " << custom_emoji_id << " from " << full_message_id
<< " from " << source;
if (custom_emoji_id != 0) {
return;
}
auto &emoji_messages_ptr = emoji_messages_[emoji];
if (emoji_messages_ptr == nullptr) {
emoji_messages_ptr = make_unique<EmojiMessages>();
@ -5059,13 +5075,19 @@ void StickersManager::register_emoji(const string &emoji, FullMessageId full_mes
LOG_CHECK(is_inserted) << source << ' ' << emoji << ' ' << full_message_id;
}
void StickersManager::unregister_emoji(const string &emoji, FullMessageId full_message_id, const char *source) {
void StickersManager::unregister_emoji(const string &emoji, int64 custom_emoji_id, FullMessageId full_message_id,
const char *source) {
CHECK(!emoji.empty());
if (td_->auth_manager_->is_bot()) {
return;
}
LOG(INFO) << "Unregister emoji " << emoji << " from " << full_message_id << " from " << source;
LOG(INFO) << "Unregister emoji " << emoji << " with custom emoji " << custom_emoji_id << " from " << full_message_id
<< " from " << source;
if (custom_emoji_id != 0) {
return;
}
auto it = emoji_messages_.find(emoji);
CHECK(it != emoji_messages_.end());
auto &full_message_ids = it->second->full_message_ids;

View File

@ -81,7 +81,7 @@ class StickersManager final : public Actor {
td_api::object_ptr<td_api::sticker> get_premium_gift_sticker_object(int32 month_count);
td_api::object_ptr<td_api::animatedEmoji> get_animated_emoji_object(const string &emoji);
td_api::object_ptr<td_api::animatedEmoji> get_animated_emoji_object(const string &emoji, int64 custom_emoji_id);
tl_object_ptr<telegram_api::InputStickerSet> get_input_sticker_set(StickerSetId sticker_set_id) const;
@ -93,9 +93,9 @@ class StickersManager final : public Actor {
void unregister_dice(const string &emoji, int32 value, FullMessageId full_message_id, const char *source);
void register_emoji(const string &emoji, FullMessageId full_message_id, const char *source);
void register_emoji(const string &emoji, int64 custom_emoji_id, FullMessageId full_message_id, const char *source);
void unregister_emoji(const string &emoji, FullMessageId full_message_id, const char *source);
void unregister_emoji(const string &emoji, int64 custom_emoji_id, FullMessageId full_message_id, const char *source);
void get_animated_emoji(string emoji, bool is_recursive,
Promise<td_api::object_ptr<td_api::animatedEmoji>> &&promise);