From f4502fe9263de589445c2cd9a4834de7a5e5def7 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 23 Oct 2024 18:34:55 +0400 Subject: [PATCH] f Migrate GIF search emoji sections to TDLib. --- .../chat_helpers/stickers_emoji_pack.cpp | 20 ++++++++++++++++++- .../chat_helpers/stickers_emoji_pack.h | 9 +++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp b/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp index 8fdbb947746bef..34f3f4e83f7feb 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp @@ -156,7 +156,6 @@ void EmojiPack::remove(not_null view) { } } -#if 0 // mtp auto EmojiPack::stickerForEmoji(EmojiPtr emoji) -> Sticker { Expects(emoji != nullptr); @@ -165,6 +164,7 @@ auto EmojiPack::stickerForEmoji(EmojiPtr emoji) -> Sticker { return { i->second.get(), nullptr }; } if (!emoji->colored()) { + request(emoji); return {}; } const auto j = _map.find(emoji->original()); @@ -172,9 +172,27 @@ auto EmojiPack::stickerForEmoji(EmojiPtr emoji) -> Sticker { const auto index = emoji->variantIndex(emoji); return { j->second.get(), ColorReplacements(index) }; } + request(emoji->original()); return {}; } +void EmojiPack::request(EmojiPtr emoji) { + if (!_requested.emplace(emoji).second) { + return; + } + _session->sender().request(TLgetAnimatedEmoji( + tl_string(emoji->id()) + )).done([=](const TLanimatedEmoji &result) { + const auto &data = result.data(); + if (const auto &sticker = data.vsticker()) { + const auto document = _session->data().processDocument(*sticker); + _map.emplace(emoji, document); + _refreshed.fire({}); + } + }).send(); +} + +#if 0 // mtp auto EmojiPack::stickerForEmoji(const IsolatedEmoji &emoji) -> Sticker { Expects(!emoji.empty()); diff --git a/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.h b/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.h index ed92162ddff69f..45ae9e219eafa1 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.h @@ -82,8 +82,8 @@ class EmojiPack final { bool add(not_null view); void remove(not_null view); -#if 0 // mtp [[nodiscard]] Sticker stickerForEmoji(EmojiPtr emoji); +#if 0 // mtp [[nodiscard]] Sticker stickerForEmoji(const IsolatedEmoji &emoji); #endif [[nodiscard]] std::shared_ptr image(EmojiPtr emoji); @@ -100,10 +100,10 @@ class EmojiPack final { [[nodiscard]] int animationsVersion() const { return _animationsVersion; } +#endif [[nodiscard]] rpl::producer<> refreshed() const { return _refreshed.events(); } -#endif [[nodiscard]] std::unique_ptr effectPlayer( not_null document, @@ -160,10 +160,11 @@ class EmojiPack final { void refreshItems(const base::flat_set> &list); void refreshItems(const base::flat_set> &items); + void request(EmojiPtr emoji); + base::flat_set _requested; + const not_null _session; -#if 0 // mtp base::flat_map> _map; -#endif base::flat_map< IsolatedEmoji, base::flat_set>> _items;