Add strongly typed StickerSetId.

GitOrigin-RevId: 518121f89e3a4c95ab5a2095a9bc2217090911de
This commit is contained in:
levlam 2019-09-18 06:55:43 +03:00
parent 6f4fda224d
commit 408a456589
14 changed files with 442 additions and 327 deletions

View File

@ -623,6 +623,7 @@ set(TDLIB_SOURCE
td/telegram/SequenceDispatcher.h td/telegram/SequenceDispatcher.h
td/telegram/SetWithPosition.h td/telegram/SetWithPosition.h
td/telegram/StateManager.h td/telegram/StateManager.h
td/telegram/StickerSetId.h
td/telegram/StickersManager.h td/telegram/StickersManager.h
td/telegram/StorageManager.h td/telegram/StorageManager.h
td/telegram/Td.h td/telegram/Td.h
@ -666,6 +667,7 @@ set(TDLIB_SOURCE
td/telegram/ReplyMarkup.hpp td/telegram/ReplyMarkup.hpp
td/telegram/SecureValue.hpp td/telegram/SecureValue.hpp
td/telegram/SendCodeHelper.hpp td/telegram/SendCodeHelper.hpp
td/telegram/StickerSetId.hpp
td/telegram/StickersManager.hpp td/telegram/StickersManager.hpp
td/telegram/VideoNotesManager.hpp td/telegram/VideoNotesManager.hpp
td/telegram/VideosManager.hpp td/telegram/VideosManager.hpp

View File

@ -27,8 +27,8 @@
#include "td/telegram/Photo.h" #include "td/telegram/Photo.h"
#include "td/telegram/Photo.hpp" #include "td/telegram/Photo.hpp"
#include "td/telegram/SecretChatActor.h" #include "td/telegram/SecretChatActor.h"
#include "td/telegram/StickerSetId.hpp"
#include "td/telegram/StickersManager.h" #include "td/telegram/StickersManager.h"
#include "td/telegram/StickersManager.hpp"
#include "td/telegram/Td.h" #include "td/telegram/Td.h"
#include "td/telegram/TdDb.h" #include "td/telegram/TdDb.h"
#include "td/telegram/TopDialogManager.h" #include "td/telegram/TopDialogManager.h"
@ -997,13 +997,13 @@ class UpdateChannelUsernameQuery : public Td::ResultHandler {
class SetChannelStickerSetQuery : public Td::ResultHandler { class SetChannelStickerSetQuery : public Td::ResultHandler {
Promise<Unit> promise_; Promise<Unit> promise_;
ChannelId channel_id_; ChannelId channel_id_;
int64 sticker_set_id_; StickerSetId sticker_set_id_;
public: public:
explicit SetChannelStickerSetQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) { explicit SetChannelStickerSetQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
} }
void send(ChannelId channel_id, int64 sticker_set_id, void send(ChannelId channel_id, StickerSetId sticker_set_id,
telegram_api::object_ptr<telegram_api::InputStickerSet> &&input_sticker_set) { telegram_api::object_ptr<telegram_api::InputStickerSet> &&input_sticker_set) {
channel_id_ = channel_id; channel_id_ = channel_id;
sticker_set_id_ = sticker_set_id; sticker_set_id_ = sticker_set_id;
@ -3008,7 +3008,7 @@ void ContactsManager::ChannelFull::store(StorerT &storer) const {
bool has_restricted_count = restricted_count != 0; bool has_restricted_count = restricted_count != 0;
bool has_banned_count = banned_count != 0; bool has_banned_count = banned_count != 0;
bool has_invite_link = !invite_link.empty(); bool has_invite_link = !invite_link.empty();
bool has_sticker_set = sticker_set_id != 0; bool has_sticker_set = sticker_set_id.is_valid();
bool has_linked_channel_id = linked_channel_id.is_valid(); bool has_linked_channel_id = linked_channel_id.is_valid();
bool has_migrated_from_max_message_id = migrated_from_max_message_id.is_valid(); bool has_migrated_from_max_message_id = migrated_from_max_message_id.is_valid();
bool has_migrated_from_chat_id = migrated_from_chat_id.is_valid(); bool has_migrated_from_chat_id = migrated_from_chat_id.is_valid();
@ -3045,7 +3045,7 @@ void ContactsManager::ChannelFull::store(StorerT &storer) const {
store(invite_link, storer); store(invite_link, storer);
} }
if (has_sticker_set) { if (has_sticker_set) {
storer.context()->td().get_actor_unsafe()->stickers_manager_->store_sticker_set_id(sticker_set_id, storer); store(sticker_set_id, storer);
} }
if (has_linked_channel_id) { if (has_linked_channel_id) {
store(linked_channel_id, storer); store(linked_channel_id, storer);
@ -3104,7 +3104,7 @@ void ContactsManager::ChannelFull::parse(ParserT &parser) {
parse(invite_link, parser); parse(invite_link, parser);
} }
if (has_sticker_set) { if (has_sticker_set) {
parser.context()->td().get_actor_unsafe()->stickers_manager_->parse_sticker_set_id(sticker_set_id, parser); parse(sticker_set_id, parser);
} }
if (has_linked_channel_id) { if (has_linked_channel_id) {
parse(linked_channel_id, parser); parse(linked_channel_id, parser);
@ -4504,7 +4504,8 @@ void ContactsManager::set_channel_username(ChannelId channel_id, const string &u
td_->create_handler<UpdateChannelUsernameQuery>(std::move(promise))->send(channel_id, username); td_->create_handler<UpdateChannelUsernameQuery>(std::move(promise))->send(channel_id, username);
} }
void ContactsManager::set_channel_sticker_set(ChannelId channel_id, int64 sticker_set_id, Promise<Unit> &&promise) { void ContactsManager::set_channel_sticker_set(ChannelId channel_id, StickerSetId sticker_set_id,
Promise<Unit> &&promise) {
auto c = get_channel(channel_id); auto c = get_channel(channel_id);
if (c == nullptr) { if (c == nullptr) {
return promise.set_error(Status::Error(6, "Supergroup not found")); return promise.set_error(Status::Error(6, "Supergroup not found"));
@ -4517,7 +4518,7 @@ void ContactsManager::set_channel_sticker_set(ChannelId channel_id, int64 sticke
} }
telegram_api::object_ptr<telegram_api::InputStickerSet> input_sticker_set; telegram_api::object_ptr<telegram_api::InputStickerSet> input_sticker_set;
if (sticker_set_id == 0) { if (!sticker_set_id.is_valid()) {
input_sticker_set = telegram_api::make_object<telegram_api::inputStickerSetEmpty>(); input_sticker_set = telegram_api::make_object<telegram_api::inputStickerSetEmpty>();
} else { } else {
input_sticker_set = td_->stickers_manager_->get_input_sticker_set(sticker_set_id); input_sticker_set = td_->stickers_manager_->get_input_sticker_set(sticker_set_id);
@ -7408,9 +7409,10 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
auto can_set_sticker_set = (channel_full->flags_ & CHANNEL_FULL_FLAG_CAN_SET_STICKERS) != 0; auto can_set_sticker_set = (channel_full->flags_ & CHANNEL_FULL_FLAG_CAN_SET_STICKERS) != 0;
auto can_view_statistics = (channel_full->flags_ & CHANNEL_FULL_FLAG_CAN_VIEW_STATISTICS) != 0; auto can_view_statistics = (channel_full->flags_ & CHANNEL_FULL_FLAG_CAN_VIEW_STATISTICS) != 0;
auto is_all_history_available = (channel_full->flags_ & CHANNEL_FULL_FLAG_IS_ALL_HISTORY_HIDDEN) == 0; auto is_all_history_available = (channel_full->flags_ & CHANNEL_FULL_FLAG_IS_ALL_HISTORY_HIDDEN) == 0;
int64 sticker_set_id = channel_full->stickerset_ == nullptr StickerSetId sticker_set_id;
? 0 if (channel_full->stickerset_ != nullptr) {
: td_->stickers_manager_->on_get_sticker_set(std::move(channel_full->stickerset_), true); sticker_set_id = td_->stickers_manager_->on_get_sticker_set(std::move(channel_full->stickerset_), true);
}
ChannelFull *channel = &channels_full_[channel_id]; ChannelFull *channel = &channels_full_[channel_id];
channel->expires_at = Time::now() + CHANNEL_FULL_EXPIRE_TIME; channel->expires_at = Time::now() + CHANNEL_FULL_EXPIRE_TIME;
@ -9376,7 +9378,7 @@ void ContactsManager::on_update_channel_description(ChannelId channel_id, string
} }
} }
void ContactsManager::on_update_channel_sticker_set(ChannelId channel_id, int64 sticker_set_id) { void ContactsManager::on_update_channel_sticker_set(ChannelId channel_id, StickerSetId sticker_set_id) {
if (!channel_id.is_valid()) { if (!channel_id.is_valid()) {
LOG(ERROR) << "Receive invalid " << channel_id; LOG(ERROR) << "Receive invalid " << channel_id;
return; return;
@ -11264,7 +11266,7 @@ tl_object_ptr<td_api::supergroupFullInfo> ContactsManager::get_supergroup_full_i
channel_full->description, channel_full->participant_count, channel_full->administrator_count, channel_full->description, channel_full->participant_count, channel_full->administrator_count,
channel_full->restricted_count, channel_full->banned_count, DialogId(channel_full->linked_channel_id).get(), channel_full->restricted_count, channel_full->banned_count, DialogId(channel_full->linked_channel_id).get(),
channel_full->can_get_participants, channel_full->can_set_username, channel_full->can_set_sticker_set, channel_full->can_get_participants, channel_full->can_set_username, channel_full->can_set_sticker_set,
channel_full->can_view_statistics, channel_full->is_all_history_available, channel_full->sticker_set_id, channel_full->can_view_statistics, channel_full->is_all_history_available, channel_full->sticker_set_id.get(),
channel_full->invite_link, channel_full->invite_link,
get_basic_group_id_object(channel_full->migrated_from_chat_id, "get_supergroup_full_info_object"), get_basic_group_id_object(channel_full->migrated_from_chat_id, "get_supergroup_full_info_object"),
channel_full->migrated_from_max_message_id.get()); channel_full->migrated_from_max_message_id.get());

View File

@ -21,6 +21,7 @@
#include "td/telegram/Photo.h" #include "td/telegram/Photo.h"
#include "td/telegram/QueryCombiner.h" #include "td/telegram/QueryCombiner.h"
#include "td/telegram/SecretChatId.h" #include "td/telegram/SecretChatId.h"
#include "td/telegram/StickerSetId.h"
#include "td/telegram/UserId.h" #include "td/telegram/UserId.h"
#include "td/actor/actor.h" #include "td/actor/actor.h"
@ -176,7 +177,7 @@ class ContactsManager : public Actor {
void on_update_channel_username(ChannelId channel_id, string &&username); void on_update_channel_username(ChannelId channel_id, string &&username);
void on_update_channel_description(ChannelId channel_id, string &&description); void on_update_channel_description(ChannelId channel_id, string &&description);
void on_update_channel_sticker_set(ChannelId channel_id, int64 sticker_set_id); void on_update_channel_sticker_set(ChannelId channel_id, StickerSetId sticker_set_id);
void on_update_channel_linked_channel_id(ChannelId channel_id, ChannelId group_channel_id); void on_update_channel_linked_channel_id(ChannelId channel_id, ChannelId group_channel_id);
void on_update_channel_is_all_history_available(ChannelId channel_id, bool is_all_history_available); void on_update_channel_is_all_history_available(ChannelId channel_id, bool is_all_history_available);
void on_update_channel_default_permissions(ChannelId channel_id, RestrictedRights default_permissions); void on_update_channel_default_permissions(ChannelId channel_id, RestrictedRights default_permissions);
@ -298,7 +299,7 @@ class ContactsManager : public Actor {
void set_channel_username(ChannelId channel_id, const string &username, Promise<Unit> &&promise); void set_channel_username(ChannelId channel_id, const string &username, Promise<Unit> &&promise);
void set_channel_sticker_set(ChannelId channel_id, int64 sticker_set_id, Promise<Unit> &&promise); void set_channel_sticker_set(ChannelId channel_id, StickerSetId sticker_set_id, Promise<Unit> &&promise);
void toggle_channel_sign_messages(ChannelId channel_id, bool sign_messages, Promise<Unit> &&promise); void toggle_channel_sign_messages(ChannelId channel_id, bool sign_messages, Promise<Unit> &&promise);
@ -706,7 +707,7 @@ class ContactsManager : public Actor {
int32 banned_count = 0; int32 banned_count = 0;
string invite_link; string invite_link;
int64 sticker_set_id = 0; // do not forget to store along with access hash StickerSetId sticker_set_id;
ChannelId linked_channel_id; ChannelId linked_channel_id;

View File

@ -12,6 +12,7 @@
#include "td/telegram/files/FileManager.h" #include "td/telegram/files/FileManager.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
#include "td/telegram/MessagesManager.h" #include "td/telegram/MessagesManager.h"
#include "td/telegram/StickerSetId.h"
#include "td/telegram/StickersManager.h" #include "td/telegram/StickersManager.h"
#include "td/telegram/WebPagesManager.h" #include "td/telegram/WebPagesManager.h"
@ -354,7 +355,7 @@ void FileReferenceManager::reload_photo(PhotoSizeSource source, Promise<Unit> pr
break; break;
case PhotoSizeSource::Type::StickerSetThumbnail: case PhotoSizeSource::Type::StickerSetThumbnail:
send_closure(G()->stickers_manager(), &StickersManager::reload_sticker_set, send_closure(G()->stickers_manager(), &StickersManager::reload_sticker_set,
source.sticker_set_thumbnail().sticker_set_id, StickerSetId(source.sticker_set_thumbnail().sticker_set_id),
source.sticker_set_thumbnail().sticker_set_access_hash, std::move(promise)); source.sticker_set_thumbnail().sticker_set_access_hash, std::move(promise));
break; break;
default: default:

View File

@ -5029,7 +5029,7 @@ void on_sent_message_content(Td *td, const MessageContent *content) {
} }
} }
int64 add_sticker_set(Td *td, tl_object_ptr<telegram_api::InputStickerSet> &&input_sticker_set) { StickerSetId add_sticker_set(Td *td, tl_object_ptr<telegram_api::InputStickerSet> &&input_sticker_set) {
return td->stickers_manager_->add_sticker_set(std::move(input_sticker_set)); return td->stickers_manager_->add_sticker_set(std::move(input_sticker_set));
} }

View File

@ -15,6 +15,7 @@
#include "td/telegram/Photo.h" #include "td/telegram/Photo.h"
#include "td/telegram/ReplyMarkup.h" #include "td/telegram/ReplyMarkup.h"
#include "td/telegram/secret_api.h" #include "td/telegram/secret_api.h"
#include "td/telegram/StickerSetId.h"
#include "td/telegram/td_api.h" #include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h" #include "td/telegram/telegram_api.h"
#include "td/telegram/UserId.h" #include "td/telegram/UserId.h"
@ -252,6 +253,6 @@ void add_message_content_dependencies(Dependencies &dependencies, const MessageC
void on_sent_message_content(Td *td, const MessageContent *content); void on_sent_message_content(Td *td, const MessageContent *content);
int64 add_sticker_set(Td *td, tl_object_ptr<telegram_api::InputStickerSet> &&input_sticker_set); StickerSetId add_sticker_set(Td *td, tl_object_ptr<telegram_api::InputStickerSet> &&input_sticker_set);
} // namespace td } // namespace td

View File

@ -41,6 +41,7 @@
#include "td/telegram/SecretChatActor.h" #include "td/telegram/SecretChatActor.h"
#include "td/telegram/SecretChatsManager.h" #include "td/telegram/SecretChatsManager.h"
#include "td/telegram/SequenceDispatcher.h" #include "td/telegram/SequenceDispatcher.h"
#include "td/telegram/StickerSetId.h"
#include "td/telegram/Td.h" #include "td/telegram/Td.h"
#include "td/telegram/TdDb.h" #include "td/telegram/TdDb.h"
#include "td/telegram/TopDialogManager.h" #include "td/telegram/TopDialogManager.h"
@ -23546,7 +23547,7 @@ tl_object_ptr<td_api::ChatEventAction> MessagesManager::get_chat_event_action_ob
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionChangeStickerSet>(action_ptr); auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionChangeStickerSet>(action_ptr);
auto old_sticker_set_id = add_sticker_set(td_, std::move(action->prev_stickerset_)); auto old_sticker_set_id = add_sticker_set(td_, std::move(action->prev_stickerset_));
auto new_sticker_set_id = add_sticker_set(td_, std::move(action->new_stickerset_)); auto new_sticker_set_id = add_sticker_set(td_, std::move(action->new_stickerset_));
return make_tl_object<td_api::chatEventStickerSetChanged>(old_sticker_set_id, new_sticker_set_id); return make_tl_object<td_api::chatEventStickerSetChanged>(old_sticker_set_id.get(), new_sticker_set_id.get());
} }
case telegram_api::channelAdminLogEventActionTogglePreHistoryHidden::ID: { case telegram_api::channelAdminLogEventActionTogglePreHistoryHidden::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionTogglePreHistoryHidden>(action_ptr); auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionTogglePreHistoryHidden>(action_ptr);

View File

@ -0,0 +1,55 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
//
// 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
#include "td/utils/common.h"
#include "td/utils/StringBuilder.h"
#include <functional>
#include <type_traits>
namespace td {
class StickerSetId {
int64 id = 0;
public:
StickerSetId() = default;
explicit constexpr StickerSetId(int64 sticker_set_id) : id(sticker_set_id) {
}
template <class T, typename = std::enable_if_t<std::is_convertible<T, int64>::value>>
StickerSetId(T sticker_set_id) = delete;
bool is_valid() const {
return id != 0;
}
int64 get() const {
return id;
}
bool operator==(const StickerSetId &other) const {
return id == other.id;
}
bool operator!=(const StickerSetId &other) const {
return id != other.id;
}
};
struct StickerSetIdHash {
std::size_t operator()(StickerSetId sticker_set_id) const {
return std::hash<int64>()(sticker_set_id.get());
}
};
inline StringBuilder &operator<<(StringBuilder &string_builder, StickerSetId sticker_set_id) {
return string_builder << "sticker set " << sticker_set_id.get();
}
} // namespace td

View File

@ -0,0 +1,27 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
//
// 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
#include "td/telegram/StickerSetId.h"
#include "td/telegram/StickersManager.h"
#include "td/telegram/StickersManager.hpp"
#include "td/telegram/Td.h"
namespace td {
template <class StorerT>
void store(const StickerSetId &sticker_set_id, StorerT &storer) {
storer.context()->td().get_actor_unsafe()->stickers_manager_->store_sticker_set_id(sticker_set_id, storer);
}
template <class ParserT>
void parse(StickerSetId &sticker_set_id, ParserT &parser) {
parser.context()->td().get_actor_unsafe()->stickers_manager_->parse_sticker_set_id(sticker_set_id, parser);
}
} // namespace td

File diff suppressed because it is too large Load Diff

View File

@ -15,6 +15,7 @@
#include "td/telegram/files/FileSourceId.h" #include "td/telegram/files/FileSourceId.h"
#include "td/telegram/Photo.h" #include "td/telegram/Photo.h"
#include "td/telegram/SecretInputMedia.h" #include "td/telegram/SecretInputMedia.h"
#include "td/telegram/StickerSetId.h"
#include "td/utils/buffer.h" #include "td/utils/buffer.h"
#include "td/utils/common.h" #include "td/utils/common.h"
@ -38,18 +39,22 @@ class StickersManager : public Actor {
public: public:
static constexpr int64 GREAT_MINDS_SET_ID = 1842540969984001; static constexpr int64 GREAT_MINDS_SET_ID = 1842540969984001;
static vector<StickerSetId> convert_sticker_set_ids(const vector<int64> &sticker_set_ids);
static vector<int64> convert_sticker_set_ids(const vector<StickerSetId> &sticker_set_ids);
StickersManager(Td *td, ActorShared<> parent); StickersManager(Td *td, ActorShared<> parent);
tl_object_ptr<td_api::sticker> get_sticker_object(FileId file_id) const; tl_object_ptr<td_api::sticker> get_sticker_object(FileId file_id) const;
tl_object_ptr<td_api::stickers> get_stickers_object(const vector<FileId> &sticker_ids) const; tl_object_ptr<td_api::stickers> get_stickers_object(const vector<FileId> &sticker_ids) const;
tl_object_ptr<td_api::stickerSet> get_sticker_set_object(int64 sticker_set_id) const; tl_object_ptr<td_api::stickerSet> get_sticker_set_object(StickerSetId sticker_set_id) const;
tl_object_ptr<td_api::stickerSets> get_sticker_sets_object(int32 total_count, const vector<int64> &sticker_set_ids, tl_object_ptr<td_api::stickerSets> get_sticker_sets_object(int32 total_count,
const vector<StickerSetId> &sticker_set_ids,
size_t covers_limit) const; size_t covers_limit) const;
tl_object_ptr<telegram_api::InputStickerSet> get_input_sticker_set(int64 sticker_set_id) const; tl_object_ptr<telegram_api::InputStickerSet> get_input_sticker_set(StickerSetId sticker_set_id) const;
void create_sticker(FileId file_id, PhotoSize thumbnail, Dimensions dimensions, void create_sticker(FileId file_id, PhotoSize thumbnail, Dimensions dimensions,
tl_object_ptr<telegram_api::documentAttributeSticker> sticker, bool is_animated, tl_object_ptr<telegram_api::documentAttributeSticker> sticker, bool is_animated,
@ -69,68 +74,69 @@ class StickersManager : public Actor {
vector<FileId> search_stickers(string emoji, int32 limit, Promise<Unit> &&promise); vector<FileId> search_stickers(string emoji, int32 limit, Promise<Unit> &&promise);
vector<int64> get_installed_sticker_sets(bool is_masks, Promise<Unit> &&promise); vector<StickerSetId> get_installed_sticker_sets(bool is_masks, Promise<Unit> &&promise);
bool has_webp_thumbnail(const tl_object_ptr<telegram_api::documentAttributeSticker> &sticker); bool has_webp_thumbnail(const tl_object_ptr<telegram_api::documentAttributeSticker> &sticker);
int64 get_sticker_set_id(const tl_object_ptr<telegram_api::InputStickerSet> &set_ptr); StickerSetId get_sticker_set_id(const tl_object_ptr<telegram_api::InputStickerSet> &set_ptr);
int64 add_sticker_set(tl_object_ptr<telegram_api::InputStickerSet> &&set_ptr); StickerSetId add_sticker_set(tl_object_ptr<telegram_api::InputStickerSet> &&set_ptr);
int64 get_sticker_set(int64 set_id, Promise<Unit> &&promise); StickerSetId get_sticker_set(StickerSetId set_id, Promise<Unit> &&promise);
int64 search_sticker_set(const string &short_name_to_search, Promise<Unit> &&promise); StickerSetId search_sticker_set(const string &short_name_to_search, Promise<Unit> &&promise);
std::pair<int32, vector<int64>> search_installed_sticker_sets(bool is_masks, const string &query, int32 limit, std::pair<int32, vector<StickerSetId>> search_installed_sticker_sets(bool is_masks, const string &query, int32 limit,
Promise<Unit> &&promise); Promise<Unit> &&promise);
vector<int64> search_sticker_sets(const string &query, Promise<Unit> &&promise); vector<StickerSetId> search_sticker_sets(const string &query, Promise<Unit> &&promise);
void change_sticker_set(int64 set_id, bool is_installed, bool is_archived, Promise<Unit> &&promise); void change_sticker_set(StickerSetId set_id, bool is_installed, bool is_archived, Promise<Unit> &&promise);
void view_featured_sticker_sets(const vector<int64> &sticker_set_ids); void view_featured_sticker_sets(const vector<StickerSetId> &sticker_set_ids);
void on_get_installed_sticker_sets(bool is_masks, tl_object_ptr<telegram_api::messages_AllStickers> &&stickers_ptr); void on_get_installed_sticker_sets(bool is_masks, tl_object_ptr<telegram_api::messages_AllStickers> &&stickers_ptr);
void on_get_installed_sticker_sets_failed(bool is_masks, Status error); void on_get_installed_sticker_sets_failed(bool is_masks, Status error);
void on_get_messages_sticker_set(int64 sticker_set_id, tl_object_ptr<telegram_api::messages_stickerSet> &&set, void on_get_messages_sticker_set(StickerSetId sticker_set_id, tl_object_ptr<telegram_api::messages_stickerSet> &&set,
bool is_changed); bool is_changed);
int64 on_get_sticker_set(tl_object_ptr<telegram_api::stickerSet> &&set, bool is_changed); StickerSetId on_get_sticker_set(tl_object_ptr<telegram_api::stickerSet> &&set, bool is_changed);
int64 on_get_sticker_set_covered(tl_object_ptr<telegram_api::StickerSetCovered> &&set_ptr, bool is_changed); StickerSetId on_get_sticker_set_covered(tl_object_ptr<telegram_api::StickerSetCovered> &&set_ptr, bool is_changed);
void on_load_sticker_set_fail(int64 sticker_set_id, const Status &error); void on_load_sticker_set_fail(StickerSetId sticker_set_id, const Status &error);
void on_install_sticker_set(int64 set_id, bool is_archived, void on_install_sticker_set(StickerSetId set_id, bool is_archived,
tl_object_ptr<telegram_api::messages_StickerSetInstallResult> &&result); tl_object_ptr<telegram_api::messages_StickerSetInstallResult> &&result);
void on_uninstall_sticker_set(int64 set_id); void on_uninstall_sticker_set(StickerSetId set_id);
void on_update_sticker_sets(); void on_update_sticker_sets();
void on_update_sticker_sets_order(bool is_masks, const vector<int64> &sticker_set_ids); void on_update_sticker_sets_order(bool is_masks, const vector<StickerSetId> &sticker_set_ids);
std::pair<int32, vector<int64>> get_archived_sticker_sets(bool is_masks, int64 offset_sticker_set_id, int32 limit, std::pair<int32, vector<StickerSetId>> get_archived_sticker_sets(bool is_masks, StickerSetId offset_sticker_set_id,
bool force, Promise<Unit> &&promise); int32 limit, bool force, Promise<Unit> &&promise);
void on_get_archived_sticker_sets(bool is_masks, int64 offset_sticker_set_id, void on_get_archived_sticker_sets(bool is_masks, StickerSetId offset_sticker_set_id,
vector<tl_object_ptr<telegram_api::StickerSetCovered>> &&sticker_sets, vector<tl_object_ptr<telegram_api::StickerSetCovered>> &&sticker_sets,
int32 total_count); int32 total_count);
vector<int64> get_featured_sticker_sets(Promise<Unit> &&promise); vector<StickerSetId> get_featured_sticker_sets(Promise<Unit> &&promise);
void on_get_featured_sticker_sets(tl_object_ptr<telegram_api::messages_FeaturedStickers> &&sticker_sets_ptr); void on_get_featured_sticker_sets(tl_object_ptr<telegram_api::messages_FeaturedStickers> &&sticker_sets_ptr);
void on_get_featured_sticker_sets_failed(Status error); void on_get_featured_sticker_sets_failed(Status error);
vector<int64> get_attached_sticker_sets(FileId file_id, Promise<Unit> &&promise); vector<StickerSetId> get_attached_sticker_sets(FileId file_id, Promise<Unit> &&promise);
void on_get_attached_sticker_sets(FileId file_id, void on_get_attached_sticker_sets(FileId file_id,
vector<tl_object_ptr<telegram_api::StickerSetCovered>> &&sticker_sets); vector<tl_object_ptr<telegram_api::StickerSetCovered>> &&sticker_sets);
void reorder_installed_sticker_sets(bool is_masks, const vector<int64> &sticker_set_ids, Promise<Unit> &&promise); void reorder_installed_sticker_sets(bool is_masks, const vector<StickerSetId> &sticker_set_ids,
Promise<Unit> &&promise);
FileId upload_sticker_file(UserId user_id, const tl_object_ptr<td_api::InputFile> &sticker, Promise<Unit> &&promise); FileId upload_sticker_file(UserId user_id, const tl_object_ptr<td_api::InputFile> &sticker, Promise<Unit> &&promise);
@ -201,7 +207,7 @@ class StickersManager : public Actor {
td_api::object_ptr<td_api::httpUrl> get_emoji_suggestions_url_result(int64 random_id); td_api::object_ptr<td_api::httpUrl> get_emoji_suggestions_url_result(int64 random_id);
void reload_sticker_set(int64 sticker_set_id, int64 access_hash, Promise<Unit> &&promise); void reload_sticker_set(StickerSetId sticker_set_id, int64 access_hash, Promise<Unit> &&promise);
void reload_installed_sticker_sets(bool is_masks, bool force); void reload_installed_sticker_sets(bool is_masks, bool force);
@ -246,10 +252,10 @@ class StickersManager : public Actor {
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const; void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
template <class StorerT> template <class StorerT>
void store_sticker_set_id(int64 sticker_set_id, StorerT &storer) const; void store_sticker_set_id(StickerSetId sticker_set_id, StorerT &storer) const;
template <class ParserT> template <class ParserT>
void parse_sticker_set_id(int64 &sticker_set_id, ParserT &parser); void parse_sticker_set_id(StickerSetId &sticker_set_id, ParserT &parser);
private: private:
static constexpr int32 MAX_FEATURED_STICKER_SET_VIEW_DELAY = 5; static constexpr int32 MAX_FEATURED_STICKER_SET_VIEW_DELAY = 5;
@ -263,7 +269,7 @@ class StickersManager : public Actor {
class Sticker { class Sticker {
public: public:
int64 set_id = 0; StickerSetId set_id;
string alt; string alt;
Dimensions dimensions; Dimensions dimensions;
PhotoSize s_thumbnail; PhotoSize s_thumbnail;
@ -285,7 +291,7 @@ class StickersManager : public Actor {
bool was_loaded = false; bool was_loaded = false;
bool is_loaded = false; bool is_loaded = false;
int64 id = 0; StickerSetId id;
int64 access_hash = 0; int64 access_hash = 0;
string title; string title;
string short_name; string short_name;
@ -337,56 +343,58 @@ class StickersManager : public Actor {
static tl_object_ptr<td_api::MaskPoint> get_mask_point_object(int32 point); static tl_object_ptr<td_api::MaskPoint> get_mask_point_object(int32 point);
tl_object_ptr<td_api::stickerSetInfo> get_sticker_set_info_object(int64 sticker_set_id, size_t covers_limit) const; tl_object_ptr<td_api::stickerSetInfo> get_sticker_set_info_object(StickerSetId sticker_set_id,
size_t covers_limit) const;
Sticker *get_sticker(FileId file_id); Sticker *get_sticker(FileId file_id);
const Sticker *get_sticker(FileId file_id) const; const Sticker *get_sticker(FileId file_id) const;
FileId on_get_sticker(unique_ptr<Sticker> new_sticker, bool replace); FileId on_get_sticker(unique_ptr<Sticker> new_sticker, bool replace);
StickerSet *get_sticker_set(int64 sticker_set_id); StickerSet *get_sticker_set(StickerSetId sticker_set_id);
const StickerSet *get_sticker_set(int64 sticker_set_id) const; const StickerSet *get_sticker_set(StickerSetId sticker_set_id) const;
StickerSet *add_sticker_set(int64 sticker_set_id, int64 access_hash); StickerSet *add_sticker_set(StickerSetId sticker_set_id, int64 access_hash);
std::pair<int64, FileId> on_get_sticker_document(tl_object_ptr<telegram_api::Document> &&document_ptr); std::pair<int64, FileId> on_get_sticker_document(tl_object_ptr<telegram_api::Document> &&document_ptr);
static tl_object_ptr<telegram_api::InputStickerSet> get_input_sticker_set(const StickerSet *set); static tl_object_ptr<telegram_api::InputStickerSet> get_input_sticker_set(const StickerSet *set);
int64 on_get_input_sticker_set(FileId sticker_file_id, tl_object_ptr<telegram_api::InputStickerSet> &&set_ptr, StickerSetId on_get_input_sticker_set(FileId sticker_file_id, tl_object_ptr<telegram_api::InputStickerSet> &&set_ptr,
MultiPromiseActor *load_data_multipromise_ptr = nullptr); MultiPromiseActor *load_data_multipromise_ptr = nullptr);
void on_resolve_sticker_set_short_name(FileId sticker_file_id, const string &short_name); void on_resolve_sticker_set_short_name(FileId sticker_file_id, const string &short_name);
int apply_installed_sticker_sets_order(bool is_masks, const vector<int64> &sticker_set_ids); int apply_installed_sticker_sets_order(bool is_masks, const vector<StickerSetId> &sticker_set_ids);
void on_update_sticker_set(StickerSet *sticker_set, bool is_installed, bool is_archived, bool is_changed, void on_update_sticker_set(StickerSet *sticker_set, bool is_installed, bool is_archived, bool is_changed,
bool from_database = false); bool from_database = false);
static string get_sticker_set_database_key(int64 set_id); static string get_sticker_set_database_key(StickerSetId set_id);
static string get_full_sticker_set_database_key(int64 set_id); static string get_full_sticker_set_database_key(StickerSetId set_id);
string get_sticker_set_database_value(const StickerSet *s, bool with_stickers); string get_sticker_set_database_value(const StickerSet *s, bool with_stickers);
void update_sticker_set(StickerSet *sticker_set); void update_sticker_set(StickerSet *sticker_set);
void load_sticker_sets(vector<int64> &&sticker_set_ids, Promise<Unit> &&promise); void load_sticker_sets(vector<StickerSetId> &&sticker_set_ids, Promise<Unit> &&promise);
void load_sticker_sets_without_stickers(vector<int64> &&sticker_set_ids, Promise<Unit> &&promise); void load_sticker_sets_without_stickers(vector<StickerSetId> &&sticker_set_ids, Promise<Unit> &&promise);
void on_load_sticker_set_from_database(int64 sticker_set_id, bool with_stickers, string value); void on_load_sticker_set_from_database(StickerSetId sticker_set_id, bool with_stickers, string value);
void update_load_requests(StickerSet *sticker_set, bool with_stickers, const Status &status); void update_load_requests(StickerSet *sticker_set, bool with_stickers, const Status &status);
void update_load_request(uint32 load_request_id, const Status &status); void update_load_request(uint32 load_request_id, const Status &status);
void do_reload_sticker_set(int64 sticker_set_id, tl_object_ptr<telegram_api::InputStickerSet> &&input_sticker_set, void do_reload_sticker_set(StickerSetId sticker_set_id,
tl_object_ptr<telegram_api::InputStickerSet> &&input_sticker_set,
Promise<Unit> &&promise) const; Promise<Unit> &&promise) const;
static void read_featured_sticker_sets(void *td_void); static void read_featured_sticker_sets(void *td_void);
int32 get_sticker_sets_hash(const vector<int64> &sticker_set_ids) const; int32 get_sticker_sets_hash(const vector<StickerSetId> &sticker_set_ids) const;
int32 get_featured_sticker_sets_hash() const; int32 get_featured_sticker_sets_hash() const;
@ -400,12 +408,12 @@ class StickersManager : public Actor {
void on_load_installed_sticker_sets_from_database(bool is_masks, string value); void on_load_installed_sticker_sets_from_database(bool is_masks, string value);
void on_load_installed_sticker_sets_finished(bool is_masks, vector<int64> &&installed_sticker_set_ids, void on_load_installed_sticker_sets_finished(bool is_masks, vector<StickerSetId> &&installed_sticker_set_ids,
bool from_database = false); bool from_database = false);
void on_load_featured_sticker_sets_from_database(string value); void on_load_featured_sticker_sets_from_database(string value);
void on_load_featured_sticker_sets_finished(vector<int64> &&featured_sticker_set_ids); void on_load_featured_sticker_sets_finished(vector<StickerSetId> &&featured_sticker_set_ids);
void on_load_recent_stickers_from_database(bool is_attached, string value); void on_load_recent_stickers_from_database(bool is_attached, string value);
@ -520,12 +528,12 @@ class StickersManager : public Actor {
Td *td_; Td *td_;
ActorShared<> parent_; ActorShared<> parent_;
std::unordered_map<FileId, unique_ptr<Sticker>, FileIdHash> stickers_; // file_id -> Sticker std::unordered_map<FileId, unique_ptr<Sticker>, FileIdHash> stickers_; // file_id -> Sticker
std::unordered_map<int64, unique_ptr<StickerSet>> sticker_sets_; // id -> StickerSet std::unordered_map<StickerSetId, unique_ptr<StickerSet>, StickerSetIdHash> sticker_sets_; // id -> StickerSet
std::unordered_map<string, int64> short_name_to_sticker_set_id_; std::unordered_map<string, StickerSetId> short_name_to_sticker_set_id_;
vector<int64> installed_sticker_set_ids_[2]; vector<StickerSetId> installed_sticker_set_ids_[2];
vector<int64> featured_sticker_set_ids_; vector<StickerSetId> featured_sticker_set_ids_;
vector<FileId> recent_sticker_ids_[2]; vector<FileId> recent_sticker_ids_[2];
vector<FileId> favorite_sticker_ids_; vector<FileId> favorite_sticker_ids_;
@ -559,20 +567,20 @@ class StickersManager : public Actor {
vector<FileId> favorite_sticker_file_ids_; vector<FileId> favorite_sticker_file_ids_;
FileSourceId favorite_stickers_file_source_id_; FileSourceId favorite_stickers_file_source_id_;
vector<int64> archived_sticker_set_ids_[2]; vector<StickerSetId> archived_sticker_set_ids_[2];
int32 total_archived_sticker_set_count_[2] = {-1, -1}; int32 total_archived_sticker_set_count_[2] = {-1, -1};
std::unordered_map<FileId, vector<int64>, FileIdHash> attached_sticker_sets_; std::unordered_map<FileId, vector<StickerSetId>, FileIdHash> attached_sticker_sets_;
Hints installed_sticker_sets_hints_[2]; // search installed sticker sets by their title and name Hints installed_sticker_sets_hints_[2]; // search installed sticker sets by their title and name
std::unordered_map<string, vector<FileId>> found_stickers_; std::unordered_map<string, vector<FileId>> found_stickers_;
std::unordered_map<string, vector<Promise<Unit>>> search_stickers_queries_; std::unordered_map<string, vector<Promise<Unit>>> search_stickers_queries_;
std::unordered_map<string, vector<int64>> found_sticker_sets_; std::unordered_map<string, vector<StickerSetId>> found_sticker_sets_;
std::unordered_map<string, vector<Promise<Unit>>> search_sticker_sets_queries_; std::unordered_map<string, vector<Promise<Unit>>> search_sticker_sets_queries_;
std::unordered_set<int64> pending_viewed_featured_sticker_set_ids_; std::unordered_set<StickerSetId, StickerSetIdHash> pending_viewed_featured_sticker_set_ids_;
Timeout pending_featured_sticker_set_views_timeout_; Timeout pending_featured_sticker_set_views_timeout_;
int32 recent_stickers_limit_ = 200; int32 recent_stickers_limit_ = 200;

View File

@ -25,7 +25,7 @@ void StickersManager::store_sticker(FileId file_id, bool in_sticker_set, StorerT
auto it = stickers_.find(file_id); auto it = stickers_.find(file_id);
CHECK(it != stickers_.end()); CHECK(it != stickers_.end());
const Sticker *sticker = it->second.get(); const Sticker *sticker = it->second.get();
bool has_sticker_set_access_hash = sticker->set_id != 0 && !in_sticker_set; bool has_sticker_set_access_hash = sticker->set_id.is_valid() && !in_sticker_set;
BEGIN_STORE_FLAGS(); BEGIN_STORE_FLAGS();
STORE_FLAG(sticker->is_mask); STORE_FLAG(sticker->is_mask);
STORE_FLAG(has_sticker_set_access_hash); STORE_FLAG(has_sticker_set_access_hash);
@ -33,7 +33,7 @@ void StickersManager::store_sticker(FileId file_id, bool in_sticker_set, StorerT
STORE_FLAG(sticker->is_animated); STORE_FLAG(sticker->is_animated);
END_STORE_FLAGS(); END_STORE_FLAGS();
if (!in_sticker_set) { if (!in_sticker_set) {
store(sticker->set_id, storer); store(sticker->set_id.get(), storer);
if (has_sticker_set_access_hash) { if (has_sticker_set_access_hash) {
auto sticker_set = get_sticker_set(sticker->set_id); auto sticker_set = get_sticker_set(sticker->set_id);
CHECK(sticker_set != nullptr); CHECK(sticker_set != nullptr);
@ -81,14 +81,16 @@ FileId StickersManager::parse_sticker(bool in_sticker_set, ParserT &parser) {
return FileId(); return FileId();
} }
if (!in_sticker_set) { if (!in_sticker_set) {
parse(sticker->set_id, parser); int64 set_id;
parse(set_id, parser);
sticker->set_id = StickerSetId(set_id);
if (has_sticker_set_access_hash) { if (has_sticker_set_access_hash) {
int64 sticker_set_access_hash; int64 sticker_set_access_hash;
parse(sticker_set_access_hash, parser); parse(sticker_set_access_hash, parser);
add_sticker_set(sticker->set_id, sticker_set_access_hash); add_sticker_set(sticker->set_id, sticker_set_access_hash);
} else { } else {
// backward compatibility // backward compatibility
sticker->set_id = 0; sticker->set_id = StickerSetId();
} }
} }
parse(sticker->alt, parser); parse(sticker->alt, parser);
@ -133,7 +135,7 @@ void StickersManager::store_sticker_set(const StickerSet *sticker_set, bool with
STORE_FLAG(sticker_set->is_thumbnail_reloaded); STORE_FLAG(sticker_set->is_thumbnail_reloaded);
STORE_FLAG(sticker_set->is_animated); STORE_FLAG(sticker_set->is_animated);
END_STORE_FLAGS(); END_STORE_FLAGS();
store(sticker_set->id, storer); store(sticker_set->id.get(), storer);
store(sticker_set->access_hash, storer); store(sticker_set->access_hash, storer);
if (sticker_set->is_inited) { if (sticker_set->is_inited) {
store(sticker_set->title, storer); store(sticker_set->title, storer);
@ -195,9 +197,9 @@ void StickersManager::parse_sticker_set(StickerSet *sticker_set, ParserT &parser
int64 access_hash; int64 access_hash;
parse(sticker_set_id, parser); parse(sticker_set_id, parser);
parse(access_hash, parser); parse(access_hash, parser);
CHECK(sticker_set->id == sticker_set_id); CHECK(sticker_set->id.get() == sticker_set_id);
if (sticker_set->access_hash != access_hash) { if (sticker_set->access_hash != access_hash) {
LOG(ERROR) << "Sticker set " << sticker_set_id << " access hash has changed from " << access_hash << " to " LOG(ERROR) << "Access hash of " << sticker_set_id << " has changed from " << access_hash << " to "
<< sticker_set->access_hash; << sticker_set->access_hash;
} }
@ -231,21 +233,21 @@ void StickersManager::parse_sticker_set(StickerSet *sticker_set, ParserT &parser
on_update_sticker_set(sticker_set, is_installed, is_archived, false, true); on_update_sticker_set(sticker_set, is_installed, is_archived, false, true);
} else { } else {
if (sticker_set->title != title) { if (sticker_set->title != title) {
LOG(INFO) << "Sticker set " << sticker_set_id << " title has changed"; LOG(INFO) << "Title of " << sticker_set_id << " has changed";
} }
if (sticker_set->short_name != short_name) { if (sticker_set->short_name != short_name) {
LOG(ERROR) << "Sticker set " << sticker_set_id << " short name has changed from \"" << short_name << "\" to \"" LOG(ERROR) << "Short name of " << sticker_set_id << " has changed from \"" << short_name << "\" to \""
<< sticker_set->short_name << "\""; << sticker_set->short_name << "\"";
} }
if (sticker_set->sticker_count != sticker_count || sticker_set->hash != hash) { if (sticker_set->sticker_count != sticker_count || sticker_set->hash != hash) {
sticker_set->is_loaded = false; sticker_set->is_loaded = false;
} }
if (sticker_set->is_animated != is_animated) { if (sticker_set->is_animated != is_animated) {
LOG(ERROR) << "Sticker set " << sticker_set_id << " is_animated has changed from \"" << is_animated LOG(ERROR) << "Is animated of " << sticker_set_id << " has changed from \"" << is_animated << "\" to \""
<< "\" to \"" << sticker_set->is_animated << "\""; << sticker_set->is_animated << "\"";
} }
if (sticker_set->is_masks != is_masks) { if (sticker_set->is_masks != is_masks) {
LOG(ERROR) << "Sticker set " << sticker_set_id << " is_masks has changed from \"" << is_masks << "\" to \"" LOG(ERROR) << "Is masks of " << sticker_set_id << " has changed from \"" << is_masks << "\" to \""
<< sticker_set->is_masks << "\""; << sticker_set->is_masks << "\"";
} }
} }
@ -270,7 +272,7 @@ void StickersManager::parse_sticker_set(StickerSet *sticker_set, ParserT &parser
Sticker *sticker = get_sticker(sticker_id); Sticker *sticker = get_sticker(sticker_id);
CHECK(sticker != nullptr); CHECK(sticker != nullptr);
if (sticker->set_id != sticker_set->id) { if (sticker->set_id != sticker_set->id) {
LOG_IF(ERROR, sticker->set_id != 0) << "Sticker " << sticker_id << " set_id has changed"; LOG_IF(ERROR, sticker->set_id.is_valid()) << "Sticker " << sticker_id << " set_id has changed";
sticker->set_id = sticker_set->id; sticker->set_id = sticker_set->id;
sticker->is_changed = true; sticker->is_changed = true;
} }
@ -294,17 +296,19 @@ void StickersManager::parse_sticker_set(StickerSet *sticker_set, ParserT &parser
} }
template <class StorerT> template <class StorerT>
void StickersManager::store_sticker_set_id(int64 sticker_set_id, StorerT &storer) const { void StickersManager::store_sticker_set_id(StickerSetId sticker_set_id, StorerT &storer) const {
CHECK(sticker_set_id != 0); CHECK(sticker_set_id.is_valid());
const StickerSet *sticker_set = get_sticker_set(sticker_set_id); const StickerSet *sticker_set = get_sticker_set(sticker_set_id);
CHECK(sticker_set != nullptr); CHECK(sticker_set != nullptr);
store(sticker_set_id, storer); store(sticker_set_id.get(), storer);
store(sticker_set->access_hash, storer); store(sticker_set->access_hash, storer);
} }
template <class ParserT> template <class ParserT>
void StickersManager::parse_sticker_set_id(int64 &sticker_set_id, ParserT &parser) { void StickersManager::parse_sticker_set_id(StickerSetId &sticker_set_id, ParserT &parser) {
parse(sticker_set_id, parser); int64 set_id;
parse(set_id, parser);
sticker_set_id = StickerSetId(set_id);
int64 sticker_set_access_hash; int64 sticker_set_access_hash;
parse(sticker_set_access_hash, parser); parse(sticker_set_access_hash, parser);
add_sticker_set(sticker_set_id, sticker_set_access_hash); add_sticker_set(sticker_set_id, sticker_set_access_hash);

View File

@ -71,6 +71,7 @@
#include "td/telegram/SecureManager.h" #include "td/telegram/SecureManager.h"
#include "td/telegram/SecureValue.h" #include "td/telegram/SecureValue.h"
#include "td/telegram/StateManager.h" #include "td/telegram/StateManager.h"
#include "td/telegram/StickerSetId.h"
#include "td/telegram/StickersManager.h" #include "td/telegram/StickersManager.h"
#include "td/telegram/StorageManager.h" #include "td/telegram/StorageManager.h"
#include "td/telegram/TdDb.h" #include "td/telegram/TdDb.h"
@ -235,12 +236,12 @@ class GetRecentMeUrlsQuery : public Td::ResultHandler {
auto url = move_tl_object_as<telegram_api::recentMeUrlStickerSet>(url_ptr); auto url = move_tl_object_as<telegram_api::recentMeUrlStickerSet>(url_ptr);
result->url_ = std::move(url->url_); result->url_ = std::move(url->url_);
auto sticker_set_id = td->stickers_manager_->on_get_sticker_set_covered(std::move(url->set_), false); auto sticker_set_id = td->stickers_manager_->on_get_sticker_set_covered(std::move(url->set_), false);
if (sticker_set_id == 0) { if (!sticker_set_id.is_valid()) {
LOG(ERROR) << "Receive invalid sticker set"; LOG(ERROR) << "Receive invalid sticker set";
result = nullptr; result = nullptr;
break; break;
} }
result->type_ = make_tl_object<td_api::tMeUrlTypeStickerSet>(sticker_set_id); result->type_ = make_tl_object<td_api::tMeUrlTypeStickerSet>(sticker_set_id.get());
break; break;
} }
case telegram_api::recentMeUrlUnknown::ID: case telegram_api::recentMeUrlUnknown::ID:
@ -2387,7 +2388,7 @@ class SearchStickersRequest : public RequestActor<> {
class GetInstalledStickerSetsRequest : public RequestActor<> { class GetInstalledStickerSetsRequest : public RequestActor<> {
bool is_masks_; bool is_masks_;
vector<int64> sticker_set_ids_; vector<StickerSetId> sticker_set_ids_;
void do_run(Promise<Unit> &&promise) override { void do_run(Promise<Unit> &&promise) override {
sticker_set_ids_ = td->stickers_manager_->get_installed_sticker_sets(is_masks_, std::move(promise)); sticker_set_ids_ = td->stickers_manager_->get_installed_sticker_sets(is_masks_, std::move(promise));
@ -2405,11 +2406,11 @@ class GetInstalledStickerSetsRequest : public RequestActor<> {
class GetArchivedStickerSetsRequest : public RequestActor<> { class GetArchivedStickerSetsRequest : public RequestActor<> {
bool is_masks_; bool is_masks_;
int64 offset_sticker_set_id_; StickerSetId offset_sticker_set_id_;
int32 limit_; int32 limit_;
int32 total_count_; int32 total_count_;
vector<int64> sticker_set_ids_; vector<StickerSetId> sticker_set_ids_;
void do_run(Promise<Unit> &&promise) override { void do_run(Promise<Unit> &&promise) override {
std::tie(total_count_, sticker_set_ids_) = td->stickers_manager_->get_archived_sticker_sets( std::tie(total_count_, sticker_set_ids_) = td->stickers_manager_->get_archived_sticker_sets(
@ -2431,7 +2432,7 @@ class GetArchivedStickerSetsRequest : public RequestActor<> {
}; };
class GetTrendingStickerSetsRequest : public RequestActor<> { class GetTrendingStickerSetsRequest : public RequestActor<> {
vector<int64> sticker_set_ids_; vector<StickerSetId> sticker_set_ids_;
void do_run(Promise<Unit> &&promise) override { void do_run(Promise<Unit> &&promise) override {
sticker_set_ids_ = td->stickers_manager_->get_featured_sticker_sets(std::move(promise)); sticker_set_ids_ = td->stickers_manager_->get_featured_sticker_sets(std::move(promise));
@ -2449,7 +2450,7 @@ class GetTrendingStickerSetsRequest : public RequestActor<> {
class GetAttachedStickerSetsRequest : public RequestActor<> { class GetAttachedStickerSetsRequest : public RequestActor<> {
FileId file_id_; FileId file_id_;
vector<int64> sticker_set_ids_; vector<StickerSetId> sticker_set_ids_;
void do_run(Promise<Unit> &&promise) override { void do_run(Promise<Unit> &&promise) override {
sticker_set_ids_ = td->stickers_manager_->get_attached_sticker_sets(file_id_, std::move(promise)); sticker_set_ids_ = td->stickers_manager_->get_attached_sticker_sets(file_id_, std::move(promise));
@ -2466,9 +2467,9 @@ class GetAttachedStickerSetsRequest : public RequestActor<> {
}; };
class GetStickerSetRequest : public RequestActor<> { class GetStickerSetRequest : public RequestActor<> {
int64 set_id_; StickerSetId set_id_;
int64 sticker_set_id_; StickerSetId sticker_set_id_;
void do_run(Promise<Unit> &&promise) override { void do_run(Promise<Unit> &&promise) override {
sticker_set_id_ = td->stickers_manager_->get_sticker_set(set_id_, std::move(promise)); sticker_set_id_ = td->stickers_manager_->get_sticker_set(set_id_, std::move(promise));
@ -2488,7 +2489,7 @@ class GetStickerSetRequest : public RequestActor<> {
class SearchStickerSetRequest : public RequestActor<> { class SearchStickerSetRequest : public RequestActor<> {
string name_; string name_;
int64 sticker_set_id_; StickerSetId sticker_set_id_;
void do_run(Promise<Unit> &&promise) override { void do_run(Promise<Unit> &&promise) override {
sticker_set_id_ = td->stickers_manager_->search_sticker_set(name_, std::move(promise)); sticker_set_id_ = td->stickers_manager_->search_sticker_set(name_, std::move(promise));
@ -2510,7 +2511,7 @@ class SearchInstalledStickerSetsRequest : public RequestActor<> {
string query_; string query_;
int32 limit_; int32 limit_;
std::pair<int32, vector<int64>> sticker_set_ids_; std::pair<int32, vector<StickerSetId>> sticker_set_ids_;
void do_run(Promise<Unit> &&promise) override { void do_run(Promise<Unit> &&promise) override {
sticker_set_ids_ = sticker_set_ids_ =
@ -2530,7 +2531,7 @@ class SearchInstalledStickerSetsRequest : public RequestActor<> {
class SearchStickerSetsRequest : public RequestActor<> { class SearchStickerSetsRequest : public RequestActor<> {
string query_; string query_;
vector<int64> sticker_set_ids_; vector<StickerSetId> sticker_set_ids_;
void do_run(Promise<Unit> &&promise) override { void do_run(Promise<Unit> &&promise) override {
sticker_set_ids_ = td->stickers_manager_->search_sticker_sets(query_, std::move(promise)); sticker_set_ids_ = td->stickers_manager_->search_sticker_sets(query_, std::move(promise));
@ -2547,7 +2548,7 @@ class SearchStickerSetsRequest : public RequestActor<> {
}; };
class ChangeStickerSetRequest : public RequestOnceActor { class ChangeStickerSetRequest : public RequestOnceActor {
int64 set_id_; StickerSetId set_id_;
bool is_installed_; bool is_installed_;
bool is_archived_; bool is_archived_;
@ -2600,7 +2601,7 @@ class CreateNewStickerSetRequest : public RequestOnceActor {
void do_send_result() override { void do_send_result() override {
auto set_id = td->stickers_manager_->search_sticker_set(name_, Auto()); auto set_id = td->stickers_manager_->search_sticker_set(name_, Auto());
if (set_id == 0) { if (!set_id.is_valid()) {
return send_error(Status::Error(500, "Created sticker set not found")); return send_error(Status::Error(500, "Created sticker set not found"));
} }
send_result(td->stickers_manager_->get_sticker_set_object(set_id)); send_result(td->stickers_manager_->get_sticker_set_object(set_id));
@ -2629,7 +2630,7 @@ class AddStickerToSetRequest : public RequestOnceActor {
void do_send_result() override { void do_send_result() override {
auto set_id = td->stickers_manager_->search_sticker_set(name_, Auto()); auto set_id = td->stickers_manager_->search_sticker_set(name_, Auto());
if (set_id == 0) { if (!set_id.is_valid()) {
return send_error(Status::Error(500, "Sticker set not found")); return send_error(Status::Error(500, "Sticker set not found"));
} }
send_result(td->stickers_manager_->get_sticker_set_object(set_id)); send_result(td->stickers_manager_->get_sticker_set_object(set_id));
@ -6435,7 +6436,7 @@ void Td::on_request(uint64 id, td_api::setSupergroupUsername &request) {
void Td::on_request(uint64 id, const td_api::setSupergroupStickerSet &request) { void Td::on_request(uint64 id, const td_api::setSupergroupStickerSet &request) {
CREATE_OK_REQUEST_PROMISE(); CREATE_OK_REQUEST_PROMISE();
contacts_manager_->set_channel_sticker_set(ChannelId(request.supergroup_id_), request.sticker_set_id_, contacts_manager_->set_channel_sticker_set(ChannelId(request.supergroup_id_), StickerSetId(request.sticker_set_id_),
std::move(promise)); std::move(promise));
} }
@ -6535,14 +6536,15 @@ void Td::on_request(uint64 id, const td_api::changeStickerSet &request) {
void Td::on_request(uint64 id, const td_api::viewTrendingStickerSets &request) { void Td::on_request(uint64 id, const td_api::viewTrendingStickerSets &request) {
CHECK_IS_USER(); CHECK_IS_USER();
stickers_manager_->view_featured_sticker_sets(request.sticker_set_ids_); stickers_manager_->view_featured_sticker_sets(StickersManager::convert_sticker_set_ids(request.sticker_set_ids_));
send_closure(actor_id(this), &Td::send_result, id, make_tl_object<td_api::ok>()); send_closure(actor_id(this), &Td::send_result, id, make_tl_object<td_api::ok>());
} }
void Td::on_request(uint64 id, td_api::reorderInstalledStickerSets &request) { void Td::on_request(uint64 id, td_api::reorderInstalledStickerSets &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE(); CREATE_OK_REQUEST_PROMISE();
stickers_manager_->reorder_installed_sticker_sets(request.is_masks_, request.sticker_set_ids_, std::move(promise)); stickers_manager_->reorder_installed_sticker_sets(
request.is_masks_, StickersManager::convert_sticker_set_ids(request.sticker_set_ids_), std::move(promise));
} }
void Td::on_request(uint64 id, td_api::uploadStickerFile &request) { void Td::on_request(uint64 id, td_api::uploadStickerFile &request) {

View File

@ -1822,7 +1822,7 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePrivacy> update
} }
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateNewStickerSet> update, bool /*force_apply*/) { void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateNewStickerSet> update, bool /*force_apply*/) {
td_->stickers_manager_->on_get_messages_sticker_set(0, std::move(update->stickerset_), true); td_->stickers_manager_->on_get_messages_sticker_set(StickerSetId(), std::move(update->stickerset_), true);
} }
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateStickerSets> update, bool /*force_apply*/) { void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateStickerSets> update, bool /*force_apply*/) {
@ -1831,7 +1831,8 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateStickerSets> up
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateStickerSetsOrder> update, bool /*force_apply*/) { void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateStickerSetsOrder> update, bool /*force_apply*/) {
bool is_masks = (update->flags_ & telegram_api::updateStickerSetsOrder::MASKS_MASK) != 0; bool is_masks = (update->flags_ & telegram_api::updateStickerSetsOrder::MASKS_MASK) != 0;
td_->stickers_manager_->on_update_sticker_sets_order(is_masks, update->order_); td_->stickers_manager_->on_update_sticker_sets_order(is_masks,
StickersManager::convert_sticker_set_ids(update->order_));
} }
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadFeaturedStickers> update, bool /*force_apply*/) { void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadFeaturedStickers> update, bool /*force_apply*/) {