Support text-color-ed emoji in userpic editor.

This commit is contained in:
John Preston 2023-02-07 20:43:50 +04:00
parent ed9ba07a32
commit fec80c0c64
5 changed files with 11 additions and 60 deletions

View file

@ -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),

View file

@ -425,10 +425,6 @@ CustomEmojiManager::CustomEmojiManager(not_null<Session*> 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<Ui::Text::CustomEmoji> 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<DocumentData*> 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());
}
}
}
}

View file

@ -152,10 +152,6 @@ private:
not_null<Listener*>,
base::flat_set<DocumentId>> _listeners;
base::flat_set<DocumentId> _pendingForRequest;
base::flat_map<
uint64,
base::flat_set<
not_null<Ui::CustomEmoji::Instance*>>> _coloredSetPending;
mtpRequestId _requestId = 0;

View file

@ -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);

View file

@ -489,14 +489,10 @@ public:
void paint(QPainter &p);
private:
void resolveIsColored();
QRectF _rect;
std::shared_ptr<Data::DocumentMedia> _media;
std::unique_ptr<HistoryView::StickerPlayer> _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,