Make StickeerPhotoSize fields private.

This commit is contained in:
levlam 2023-01-23 13:02:10 +03:00
parent fac51c9819
commit 7d2442f57f
5 changed files with 55 additions and 48 deletions

View File

@ -486,7 +486,8 @@ class UploadProfilePhotoQuery final : public Td::ResultHandler {
if (is_fallback) { if (is_fallback) {
flags |= telegram_api::photos_uploadProfilePhoto::FALLBACK_MASK; flags |= telegram_api::photos_uploadProfilePhoto::FALLBACK_MASK;
} }
auto video_emoji_markup = get_input_video_size_object(td_, sticker_photo_size); auto video_emoji_markup =
sticker_photo_size != nullptr ? sticker_photo_size->get_input_video_size_object(td_) : nullptr;
if (video_emoji_markup != nullptr) { if (video_emoji_markup != nullptr) {
flags |= telegram_api::photos_uploadProfilePhoto::VIDEO_EMOJI_MARKUP_MASK; flags |= telegram_api::photos_uploadProfilePhoto::VIDEO_EMOJI_MARKUP_MASK;
} }
@ -7116,7 +7117,7 @@ void ContactsManager::set_profile_photo_impl(UserId user_id,
return promise.set_error(Status::Error(400, "Wrong main frame timestamp specified")); return promise.set_error(Status::Error(400, "Wrong main frame timestamp specified"));
} }
TRY_RESULT_PROMISE(promise, sticker_photo_size, get_sticker_photo_size(td_, sticker)); TRY_RESULT_PROMISE(promise, sticker_photo_size, StickerPhotoSize::get_sticker_photo_size(td_, sticker));
auto file_type = is_animation ? FileType::Animation : FileType::Photo; auto file_type = is_animation ? FileType::Animation : FileType::Photo;
auto r_file_id = td_->file_manager_->get_input_file_id(file_type, *input_file, DialogId(user_id), false, false); auto r_file_id = td_->file_manager_->get_input_file_id(file_type, *input_file, DialogId(user_id), false, false);

View File

