From fec80c0c642bf324bfda07a05e015702315184b7 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 7 Feb 2023 20:43:50 +0400 Subject: [PATCH] Support text-color-ed emoji in userpic editor. --- Telegram/SourceFiles/api/api_peer_photo.cpp | 7 +++- .../data/stickers/data_custom_emoji.cpp | 32 ++----------------- .../data/stickers/data_custom_emoji.h | 4 --- .../info_userpic_emoji_builder_preview.cpp | 6 ++-- .../SourceFiles/settings/settings_premium.cpp | 22 +------------ 5 files changed, 11 insertions(+), 60 deletions(-) diff --git a/Telegram/SourceFiles/api/api_peer_photo.cpp b/Telegram/SourceFiles/api/api_peer_photo.cpp index 65d9207a5..86b08e058 100644 --- a/Telegram/SourceFiles/api/api_peer_photo.cpp +++ b/Telegram/SourceFiles/api/api_peer_photo.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "base/random.h" #include "base/unixtime.h" +#include "data/stickers/data_stickers.h" #include "data/data_channel.h" #include "data/data_chat.h" #include "data/data_document.h" @@ -125,7 +126,11 @@ constexpr auto kSharedMediaLimit = 100; colors, ranges::back_inserter(mtpColors), [&](const QColor &c) { return MTP_int(serializeColor(c)); }); - if (sticker->set.id && sticker->set.accessHash) { + if (sticker->setType == Data::StickersType::Emoji) { + return MTP_videoSizeEmojiMarkup( + MTP_long(document->id), + MTP_vector(mtpColors)); + } else if (sticker->set.id && sticker->set.accessHash) { return MTP_videoSizeStickerMarkup( MTP_inputStickerSetID( MTP_long(sticker->set.id), diff --git a/Telegram/SourceFiles/data/stickers/data_custom_emoji.cpp b/Telegram/SourceFiles/data/stickers/data_custom_emoji.cpp index 447e6f057..04565a741 100644 --- a/Telegram/SourceFiles/data/stickers/data_custom_emoji.cpp +++ b/Telegram/SourceFiles/data/stickers/data_custom_emoji.cpp @@ -425,10 +425,6 @@ CustomEmojiManager::CustomEmojiManager(not_null owner) QString()).toULongLong(); if (setId) { _coloredSetId = setId; - auto pending = base::take(_coloredSetPending); - for (const auto &instance : pending[setId]) { - instance->setColored(); - } } }, _lifetime); } @@ -460,12 +456,6 @@ std::unique_ptr CustomEmojiManager::create( }, std::move(repaint))).first; if (colored) { i->second->setColored(); - } else if (_coloredSetId) { - if (_coloredSetId == setId) { - i->second->setColored(); - } - } else if (setId) { - _coloredSetPending[setId].emplace(i->second.get()); } } else if (!i->second->hasImagePreview()) { auto preview = prepareNonExactPreview(documentId, tag, sizeOverride); @@ -693,32 +683,14 @@ void CustomEmojiManager::request() { } void CustomEmojiManager::fillColoredFlags(not_null document) { - const auto id = document->id; - const auto setColored = [&] { + if (document->emojiUsesTextColor()) { + const auto id = document->id; for (auto &instances : _instances) { const auto i = instances.find(id); if (i != end(instances)) { i->second->setColored(); } } - }; - if (document->emojiUsesTextColor()) { - setColored(); - return; - } - const auto sticker = document->sticker(); - const auto setId = sticker ? sticker->set.id : uint64(); - if (!setId || (_coloredSetId && setId != _coloredSetId)) { - return; - } else if (setId == _coloredSetId) { - setColored(); - } else { - for (auto &instances : _instances) { - const auto i = instances.find(id); - if (i != end(instances)) { - _coloredSetPending[setId].emplace(i->second.get()); - } - } } } diff --git a/Telegram/SourceFiles/data/stickers/data_custom_emoji.h b/Telegram/SourceFiles/data/stickers/data_custom_emoji.h index be63ce549..4c79f8870 100644 --- a/Telegram/SourceFiles/data/stickers/data_custom_emoji.h +++ b/Telegram/SourceFiles/data/stickers/data_custom_emoji.h @@ -152,10 +152,6 @@ private: not_null, base::flat_set> _listeners; base::flat_set _pendingForRequest; - base::flat_map< - uint64, - base::flat_set< - not_null>> _coloredSetPending; mtpRequestId _requestId = 0; diff --git a/Telegram/SourceFiles/info/userpic/info_userpic_emoji_builder_preview.cpp b/Telegram/SourceFiles/info/userpic/info_userpic_emoji_builder_preview.cpp index 01f026ecf..c7997381c 100644 --- a/Telegram/SourceFiles/info/userpic/info_userpic_emoji_builder_preview.cpp +++ b/Telegram/SourceFiles/info/userpic/info_userpic_emoji_builder_preview.cpp @@ -118,12 +118,10 @@ void PreviewPainter::paintBackground(QPainter &p, const QImage &image) { bool PreviewPainter::paintForeground(QPainter &p) { if (_player && _player->ready()) { - // resolveIsColored(); + const auto c = _media->owner()->emojiUsesTextColor() ? 255 : 0; auto frame = _player->frame( Size(_emojiSize), - (/*_isColored - ? st::profileVerifiedCheckBg->c - : */QColor(0, 0, 0, 0)), + QColor(c, c, c, c), false, crl::now(), _paused); diff --git a/Telegram/SourceFiles/settings/settings_premium.cpp b/Telegram/SourceFiles/settings/settings_premium.cpp index 8f7eca2ec..b9c7f78ad 100644 --- a/Telegram/SourceFiles/settings/settings_premium.cpp +++ b/Telegram/SourceFiles/settings/settings_premium.cpp @@ -489,14 +489,10 @@ public: void paint(QPainter &p); private: - void resolveIsColored(); - QRectF _rect; std::shared_ptr _media; std::unique_ptr _player; bool _paused = false; - bool _isColored = false; - bool _isColoredResolved = false; rpl::lifetime _lifetime; }; @@ -555,27 +551,11 @@ void EmojiStatusTopBar::setPaused(bool paused) { _paused = paused; } -void EmojiStatusTopBar::resolveIsColored() { - if (_isColoredResolved) { - return; - } - const auto document = _media->owner(); - const auto manager = &document->owner().customEmojiManager(); - const auto coloredSetId = manager->coloredSetId(); - if (!coloredSetId) { - return; - } - _isColoredResolved = true; - const auto sticker = document->sticker(); - _isColored = sticker && (sticker->set.id == coloredSetId); -} - void EmojiStatusTopBar::paint(QPainter &p) { if (_player && _player->ready()) { - resolveIsColored(); const auto frame = _player->frame( _rect.size().toSize(), - (_isColored + (_media->owner()->emojiUsesTextColor() ? st::profileVerifiedCheckBg->c : QColor(0, 0, 0, 0)), false,