diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 158906eeb..37b1ba127 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -8158,6 +8158,19 @@ void StickersManager::on_new_stickers_uploaded(int64 random_id, Result res pending_new_sticker_set->has_text_color_, std::move(input_stickers), pending_new_sticker_set->software_); } +StickerFormat StickersManager::guess_sticker_set_format(const StickerSet *sticker_set) const { + auto format = StickerFormat::Unknown; + for (auto sticker_id : sticker_set->sticker_ids_) { + const auto *s = get_sticker(sticker_id); + if (format == StickerFormat::Unknown) { + format = s->format_; + } else if (format != s->format_) { + return StickerFormat::Unknown; + } + } + return format; +} + void StickersManager::add_sticker_to_set(UserId user_id, string short_name, td_api::object_ptr &&sticker, Promise &&promise) { TRY_RESULT_PROMISE(promise, input_user, td_->contacts_manager_->get_input_user(user_id)); @@ -8195,6 +8208,12 @@ void StickersManager::do_add_sticker_to_set(UserId user_id, string short_name, if (sticker_set == nullptr || !sticker_set->was_loaded_) { return promise.set_error(Status::Error(400, "Sticker set not found")); } + if (sticker != nullptr && sticker->format_ == nullptr) { + auto format = guess_sticker_set_format(sticker_set); + if (format != StickerFormat::Unknown) { + sticker->format_ = get_sticker_format_object(format); + } + } auto r_file_id = prepare_input_sticker(sticker.get(), sticker_set->sticker_type_); if (r_file_id.is_error()) { @@ -8292,6 +8311,9 @@ void StickersManager::do_set_sticker_set_thumbnail(UserId user_id, string short_ return promise.set_error( Status::Error(400, "The method can't be used to set thumbnail of custom emoji sticker sets")); } + if (format == StickerFormat::Unknown) { + format = guess_sticker_set_format(sticker_set); + } auto r_file_id = prepare_input_file(thumbnail, format, sticker_set->sticker_type_, true); if (r_file_id.is_error()) { diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index 663514a6c..a0282e882 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -812,6 +812,8 @@ class StickersManager final : public Actor { void on_added_sticker_uploaded(int64 random_id, Result result); + StickerFormat guess_sticker_set_format(const StickerSet *sticker_set) const; + void do_add_sticker_to_set(UserId user_id, string short_name, td_api::object_ptr &&sticker, Promise &&promise);