@ -308,7 +308,7 @@ Variant<AnimationSize, unique_ptr<StickerPhotoSize>> process_video_size(
} }
case telegram_api::videoSizeEmojiMarkup::ID: case telegram_api::videoSizeEmojiMarkup::ID:
case telegram_api::videoSizeStickerMarkup::ID: { case telegram_api::videoSizeStickerMarkup::ID: {
auto sticker_photo_size = get_sticker_photo_size(td, std::move(size_ptr)); auto sticker_photo_size = StickerPhotoSize::get_sticker_photo_size(td, std::move(size_ptr));
if (sticker_photo_size == nullptr) { if (sticker_photo_size == nullptr) {
return {}; return {};
} }

View File

@ -11,7 +11,7 @@
namespace td { namespace td {
Result<unique_ptr<StickerPhotoSize>> get_sticker_photo_size( Result<unique_ptr<StickerPhotoSize>> StickerPhotoSize::get_sticker_photo_size(
Td *td, const td_api::object_ptr<td_api::chatPhotoSticker> &sticker) { Td *td, const td_api::object_ptr<td_api::chatPhotoSticker> &sticker) {
if (sticker == nullptr) { if (sticker == nullptr) {
return nullptr; return nullptr;
@ -26,7 +26,7 @@ Result<unique_ptr<StickerPhotoSize>> get_sticker_photo_size(
switch (sticker->type_->get_id()) { switch (sticker->type_->get_id()) {
case td_api::chatPhotoStickerTypeRegularOrMask::ID: { case td_api::chatPhotoStickerTypeRegularOrMask::ID: {
auto type = static_cast<const td_api::chatPhotoStickerTypeRegularOrMask *>(sticker->type_.get()); auto type = static_cast<const td_api::chatPhotoStickerTypeRegularOrMask *>(sticker->type_.get());
result->type_ = StickerPhotoSize::Type::Sticker; result->type_ = Type::Sticker;
result->sticker_set_id_ = StickerSetId(type->sticker_set_id_); result->sticker_set_id_ = StickerSetId(type->sticker_set_id_);
result->sticker_id_ = type->sticker_id_; result->sticker_id_ = type->sticker_id_;
if (!td->stickers_manager_->have_sticker(result->sticker_set_id_, result->sticker_id_)) { if (!td->stickers_manager_->have_sticker(result->sticker_set_id_, result->sticker_id_)) {
@ -36,7 +36,7 @@ Result<unique_ptr<StickerPhotoSize>> get_sticker_photo_size(
} }
case td_api::chatPhotoStickerTypeCustomEmoji::ID: { case td_api::chatPhotoStickerTypeCustomEmoji::ID: {
auto type = static_cast<const td_api::chatPhotoStickerTypeCustomEmoji *>(sticker->type_.get()); auto type = static_cast<const td_api::chatPhotoStickerTypeCustomEmoji *>(sticker->type_.get());
result->type_ = StickerPhotoSize::Type::CustomEmoji; result->type_ = Type::CustomEmoji;
result->custom_emoji_id_ = CustomEmojiId(type->custom_emoji_id_); result->custom_emoji_id_ = CustomEmojiId(type->custom_emoji_id_);
if (!td->stickers_manager_->have_custom_emoji(result->custom_emoji_id_)) { if (!td->stickers_manager_->have_custom_emoji(result->custom_emoji_id_)) {
return Status::Error(400, "Custom emoji not found"); return Status::Error(400, "Custom emoji not found");
@ -75,34 +75,30 @@ Result<unique_ptr<StickerPhotoSize>> get_sticker_photo_size(
return std::move(result); return std::move(result);
} }
telegram_api::object_ptr<telegram_api::VideoSize> get_input_video_size_object( telegram_api::object_ptr<telegram_api::VideoSize> StickerPhotoSize::get_input_video_size_object(Td *td) const {
Td *td, const unique_ptr<StickerPhotoSize> &sticker_photo_size) { switch (type_) {
if (sticker_photo_size == nullptr) { case Type::Sticker:
return nullptr;
}
switch (sticker_photo_size->type_) {
case StickerPhotoSize::Type::Sticker:
return telegram_api::make_object<telegram_api::videoSizeStickerMarkup>( return telegram_api::make_object<telegram_api::videoSizeStickerMarkup>(
td->stickers_manager_->get_input_sticker_set(sticker_photo_size->sticker_set_id_), td->stickers_manager_->get_input_sticker_set(sticker_set_id_), sticker_id_,
sticker_photo_size->sticker_id_, vector<int32>(sticker_photo_size->background_colors_)); vector<int32>(background_colors_));
case StickerPhotoSize::Type::CustomEmoji: case Type::CustomEmoji:
return telegram_api::make_object<telegram_api::videoSizeEmojiMarkup>( return telegram_api::make_object<telegram_api::videoSizeEmojiMarkup>(custom_emoji_id_.get(),
sticker_photo_size->custom_emoji_id_.get(), vector<int32>(sticker_photo_size->background_colors_)); vector<int32>(background_colors_));
default: default:
UNREACHABLE(); UNREACHABLE();
return nullptr; return nullptr;
} }
} }
unique_ptr<StickerPhotoSize> get_sticker_photo_size(Td *td, unique_ptr<StickerPhotoSize> StickerPhotoSize::get_sticker_photo_size(
telegram_api::object_ptr<telegram_api::VideoSize> &&size_ptr) { Td *td, telegram_api::object_ptr<telegram_api::VideoSize> &&size_ptr) {
CHECK(size_ptr != nullptr); CHECK(size_ptr != nullptr);
auto result = make_unique<StickerPhotoSize>(); auto result = make_unique<StickerPhotoSize>();
bool is_valid = false; bool is_valid = false;
switch (size_ptr->get_id()) { switch (size_ptr->get_id()) {
case telegram_api::videoSizeEmojiMarkup::ID: { case telegram_api::videoSizeEmojiMarkup::ID: {
auto size = move_tl_object_as<telegram_api::videoSizeEmojiMarkup>(size_ptr); auto size = move_tl_object_as<telegram_api::videoSizeEmojiMarkup>(size_ptr);
result->type_ = StickerPhotoSize::Type::CustomEmoji; result->type_ = Type::CustomEmoji;
result->custom_emoji_id_ = CustomEmojiId(size->emoji_id_); result->custom_emoji_id_ = CustomEmojiId(size->emoji_id_);
result->background_colors_ = std::move(size->background_colors_); result->background_colors_ = std::move(size->background_colors_);
is_valid = result->custom_emoji_id_.is_valid(); is_valid = result->custom_emoji_id_.is_valid();
@ -110,7 +106,7 @@ unique_ptr<StickerPhotoSize> get_sticker_photo_size(Td *td,
} }
case telegram_api::videoSizeStickerMarkup::ID: { case telegram_api::videoSizeStickerMarkup::ID: {
auto size = move_tl_object_as<telegram_api::videoSizeStickerMarkup>(size_ptr); auto size = move_tl_object_as<telegram_api::videoSizeStickerMarkup>(size_ptr);
result->type_ = StickerPhotoSize::Type::Sticker; result->type_ = Type::Sticker;
result->sticker_set_id_ = td->stickers_manager_->add_sticker_set(std::move(size->stickerset_)); result->sticker_set_id_ = td->stickers_manager_->add_sticker_set(std::move(size->stickerset_));
result->sticker_id_ = size->sticker_id_; result->sticker_id_ = size->sticker_id_;
result->background_colors_ = std::move(size->background_colors_); result->background_colors_ = std::move(size->background_colors_);
@ -133,10 +129,10 @@ unique_ptr<StickerPhotoSize> get_sticker_photo_size(Td *td,
td_api::object_ptr<td_api::chatPhotoSticker> StickerPhotoSize::get_chat_photo_sticker_object() const { td_api::object_ptr<td_api::chatPhotoSticker> StickerPhotoSize::get_chat_photo_sticker_object() const {
td_api::object_ptr<td_api::ChatPhotoStickerType> sticker_type; td_api::object_ptr<td_api::ChatPhotoStickerType> sticker_type;
switch (type_) { switch (type_) {
case StickerPhotoSize::Type::Sticker: case Type::Sticker:
sticker_type = td_api::make_object<td_api::chatPhotoStickerTypeRegularOrMask>(sticker_set_id_.get(), sticker_id_); sticker_type = td_api::make_object<td_api::chatPhotoStickerTypeRegularOrMask>(sticker_set_id_.get(), sticker_id_);
break; break;
case StickerPhotoSize::Type::CustomEmoji: case Type::CustomEmoji:
sticker_type = td_api::make_object<td_api::chatPhotoStickerTypeCustomEmoji>(custom_emoji_id_.get()); sticker_type = td_api::make_object<td_api::chatPhotoStickerTypeCustomEmoji>(custom_emoji_id_.get());
break; break;
default: default:

View File

@ -19,7 +19,7 @@ namespace td {
class Td; class Td;
struct StickerPhotoSize { class StickerPhotoSize {
enum class Type : int32 { Sticker, CustomEmoji }; enum class Type : int32 { Sticker, CustomEmoji };
Type type_ = Type::CustomEmoji; Type type_ = Type::CustomEmoji;
CustomEmojiId custom_emoji_id_; CustomEmojiId custom_emoji_id_;
@ -27,18 +27,28 @@ struct StickerPhotoSize {
int64 sticker_id_ = 0; int64 sticker_id_ = 0;
vector<int32> background_colors_; vector<int32> background_colors_;
friend bool operator==(const StickerPhotoSize &lhs, const StickerPhotoSize &rhs);
friend StringBuilder &operator<<(StringBuilder &string_builder, const StickerPhotoSize &sticker_photo_size);
public:
static Result<unique_ptr<StickerPhotoSize>> get_sticker_photo_size(
Td *td, const td_api::object_ptr<td_api::chatPhotoSticker> &chat_photo_sticker);
static unique_ptr<StickerPhotoSize> get_sticker_photo_size(
Td *td, telegram_api::object_ptr<telegram_api::VideoSize> &&size_ptr);
telegram_api::object_ptr<telegram_api::VideoSize> get_input_video_size_object(Td *td) const;
td_api::object_ptr<td_api::chatPhotoSticker> get_chat_photo_sticker_object() const; td_api::object_ptr<td_api::chatPhotoSticker> get_chat_photo_sticker_object() const;
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
}; };
Result<unique_ptr<StickerPhotoSize>> get_sticker_photo_size(
Td *td, const td_api::object_ptr<td_api::chatPhotoSticker> &chat_photo_sticker);
telegram_api::object_ptr<telegram_api::VideoSize> get_input_video_size_object(
Td *td, const unique_ptr<StickerPhotoSize> &sticker_photo_size);
unique_ptr<StickerPhotoSize> get_sticker_photo_size(Td *td,
telegram_api::object_ptr<telegram_api::VideoSize> &&size_ptr);
bool operator==(const StickerPhotoSize &lhs, const StickerPhotoSize &rhs); bool operator==(const StickerPhotoSize &lhs, const StickerPhotoSize &rhs);
bool operator!=(const StickerPhotoSize &lhs, const StickerPhotoSize &rhs); bool operator!=(const StickerPhotoSize &lhs, const StickerPhotoSize &rhs);

View File

@ -14,24 +14,24 @@
namespace td { namespace td {
template <class StorerT> template <class StorerT>
void store(const StickerPhotoSize &sticker_photo_size, StorerT &storer) { void StickerPhotoSize::store(StorerT &storer) const {
bool is_custom_emoji = sticker_photo_size.type_ == StickerPhotoSize::Type::CustomEmoji; bool is_custom_emoji = type_ == Type::CustomEmoji;
bool is_sticker = sticker_photo_size.type_ == StickerPhotoSize::Type::Sticker; bool is_sticker = type_ == Type::Sticker;
BEGIN_STORE_FLAGS(); BEGIN_STORE_FLAGS();
STORE_FLAG(is_custom_emoji); STORE_FLAG(is_custom_emoji);
STORE_FLAG(is_sticker); STORE_FLAG(is_sticker);
END_STORE_FLAGS(); END_STORE_FLAGS();
if (is_custom_emoji) { if (is_custom_emoji) {
store(sticker_photo_size.custom_emoji_id_, storer); td::store(custom_emoji_id_, storer);
} else if (is_sticker) { } else if (is_sticker) {
store(sticker_photo_size.sticker_set_id_, storer); td::store(sticker_set_id_, storer);
store(sticker_photo_size.sticker_id_, storer); td::store(sticker_id_, storer);
} }
store(sticker_photo_size.background_colors_, storer); td::store(background_colors_, storer);
} }
template <class ParserT> template <class ParserT>
void parse(StickerPhotoSize &sticker_photo_size, ParserT &parser) { void StickerPhotoSize::parse(ParserT &parser) {
bool is_custom_emoji; bool is_custom_emoji;
bool is_sticker; bool is_sticker;
BEGIN_PARSE_FLAGS(); BEGIN_PARSE_FLAGS();
@ -39,16 +39,16 @@ void parse(StickerPhotoSize &sticker_photo_size, ParserT &parser) {
PARSE_FLAG(is_sticker); PARSE_FLAG(is_sticker);
END_PARSE_FLAGS(); END_PARSE_FLAGS();
if (is_custom_emoji) { if (is_custom_emoji) {
sticker_photo_size.type_ = StickerPhotoSize::Type::CustomEmoji; type_ = Type::CustomEmoji;
parse(sticker_photo_size.custom_emoji_id_, parser); td::parse(custom_emoji_id_, parser);
} else if (is_sticker) { } else if (is_sticker) {
sticker_photo_size.type_ = StickerPhotoSize::Type::Sticker; type_ = Type::Sticker;
parse(sticker_photo_size.sticker_set_id_, parser); td::parse(sticker_set_id_, parser);
parse(sticker_photo_size.sticker_id_, parser); td::parse(sticker_id_, parser);
} else { } else {
UNREACHABLE(); UNREACHABLE();
} }
parse(sticker_photo_size.background_colors_, parser); td::parse(background_colors_, parser);
} }
} // namespace td } // namespace td