diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index 0a5d7b1b1..7a119c2a5 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -266,44 +266,6 @@ static tl_object_ptr get_animated_chat_photo_object(F animation_size->main_frame_timestamp); } -static tl_object_ptr get_chat_photo_sticker_object( - const unique_value_ptr &sticker_photo_size) { - if (sticker_photo_size == nullptr) { - return nullptr; - } - td_api::object_ptr type; - switch (sticker_photo_size->type) { - case StickerPhotoSize::Type::Sticker: - type = td_api::make_object(sticker_photo_size->sticker_set_id.get(), - sticker_photo_size->sticker_id); - break; - case StickerPhotoSize::Type::CustomEmoji: - type = td_api::make_object(sticker_photo_size->custom_emoji_id.get()); - break; - default: - UNREACHABLE(); - return nullptr; - } - CHECK(type != nullptr); - - auto background_fill = [&](vector colors) -> td_api::object_ptr { - switch (colors.size()) { - case 1: - return td_api::make_object(colors[0]); - case 2: - return td_api::make_object(colors[0], colors[1], 0); - case 3: - case 4: - return td_api::make_object(std::move(colors)); - default: - UNREACHABLE(); - return nullptr; - } - }(sticker_photo_size->background_colors); - - return td_api::make_object(std::move(type), std::move(background_fill)); -} - Photo get_encrypted_file_photo(FileManager *file_manager, unique_ptr &&file, tl_object_ptr &&photo, DialogId owner_dialog_id) { @@ -430,11 +392,12 @@ tl_object_ptr get_chat_photo_object(FileManager *file_manager LOG(ERROR) << "Have small animation without big animation in " << photo; small_animation = nullptr; } + auto chat_photo_sticker = + photo.sticker_photo_size == nullptr ? nullptr : photo.sticker_photo_size->get_chat_photo_sticker_object(); return td_api::make_object( photo.id.get(), photo.date, get_minithumbnail_object(photo.minithumbnail), get_photo_sizes_object(file_manager, photo.photos), get_animated_chat_photo_object(file_manager, big_animation), - get_animated_chat_photo_object(file_manager, small_animation), - get_chat_photo_sticker_object(photo.sticker_photo_size)); + get_animated_chat_photo_object(file_manager, small_animation), std::move(chat_photo_sticker)); } void photo_delete_thumbnail(Photo &photo) { diff --git a/td/telegram/StickerPhotoSize.cpp b/td/telegram/StickerPhotoSize.cpp index f2d1d2e50..0026b033d 100644 --- a/td/telegram/StickerPhotoSize.cpp +++ b/td/telegram/StickerPhotoSize.cpp @@ -130,6 +130,39 @@ unique_ptr get_sticker_photo_size(Td *td, return std::move(result); } +td_api::object_ptr StickerPhotoSize::get_chat_photo_sticker_object() const { + td_api::object_ptr sticker_type; + switch (type) { + case StickerPhotoSize::Type::Sticker: + sticker_type = td_api::make_object(sticker_set_id.get(), sticker_id); + break; + case StickerPhotoSize::Type::CustomEmoji: + sticker_type = td_api::make_object(custom_emoji_id.get()); + break; + default: + UNREACHABLE(); + return nullptr; + } + CHECK(sticker_type != nullptr); + + auto background_fill = [&](vector colors) -> td_api::object_ptr { + switch (colors.size()) { + case 1: + return td_api::make_object(colors[0]); + case 2: + return td_api::make_object(colors[0], colors[1], 0); + case 3: + case 4: + return td_api::make_object(std::move(colors)); + default: + UNREACHABLE(); + return nullptr; + } + }(background_colors); + + return td_api::make_object(std::move(sticker_type), std::move(background_fill)); +} + bool operator==(const StickerPhotoSize &lhs, const StickerPhotoSize &rhs) { return lhs.type == rhs.type && lhs.sticker_set_id == rhs.sticker_set_id && lhs.sticker_id == rhs.sticker_id && lhs.custom_emoji_id == rhs.custom_emoji_id && lhs.background_colors == rhs.background_colors; diff --git a/td/telegram/StickerPhotoSize.h b/td/telegram/StickerPhotoSize.h index fa488c209..bd383d54e 100644 --- a/td/telegram/StickerPhotoSize.h +++ b/td/telegram/StickerPhotoSize.h @@ -26,6 +26,8 @@ struct StickerPhotoSize { StickerSetId sticker_set_id; int64 sticker_id = 0; vector background_colors; + + td_api::object_ptr get_chat_photo_sticker_object() const; }; Result> get_sticker_photo_size(