2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-01-01 01:35:39 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
2018-07-03 21:29:04 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/StickersManager.h"
|
|
|
|
|
|
|
|
#include "td/telegram/files/FileId.hpp"
|
|
|
|
#include "td/telegram/misc.h"
|
2022-04-10 00:15:49 +02:00
|
|
|
#include "td/telegram/PhotoSize.hpp"
|
2022-01-18 17:20:43 +01:00
|
|
|
#include "td/telegram/StickerFormat.h"
|
2022-01-24 14:43:38 +01:00
|
|
|
#include "td/telegram/StickersManager.h"
|
|
|
|
#include "td/telegram/Td.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-09-21 05:32:34 +02:00
|
|
|
#include "td/utils/emoji.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/logging.h"
|
|
|
|
#include "td/utils/misc.h"
|
2018-08-10 20:54:17 +02:00
|
|
|
#include "td/utils/Slice.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/tl_helpers.h"
|
2021-06-17 22:29:13 +02:00
|
|
|
#include "td/utils/utf8.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class StorerT>
|
2021-09-13 15:03:21 +02:00
|
|
|
void StickersManager::store_sticker(FileId file_id, bool in_sticker_set, StorerT &storer, const char *source) const {
|
2022-08-03 21:42:52 +02:00
|
|
|
const Sticker *sticker = get_sticker(file_id);
|
|
|
|
LOG_CHECK(sticker != nullptr) << file_id << ' ' << in_sticker_set << ' ' << source;
|
2022-08-07 18:47:50 +02:00
|
|
|
bool has_sticker_set_access_hash = sticker->set_id_.is_valid() && !in_sticker_set;
|
|
|
|
bool has_minithumbnail = !sticker->minithumbnail_.empty();
|
|
|
|
bool is_tgs = sticker->format_ == StickerFormat::Tgs;
|
|
|
|
bool is_webm = sticker->format_ == StickerFormat::Webm;
|
|
|
|
bool has_premium_animation = sticker->premium_animation_file_id_.is_valid();
|
|
|
|
bool is_mask = sticker->type_ == StickerType::Mask;
|
|
|
|
bool is_emoji = sticker->type_ == StickerType::CustomEmoji;
|
|
|
|
bool has_emoji_receive_date = is_emoji && sticker->emoji_receive_date_ != 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
BEGIN_STORE_FLAGS();
|
2022-07-14 14:02:55 +02:00
|
|
|
STORE_FLAG(is_mask);
|
2018-12-31 20:04:05 +01:00
|
|
|
STORE_FLAG(has_sticker_set_access_hash);
|
|
|
|
STORE_FLAG(in_sticker_set);
|
2022-01-18 17:20:43 +01:00
|
|
|
STORE_FLAG(is_tgs);
|
2020-11-09 21:41:23 +01:00
|
|
|
STORE_FLAG(has_minithumbnail);
|
2022-01-25 12:58:04 +01:00
|
|
|
STORE_FLAG(is_webm);
|
2022-04-26 15:01:29 +02:00
|
|
|
STORE_FLAG(has_premium_animation);
|
2022-07-14 15:42:27 +02:00
|
|
|
STORE_FLAG(is_emoji);
|
2022-08-07 18:47:50 +02:00
|
|
|
STORE_FLAG(sticker->is_premium_);
|
2022-07-25 20:18:43 +02:00
|
|
|
STORE_FLAG(has_emoji_receive_date);
|
2018-12-31 20:04:05 +01:00
|
|
|
END_STORE_FLAGS();
|
|
|
|
if (!in_sticker_set) {
|
2022-08-07 18:47:50 +02:00
|
|
|
store(sticker->set_id_.get(), storer);
|
2018-12-31 20:04:05 +01:00
|
|
|
if (has_sticker_set_access_hash) {
|
2022-08-07 18:47:50 +02:00
|
|
|
auto sticker_set = get_sticker_set(sticker->set_id_);
|
2018-12-31 20:04:05 +01:00
|
|
|
CHECK(sticker_set != nullptr);
|
2022-08-07 18:47:50 +02:00
|
|
|
store(sticker_set->access_hash_, storer);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
2022-08-07 18:47:50 +02:00
|
|
|
store(sticker->alt_, storer);
|
|
|
|
store(sticker->dimensions_, storer);
|
|
|
|
store(sticker->s_thumbnail_, storer);
|
|
|
|
store(sticker->m_thumbnail_, storer);
|
2018-03-08 20:43:12 +01:00
|
|
|
store(file_id, storer);
|
2022-07-14 14:02:55 +02:00
|
|
|
if (is_mask) {
|
2022-08-07 18:47:50 +02:00
|
|
|
store(sticker->point_, storer);
|
|
|
|
store(sticker->x_shift_, storer);
|
|
|
|
store(sticker->y_shift_, storer);
|
|
|
|
store(sticker->scale_, storer);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2020-11-09 21:41:23 +01:00
|
|
|
if (has_minithumbnail) {
|
2022-08-07 18:47:50 +02:00
|
|
|
store(sticker->minithumbnail_, storer);
|
2020-11-09 21:41:23 +01:00
|
|
|
}
|
2022-04-26 15:01:29 +02:00
|
|
|
if (has_premium_animation) {
|
2022-08-07 18:47:50 +02:00
|
|
|
store(sticker->premium_animation_file_id_, storer);
|
2022-04-26 15:01:29 +02:00
|
|
|
}
|
2022-07-25 20:18:43 +02:00
|
|
|
if (has_emoji_receive_date) {
|
2022-08-07 18:47:50 +02:00
|
|
|
store(sticker->emoji_receive_date_, storer);
|
2022-07-25 20:18:43 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class ParserT>
|
|
|
|
FileId StickersManager::parse_sticker(bool in_sticker_set, ParserT &parser) {
|
2019-05-30 00:35:19 +02:00
|
|
|
if (parser.get_error() != nullptr) {
|
|
|
|
return FileId();
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
auto sticker = make_unique<Sticker>();
|
|
|
|
bool has_sticker_set_access_hash;
|
|
|
|
bool in_sticker_set_stored;
|
2020-11-09 21:41:23 +01:00
|
|
|
bool has_minithumbnail;
|
2022-01-18 17:20:43 +01:00
|
|
|
bool is_tgs;
|
2022-01-25 12:58:04 +01:00
|
|
|
bool is_webm;
|
2022-04-26 15:01:29 +02:00
|
|
|
bool has_premium_animation;
|
2022-07-14 14:02:55 +02:00
|
|
|
bool is_mask;
|
2022-07-14 15:42:27 +02:00
|
|
|
bool is_emoji;
|
2022-07-25 20:18:43 +02:00
|
|
|
bool has_emoji_receive_date;
|
2018-12-31 20:04:05 +01:00
|
|
|
BEGIN_PARSE_FLAGS();
|
2022-07-14 14:02:55 +02:00
|
|
|
PARSE_FLAG(is_mask);
|
2018-12-31 20:04:05 +01:00
|
|
|
PARSE_FLAG(has_sticker_set_access_hash);
|
|
|
|
PARSE_FLAG(in_sticker_set_stored);
|
2022-01-18 17:20:43 +01:00
|
|
|
PARSE_FLAG(is_tgs);
|
2020-11-09 21:41:23 +01:00
|
|
|
PARSE_FLAG(has_minithumbnail);
|
2022-01-25 12:58:04 +01:00
|
|
|
PARSE_FLAG(is_webm);
|
2022-04-26 15:01:29 +02:00
|
|
|
PARSE_FLAG(has_premium_animation);
|
2022-07-14 15:42:27 +02:00
|
|
|
PARSE_FLAG(is_emoji);
|
2022-08-07 18:47:50 +02:00
|
|
|
PARSE_FLAG(sticker->is_premium_);
|
2022-07-25 20:18:43 +02:00
|
|
|
PARSE_FLAG(has_emoji_receive_date);
|
2018-12-31 20:04:05 +01:00
|
|
|
END_PARSE_FLAGS();
|
2022-01-25 12:58:04 +01:00
|
|
|
if (is_webm) {
|
2022-08-07 18:47:50 +02:00
|
|
|
sticker->format_ = StickerFormat::Webm;
|
2022-01-25 12:58:04 +01:00
|
|
|
} else if (is_tgs) {
|
2022-08-07 18:47:50 +02:00
|
|
|
sticker->format_ = StickerFormat::Tgs;
|
2022-01-18 17:20:43 +01:00
|
|
|
} else {
|
2022-08-07 18:47:50 +02:00
|
|
|
sticker->format_ = StickerFormat::Webp;
|
2022-01-18 17:20:43 +01:00
|
|
|
}
|
2022-07-14 15:42:27 +02:00
|
|
|
if (is_emoji) {
|
2022-08-07 18:47:50 +02:00
|
|
|
sticker->type_ = StickerType::CustomEmoji;
|
2022-07-14 15:42:27 +02:00
|
|
|
} else if (is_mask) {
|
2022-08-07 18:47:50 +02:00
|
|
|
sticker->type_ = StickerType::Mask;
|
2022-07-14 14:02:55 +02:00
|
|
|
} else {
|
2022-08-07 18:47:50 +02:00
|
|
|
sticker->type_ = StickerType::Regular;
|
2022-07-14 14:02:55 +02:00
|
|
|
}
|
2019-05-30 00:35:19 +02:00
|
|
|
if (in_sticker_set_stored != in_sticker_set) {
|
|
|
|
Slice data = parser.template fetch_string_raw<Slice>(parser.get_left_len());
|
|
|
|
for (auto c : data) {
|
|
|
|
if (c != '\0') {
|
2020-04-21 10:07:50 +02:00
|
|
|
parser.set_error("Invalid sticker set is stored in the database");
|
|
|
|
break;
|
2019-05-30 00:35:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
parser.set_error("Zero sticker set is stored in the database");
|
|
|
|
return FileId();
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
if (!in_sticker_set) {
|
2019-09-18 05:55:43 +02:00
|
|
|
int64 set_id;
|
|
|
|
parse(set_id, parser);
|
2022-08-07 18:47:50 +02:00
|
|
|
sticker->set_id_ = StickerSetId(set_id);
|
2018-12-31 20:04:05 +01:00
|
|
|
if (has_sticker_set_access_hash) {
|
|
|
|
int64 sticker_set_access_hash;
|
|
|
|
parse(sticker_set_access_hash, parser);
|
2022-08-07 18:47:50 +02:00
|
|
|
add_sticker_set(sticker->set_id_, sticker_set_access_hash);
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
|
|
|
// backward compatibility
|
2022-08-07 18:47:50 +02:00
|
|
|
sticker->set_id_ = StickerSetId();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
2022-08-07 18:47:50 +02:00
|
|
|
parse(sticker->alt_, parser);
|
|
|
|
parse(sticker->dimensions_, parser);
|
2019-07-15 03:01:26 +02:00
|
|
|
PhotoSize thumbnail;
|
|
|
|
parse(thumbnail, parser);
|
|
|
|
add_sticker_thumbnail(sticker.get(), thumbnail);
|
|
|
|
parse(thumbnail, parser);
|
|
|
|
add_sticker_thumbnail(sticker.get(), thumbnail);
|
2022-08-07 18:47:50 +02:00
|
|
|
parse(sticker->file_id_, parser);
|
2022-07-14 14:02:55 +02:00
|
|
|
if (is_mask) {
|
2022-08-07 18:47:50 +02:00
|
|
|
parse(sticker->point_, parser);
|
|
|
|
parse(sticker->x_shift_, parser);
|
|
|
|
parse(sticker->y_shift_, parser);
|
|
|
|
parse(sticker->scale_, parser);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2020-11-09 21:41:23 +01:00
|
|
|
if (has_minithumbnail) {
|
2022-08-07 18:47:50 +02:00
|
|
|
parse(sticker->minithumbnail_, parser);
|
2020-11-09 21:41:23 +01:00
|
|
|
}
|
2022-04-26 15:01:29 +02:00
|
|
|
if (has_premium_animation) {
|
2022-08-07 18:47:50 +02:00
|
|
|
sticker->is_premium_ = true;
|
|
|
|
parse(sticker->premium_animation_file_id_, parser);
|
2022-04-26 15:01:29 +02:00
|
|
|
}
|
2022-07-25 20:18:43 +02:00
|
|
|
if (has_emoji_receive_date) {
|
2022-08-07 18:47:50 +02:00
|
|
|
parse(sticker->emoji_receive_date_, parser);
|
2022-07-25 20:18:43 +02:00
|
|
|
}
|
|
|
|
|
2022-08-07 18:47:50 +02:00
|
|
|
if (parser.get_error() != nullptr || !sticker->file_id_.is_valid()) {
|
2019-08-01 02:58:49 +02:00
|
|
|
return FileId();
|
|
|
|
}
|
2022-08-07 18:47:50 +02:00
|
|
|
sticker->is_from_database_ = true;
|
2018-11-06 12:37:07 +01:00
|
|
|
return on_get_sticker(std::move(sticker), false); // data in the database is always outdated
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class StorerT>
|
2021-11-14 08:19:03 +01:00
|
|
|
void StickersManager::store_sticker_set(const StickerSet *sticker_set, bool with_stickers, StorerT &storer,
|
|
|
|
const char *source) const {
|
2022-07-17 21:39:22 +02:00
|
|
|
size_t stickers_limit =
|
2022-08-07 18:47:50 +02:00
|
|
|
with_stickers ? sticker_set->sticker_ids_.size() : get_max_featured_sticker_count(sticker_set->sticker_type_);
|
|
|
|
bool is_full = sticker_set->sticker_ids_.size() <= stickers_limit;
|
|
|
|
bool was_loaded = sticker_set->was_loaded_ && is_full;
|
|
|
|
bool is_loaded = sticker_set->is_loaded_ && is_full;
|
|
|
|
bool has_expires_at = !sticker_set->is_installed_ && sticker_set->expires_at_ != 0;
|
|
|
|
bool has_thumbnail = sticker_set->thumbnail_.file_id.is_valid();
|
|
|
|
bool has_minithumbnail = !sticker_set->minithumbnail_.empty();
|
|
|
|
bool is_tgs = sticker_set->sticker_format_ == StickerFormat::Tgs;
|
|
|
|
bool is_webm = sticker_set->sticker_format_ == StickerFormat::Webm;
|
|
|
|
bool is_masks = sticker_set->sticker_type_ == StickerType::Mask;
|
|
|
|
bool is_emojis = sticker_set->sticker_type_ == StickerType::CustomEmoji;
|
|
|
|
bool has_thumbnail_document_id = sticker_set->thumbnail_document_id_ != 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
BEGIN_STORE_FLAGS();
|
2022-08-07 18:47:50 +02:00
|
|
|
STORE_FLAG(sticker_set->is_inited_);
|
2018-12-31 20:04:05 +01:00
|
|
|
STORE_FLAG(was_loaded);
|
|
|
|
STORE_FLAG(is_loaded);
|
2022-08-07 18:47:50 +02:00
|
|
|
STORE_FLAG(sticker_set->is_installed_);
|
|
|
|
STORE_FLAG(sticker_set->is_archived_);
|
|
|
|
STORE_FLAG(sticker_set->is_official_);
|
2022-07-14 15:17:19 +02:00
|
|
|
STORE_FLAG(is_masks);
|
2022-08-07 18:47:50 +02:00
|
|
|
STORE_FLAG(sticker_set->is_viewed_);
|
2018-12-31 20:04:05 +01:00
|
|
|
STORE_FLAG(has_expires_at);
|
2019-05-17 16:35:45 +02:00
|
|
|
STORE_FLAG(has_thumbnail);
|
2022-08-07 18:47:50 +02:00
|
|
|
STORE_FLAG(sticker_set->is_thumbnail_reloaded_);
|
2022-01-18 17:20:43 +01:00
|
|
|
STORE_FLAG(is_tgs);
|
2022-08-07 18:47:50 +02:00
|
|
|
STORE_FLAG(sticker_set->are_legacy_sticker_thumbnails_reloaded_);
|
2020-11-09 21:41:23 +01:00
|
|
|
STORE_FLAG(has_minithumbnail);
|
2022-01-25 12:58:04 +01:00
|
|
|
STORE_FLAG(is_webm);
|
2022-07-14 15:42:27 +02:00
|
|
|
STORE_FLAG(is_emojis);
|
2022-07-16 16:22:30 +02:00
|
|
|
STORE_FLAG(has_thumbnail_document_id);
|
2018-12-31 20:04:05 +01:00
|
|
|
END_STORE_FLAGS();
|
2022-08-07 18:47:50 +02:00
|
|
|
store(sticker_set->id_.get(), storer);
|
|
|
|
store(sticker_set->access_hash_, storer);
|
|
|
|
if (sticker_set->is_inited_) {
|
|
|
|
store(sticker_set->title_, storer);
|
|
|
|
store(sticker_set->short_name_, storer);
|
|
|
|
store(sticker_set->sticker_count_, storer);
|
|
|
|
store(sticker_set->hash_, storer);
|
2018-12-31 20:04:05 +01:00
|
|
|
if (has_expires_at) {
|
2022-08-07 18:47:50 +02:00
|
|
|
store(sticker_set->expires_at_, storer);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2019-05-17 16:35:45 +02:00
|
|
|
if (has_thumbnail) {
|
2022-08-07 18:47:50 +02:00
|
|
|
store(sticker_set->thumbnail_, storer);
|
2019-05-17 16:35:45 +02:00
|
|
|
}
|
2020-11-09 21:41:23 +01:00
|
|
|
if (has_minithumbnail) {
|
2022-08-07 18:47:50 +02:00
|
|
|
store(sticker_set->minithumbnail_, storer);
|
2020-11-09 21:41:23 +01:00
|
|
|
}
|
2022-07-16 16:22:30 +02:00
|
|
|
if (has_thumbnail_document_id) {
|
2022-08-07 18:47:50 +02:00
|
|
|
store(sticker_set->thumbnail_document_id_, storer);
|
2022-07-16 16:22:30 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2022-08-07 18:47:50 +02:00
|
|
|
auto stored_sticker_count = narrow_cast<uint32>(is_full ? sticker_set->sticker_ids_.size() : stickers_limit);
|
2018-12-31 20:04:05 +01:00
|
|
|
store(stored_sticker_count, storer);
|
|
|
|
for (uint32 i = 0; i < stored_sticker_count; i++) {
|
2022-08-07 18:47:50 +02:00
|
|
|
auto sticker_id = sticker_set->sticker_ids_[i];
|
2021-11-14 08:19:03 +01:00
|
|
|
store_sticker(sticker_id, true, storer, source);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
if (was_loaded) {
|
|
|
|
auto it = sticker_set->sticker_emojis_map_.find(sticker_id);
|
|
|
|
if (it != sticker_set->sticker_emojis_map_.end()) {
|
|
|
|
store(it->second, storer);
|
|
|
|
} else {
|
|
|
|
store(vector<string>(), storer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class ParserT>
|
|
|
|
void StickersManager::parse_sticker_set(StickerSet *sticker_set, ParserT &parser) {
|
2018-12-31 20:04:05 +01:00
|
|
|
CHECK(sticker_set != nullptr);
|
2022-08-07 18:47:50 +02:00
|
|
|
CHECK(!sticker_set->was_loaded_);
|
|
|
|
bool was_inited = sticker_set->is_inited_;
|
2018-12-31 20:04:05 +01:00
|
|
|
bool is_installed;
|
|
|
|
bool is_archived;
|
|
|
|
bool is_official;
|
|
|
|
bool is_masks;
|
|
|
|
bool has_expires_at;
|
2019-05-17 16:35:45 +02:00
|
|
|
bool has_thumbnail;
|
2022-01-18 17:20:43 +01:00
|
|
|
bool is_tgs;
|
2020-11-09 21:41:23 +01:00
|
|
|
bool has_minithumbnail;
|
2022-01-25 12:58:04 +01:00
|
|
|
bool is_webm;
|
2022-07-14 15:42:27 +02:00
|
|
|
bool is_emojis;
|
2022-07-16 16:22:30 +02:00
|
|
|
bool has_thumbnail_document_id;
|
2018-12-31 20:04:05 +01:00
|
|
|
BEGIN_PARSE_FLAGS();
|
2022-08-07 18:47:50 +02:00
|
|
|
PARSE_FLAG(sticker_set->is_inited_);
|
|
|
|
PARSE_FLAG(sticker_set->was_loaded_);
|
|
|
|
PARSE_FLAG(sticker_set->is_loaded_);
|
2018-12-31 20:04:05 +01:00
|
|
|
PARSE_FLAG(is_installed);
|
|
|
|
PARSE_FLAG(is_archived);
|
|
|
|
PARSE_FLAG(is_official);
|
|
|
|
PARSE_FLAG(is_masks);
|
2022-08-07 18:47:50 +02:00
|
|
|
PARSE_FLAG(sticker_set->is_viewed_);
|
2018-12-31 20:04:05 +01:00
|
|
|
PARSE_FLAG(has_expires_at);
|
2019-05-17 16:35:45 +02:00
|
|
|
PARSE_FLAG(has_thumbnail);
|
2022-08-07 18:47:50 +02:00
|
|
|
PARSE_FLAG(sticker_set->is_thumbnail_reloaded_);
|
2022-01-18 17:20:43 +01:00
|
|
|
PARSE_FLAG(is_tgs);
|
2022-08-07 18:47:50 +02:00
|
|
|
PARSE_FLAG(sticker_set->are_legacy_sticker_thumbnails_reloaded_);
|
2020-11-09 21:41:23 +01:00
|
|
|
PARSE_FLAG(has_minithumbnail);
|
2022-01-25 12:58:04 +01:00
|
|
|
PARSE_FLAG(is_webm);
|
2022-07-14 15:42:27 +02:00
|
|
|
PARSE_FLAG(is_emojis);
|
2022-07-16 16:22:30 +02:00
|
|
|
PARSE_FLAG(has_thumbnail_document_id);
|
2018-12-31 20:04:05 +01:00
|
|
|
END_PARSE_FLAGS();
|
|
|
|
int64 sticker_set_id;
|
|
|
|
int64 access_hash;
|
|
|
|
parse(sticker_set_id, parser);
|
|
|
|
parse(access_hash, parser);
|
2022-08-07 18:47:50 +02:00
|
|
|
CHECK(sticker_set->id_.get() == sticker_set_id);
|
2022-08-02 20:41:18 +02:00
|
|
|
(void)access_hash; // unused, because only known sticker sets with access hash can be loaded from database
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2022-01-18 17:20:43 +01:00
|
|
|
StickerFormat sticker_format = StickerFormat::Unknown;
|
2022-01-25 12:58:04 +01:00
|
|
|
if (is_webm) {
|
|
|
|
sticker_format = StickerFormat::Webm;
|
|
|
|
} else if (is_tgs) {
|
2022-01-18 17:20:43 +01:00
|
|
|
sticker_format = StickerFormat::Tgs;
|
|
|
|
} else {
|
|
|
|
sticker_format = StickerFormat::Webp;
|
|
|
|
}
|
2022-07-14 15:17:19 +02:00
|
|
|
StickerType sticker_type = StickerType::Regular;
|
2022-07-14 15:42:27 +02:00
|
|
|
if (is_emojis) {
|
2022-07-19 13:51:29 +02:00
|
|
|
sticker_type = StickerType::CustomEmoji;
|
2022-07-14 15:42:27 +02:00
|
|
|
} else if (is_masks) {
|
|
|
|
sticker_type = StickerType::Mask;
|
2022-07-14 15:17:19 +02:00
|
|
|
}
|
2022-01-18 17:20:43 +01:00
|
|
|
|
2022-08-07 18:47:50 +02:00
|
|
|
if (sticker_set->is_inited_) {
|
2018-12-31 20:04:05 +01:00
|
|
|
string title;
|
|
|
|
string short_name;
|
2020-11-09 21:41:23 +01:00
|
|
|
string minithumbnail;
|
|
|
|
PhotoSize thumbnail;
|
2022-07-16 16:22:30 +02:00
|
|
|
int64 thumbnail_document_id = 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
int32 sticker_count;
|
|
|
|
int32 hash;
|
|
|
|
int32 expires_at = 0;
|
|
|
|
parse(title, parser);
|
|
|
|
parse(short_name, parser);
|
|
|
|
parse(sticker_count, parser);
|
|
|
|
parse(hash, parser);
|
|
|
|
if (has_expires_at) {
|
|
|
|
parse(expires_at, parser);
|
|
|
|
}
|
2019-05-17 16:35:45 +02:00
|
|
|
if (has_thumbnail) {
|
2020-11-09 21:41:23 +01:00
|
|
|
parse(thumbnail, parser);
|
|
|
|
}
|
|
|
|
if (has_minithumbnail) {
|
|
|
|
parse(minithumbnail, parser);
|
2019-05-17 16:35:45 +02:00
|
|
|
}
|
2022-07-16 16:22:30 +02:00
|
|
|
if (has_thumbnail_document_id) {
|
|
|
|
parse(thumbnail_document_id, parser);
|
|
|
|
}
|
2020-11-09 21:41:23 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
if (!was_inited) {
|
2022-08-07 18:47:50 +02:00
|
|
|
sticker_set->title_ = std::move(title);
|
|
|
|
sticker_set->short_name_ = std::move(short_name);
|
|
|
|
sticker_set->minithumbnail_ = std::move(minithumbnail);
|
|
|
|
sticker_set->thumbnail_ = std::move(thumbnail);
|
|
|
|
sticker_set->thumbnail_document_id_ = thumbnail_document_id;
|
|
|
|
sticker_set->sticker_count_ = sticker_count;
|
|
|
|
sticker_set->hash_ = hash;
|
|
|
|
sticker_set->expires_at_ = expires_at;
|
|
|
|
sticker_set->is_official_ = is_official;
|
|
|
|
sticker_set->sticker_type_ = sticker_type;
|
|
|
|
sticker_set->sticker_format_ = sticker_format;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2022-08-07 18:47:50 +02:00
|
|
|
auto cleaned_username = clean_username(sticker_set->short_name_);
|
2022-02-11 15:46:57 +01:00
|
|
|
if (!cleaned_username.empty()) {
|
2022-08-07 18:47:50 +02:00
|
|
|
short_name_to_sticker_set_id_.set(cleaned_username, sticker_set->id_);
|
2022-02-11 15:46:57 +01:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
on_update_sticker_set(sticker_set, is_installed, is_archived, false, true);
|
|
|
|
} else {
|
2022-08-07 18:47:50 +02:00
|
|
|
if (sticker_set->title_ != title) {
|
|
|
|
LOG(INFO) << "Title of " << sticker_set->id_ << " has changed";
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2022-08-07 18:47:50 +02:00
|
|
|
if (sticker_set->short_name_ != short_name) {
|
|
|
|
LOG(ERROR) << "Short name of " << sticker_set->id_ << " has changed from \"" << short_name << "\" to \""
|
|
|
|
<< sticker_set->short_name_ << "\"";
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2022-08-07 18:47:50 +02:00
|
|
|
if (sticker_set->sticker_count_ != sticker_count || sticker_set->hash_ != hash) {
|
|
|
|
sticker_set->is_loaded_ = false;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2022-08-07 18:47:50 +02:00
|
|
|
if (sticker_set->sticker_format_ != sticker_format) {
|
|
|
|
LOG(ERROR) << "Sticker format of " << sticker_set->id_ << " has changed from \"" << sticker_format << "\" to \""
|
|
|
|
<< sticker_set->sticker_format_ << "\"";
|
2019-07-15 02:43:05 +02:00
|
|
|
}
|
2022-08-07 18:47:50 +02:00
|
|
|
if (sticker_set->sticker_type_ != sticker_type) {
|
|
|
|
LOG(ERROR) << "Type of " << sticker_set->id_ << " has changed from \"" << sticker_type << "\" to \""
|
|
|
|
<< sticker_set->sticker_type_ << "\"";
|
2019-07-15 02:43:05 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32 stored_sticker_count;
|
|
|
|
parse(stored_sticker_count, parser);
|
2022-08-07 18:47:50 +02:00
|
|
|
sticker_set->sticker_ids_.clear();
|
2022-08-08 20:13:22 +02:00
|
|
|
sticker_set->premium_sticker_positions_.clear();
|
2022-08-07 18:47:50 +02:00
|
|
|
if (sticker_set->was_loaded_) {
|
2018-12-31 20:04:05 +01:00
|
|
|
sticker_set->emoji_stickers_map_.clear();
|
|
|
|
sticker_set->sticker_emojis_map_.clear();
|
|
|
|
}
|
|
|
|
for (uint32 i = 0; i < stored_sticker_count; i++) {
|
|
|
|
auto sticker_id = parse_sticker(true, parser);
|
2019-05-30 00:35:19 +02:00
|
|
|
if (parser.get_error() != nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
2019-10-03 17:16:11 +02:00
|
|
|
if (!sticker_id.is_valid()) {
|
|
|
|
return parser.set_error("Receive invalid sticker in a sticker set");
|
|
|
|
}
|
2022-08-07 18:47:50 +02:00
|
|
|
sticker_set->sticker_ids_.push_back(sticker_id);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
Sticker *sticker = get_sticker(sticker_id);
|
|
|
|
CHECK(sticker != nullptr);
|
2022-08-07 18:47:50 +02:00
|
|
|
if (sticker->set_id_ != sticker_set->id_) {
|
|
|
|
LOG_IF(ERROR, sticker->set_id_.is_valid()) << "Sticker " << sticker_id << " set_id has changed";
|
|
|
|
sticker->set_id_ = sticker_set->id_;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2022-08-07 19:35:13 +02:00
|
|
|
if (sticker->is_premium_) {
|
|
|
|
sticker_set->premium_sticker_positions_.push_back(static_cast<int32>(sticker_set->sticker_ids_.size() - 1));
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2022-08-07 18:47:50 +02:00
|
|
|
if (sticker_set->was_loaded_) {
|
2018-12-31 20:04:05 +01:00
|
|
|
vector<string> emojis;
|
|
|
|
parse(emojis, parser);
|
|
|
|
for (auto &emoji : emojis) {
|
2022-05-12 17:02:27 +02:00
|
|
|
auto cleaned_emoji = remove_emoji_modifiers(emoji);
|
2022-02-11 15:46:57 +01:00
|
|
|
if (!cleaned_emoji.empty()) {
|
|
|
|
auto &sticker_ids = sticker_set->emoji_stickers_map_[cleaned_emoji];
|
|
|
|
if (sticker_ids.empty() || sticker_ids.back() != sticker_id) {
|
|
|
|
sticker_ids.push_back(sticker_id);
|
|
|
|
}
|
|
|
|
} else {
|
2022-08-07 18:47:50 +02:00
|
|
|
LOG(INFO) << "Sticker " << sticker_id << " in " << sticker_set_id << '/' << sticker_set->short_name_
|
2022-02-11 15:46:57 +01:00
|
|
|
<< " has an empty emoji";
|
2018-07-31 22:48:54 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
sticker_set->sticker_emojis_map_[sticker_id] = std::move(emojis);
|
|
|
|
}
|
|
|
|
}
|
2022-08-07 18:47:50 +02:00
|
|
|
if (expires_at > sticker_set->expires_at_) {
|
|
|
|
sticker_set->expires_at_ = expires_at;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2021-06-17 22:29:13 +02:00
|
|
|
|
2022-08-07 18:47:50 +02:00
|
|
|
if (!check_utf8(sticker_set->title_)) {
|
2021-06-17 22:29:13 +02:00
|
|
|
return parser.set_error("Have invalid sticker set title");
|
|
|
|
}
|
2022-08-07 18:47:50 +02:00
|
|
|
if (!check_utf8(sticker_set->short_name_)) {
|
2021-06-17 22:29:13 +02:00
|
|
|
return parser.set_error("Have invalid sticker set name");
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class StorerT>
|
2019-09-18 05:55:43 +02:00
|
|
|
void StickersManager::store_sticker_set_id(StickerSetId sticker_set_id, StorerT &storer) const {
|
|
|
|
CHECK(sticker_set_id.is_valid());
|
2018-12-31 20:04:05 +01:00
|
|
|
const StickerSet *sticker_set = get_sticker_set(sticker_set_id);
|
|
|
|
CHECK(sticker_set != nullptr);
|
2019-09-18 05:55:43 +02:00
|
|
|
store(sticker_set_id.get(), storer);
|
2022-08-07 18:47:50 +02:00
|
|
|
store(sticker_set->access_hash_, storer);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class ParserT>
|
2019-09-18 05:55:43 +02:00
|
|
|
void StickersManager::parse_sticker_set_id(StickerSetId &sticker_set_id, ParserT &parser) {
|
|
|
|
int64 set_id;
|
|
|
|
parse(set_id, parser);
|
|
|
|
sticker_set_id = StickerSetId(set_id);
|
2018-12-31 20:04:05 +01:00
|
|
|
int64 sticker_set_access_hash;
|
|
|
|
parse(sticker_set_access_hash, parser);
|
|
|
|
add_sticker_set(sticker_set_id, sticker_set_access_hash);
|
|
|
|
}
|
|
|
|
|
2022-01-24 14:43:38 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void StickersManager::Reaction::store(StorerT &storer) const {
|
|
|
|
StickersManager *stickers_manager = storer.context()->td().get_actor_unsafe()->stickers_manager_.get();
|
|
|
|
bool has_around_animation = !around_animation_.empty();
|
|
|
|
bool has_center_animation = !center_animation_.empty();
|
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(is_active_);
|
|
|
|
STORE_FLAG(has_around_animation);
|
|
|
|
STORE_FLAG(has_center_animation);
|
2022-04-26 13:40:06 +02:00
|
|
|
STORE_FLAG(is_premium_);
|
2022-01-24 14:43:38 +01:00
|
|
|
END_STORE_FLAGS();
|
|
|
|
td::store(reaction_, storer);
|
|
|
|
td::store(title_, storer);
|
|
|
|
stickers_manager->store_sticker(static_icon_, false, storer, "Reaction");
|
|
|
|
stickers_manager->store_sticker(appear_animation_, false, storer, "Reaction");
|
|
|
|
stickers_manager->store_sticker(select_animation_, false, storer, "Reaction");
|
|
|
|
stickers_manager->store_sticker(activate_animation_, false, storer, "Reaction");
|
|
|
|
stickers_manager->store_sticker(effect_animation_, false, storer, "Reaction");
|
|
|
|
if (has_around_animation) {
|
|
|
|
stickers_manager->store_sticker(around_animation_, false, storer, "Reaction");
|
|
|
|
}
|
|
|
|
if (has_center_animation) {
|
|
|
|
stickers_manager->store_sticker(center_animation_, false, storer, "Reaction");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void StickersManager::Reaction::parse(ParserT &parser) {
|
|
|
|
StickersManager *stickers_manager = parser.context()->td().get_actor_unsafe()->stickers_manager_.get();
|
|
|
|
bool has_around_animation;
|
|
|
|
bool has_center_animation;
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(is_active_);
|
|
|
|
PARSE_FLAG(has_around_animation);
|
|
|
|
PARSE_FLAG(has_center_animation);
|
2022-04-26 13:40:06 +02:00
|
|
|
PARSE_FLAG(is_premium_);
|
2022-01-24 14:43:38 +01:00
|
|
|
END_PARSE_FLAGS();
|
|
|
|
td::parse(reaction_, parser);
|
|
|
|
td::parse(title_, parser);
|
|
|
|
static_icon_ = stickers_manager->parse_sticker(false, parser);
|
|
|
|
appear_animation_ = stickers_manager->parse_sticker(false, parser);
|
|
|
|
select_animation_ = stickers_manager->parse_sticker(false, parser);
|
|
|
|
activate_animation_ = stickers_manager->parse_sticker(false, parser);
|
|
|
|
effect_animation_ = stickers_manager->parse_sticker(false, parser);
|
|
|
|
if (has_around_animation) {
|
|
|
|
around_animation_ = stickers_manager->parse_sticker(false, parser);
|
|
|
|
}
|
|
|
|
if (has_center_animation) {
|
|
|
|
center_animation_ = stickers_manager->parse_sticker(false, parser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void StickersManager::Reactions::store(StorerT &storer) const {
|
|
|
|
bool has_reactions = !reactions_.empty();
|
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(has_reactions);
|
|
|
|
END_STORE_FLAGS();
|
|
|
|
if (has_reactions) {
|
|
|
|
td::store(reactions_, storer);
|
|
|
|
td::store(hash_, storer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void StickersManager::Reactions::parse(ParserT &parser) {
|
|
|
|
bool has_reactions;
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(has_reactions);
|
|
|
|
END_PARSE_FLAGS();
|
|
|
|
if (has_reactions) {
|
|
|
|
td::parse(reactions_, parser);
|
|
|
|
td::parse(hash_, parser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|