Insert recent stickers as emoji for testing.

This commit is contained in:
John Preston 2022-06-28 17:47:28 +04:00
parent c796dd142b
commit 8ed101cbbf
1 changed files with 28 additions and 11 deletions

View File

@ -13,7 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_document.h"
#include "data/data_document_media.h"
#include "data/data_file_origin.h"
#include "data/stickers/data_stickers_set.h"
#include "lottie/lottie_common.h"
#include "lottie/lottie_emoji.h"
#include "chat_helpers/stickers_lottie.h"
@ -21,6 +20,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/ui_utility.h"
#include "apiwrap.h"
#include "data/stickers/data_stickers.h"
#include "data/stickers/data_stickers_set.h"
namespace Data {
struct CustomEmojiId {
@ -537,25 +539,40 @@ Session &CustomEmojiManager::owner() const {
void FillTestCustomEmoji(
not_null<Main::Session*> session,
TextWithEntities &text) {
auto &sets = session->data().stickers().sets();
auto recentIt = sets.find(Data::Stickers::CloudRecentSetId);
const auto pack = &session->emojiStickersPack();
const auto begin = text.text.constData(), end = begin + text.text.size();
for (auto ch = begin; ch != end;) {
auto length = 0;
if (const auto emoji = Ui::Emoji::Find(ch, end, &length)) {
auto replace = (DocumentData*)nullptr;
if (recentIt != sets.end()) {
for (const auto document : recentIt->second->stickers) {
if (const auto sticker = document->sticker()) {
if (Ui::Emoji::Find(sticker->alt) == emoji) {
replace = document;
}
}
}
}
if (const auto found = pack->stickerForEmoji(emoji)) {
Assert(found.document->sticker() != nullptr);
if (found.document->sticker()->set.id) {
text.entities.push_back({
EntityType::CustomEmoji,
(ch - begin),
length,
SerializeCustomEmojiId({
found.document->sticker()->set,
found.document->id,
}),
});
if (!replace && found.document->sticker()->set.id) {
replace = found.document;
}
}
if (replace) {
text.entities.push_back({
EntityType::CustomEmoji,
(ch - begin),
length,
SerializeCustomEmojiId({
replace->sticker()->set,
replace->id,
}),
});
}
ch += length;
} else if (ch->isHighSurrogate()
&& (ch + 1 != end)