Move get_chat_photo_sticker_object to StickerPhotoSize class.
This commit is contained in:
parent
0e1537420c
commit
61dee568d1
@ -266,44 +266,6 @@ static tl_object_ptr<td_api::animatedChatPhoto> get_animated_chat_photo_object(F
|
|||||||
animation_size->main_frame_timestamp);
|
animation_size->main_frame_timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static tl_object_ptr<td_api::chatPhotoSticker> get_chat_photo_sticker_object(
|
|
||||||
const unique_value_ptr<StickerPhotoSize> &sticker_photo_size) {
|
|
||||||
if (sticker_photo_size == nullptr) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
td_api::object_ptr<td_api::ChatPhotoStickerType> type;
|
|
||||||
switch (sticker_photo_size->type) {
|
|
||||||
case StickerPhotoSize::Type::Sticker:
|
|
||||||
type = td_api::make_object<td_api::chatPhotoStickerTypeRegularOrMask>(sticker_photo_size->sticker_set_id.get(),
|
|
||||||
sticker_photo_size->sticker_id);
|
|
||||||
break;
|
|
||||||
case StickerPhotoSize::Type::CustomEmoji:
|
|
||||||
type = td_api::make_object<td_api::chatPhotoStickerTypeCustomEmoji>(sticker_photo_size->custom_emoji_id.get());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
UNREACHABLE();
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
CHECK(type != nullptr);
|
|
||||||
|
|
||||||
auto background_fill = [&](vector<int32> colors) -> td_api::object_ptr<td_api::BackgroundFill> {
|
|
||||||
switch (colors.size()) {
|
|
||||||
case 1:
|
|
||||||
return td_api::make_object<td_api::backgroundFillSolid>(colors[0]);
|
|
||||||
case 2:
|
|
||||||
return td_api::make_object<td_api::backgroundFillGradient>(colors[0], colors[1], 0);
|
|
||||||
case 3:
|
|
||||||
case 4:
|
|
||||||
return td_api::make_object<td_api::backgroundFillFreeformGradient>(std::move(colors));
|
|
||||||
default:
|
|
||||||
UNREACHABLE();
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}(sticker_photo_size->background_colors);
|
|
||||||
|
|
||||||
return td_api::make_object<td_api::chatPhotoSticker>(std::move(type), std::move(background_fill));
|
|
||||||
}
|
|
||||||
|
|
||||||
Photo get_encrypted_file_photo(FileManager *file_manager, unique_ptr<EncryptedFile> &&file,
|
Photo get_encrypted_file_photo(FileManager *file_manager, unique_ptr<EncryptedFile> &&file,
|
||||||
tl_object_ptr<secret_api::decryptedMessageMediaPhoto> &&photo,
|
tl_object_ptr<secret_api::decryptedMessageMediaPhoto> &&photo,
|
||||||
DialogId owner_dialog_id) {
|
DialogId owner_dialog_id) {
|
||||||
@ -430,11 +392,12 @@ tl_object_ptr<td_api::chatPhoto> get_chat_photo_object(FileManager *file_manager
|
|||||||
LOG(ERROR) << "Have small animation without big animation in " << photo;
|
LOG(ERROR) << "Have small animation without big animation in " << photo;
|
||||||
small_animation = nullptr;
|
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<td_api::chatPhoto>(
|
return td_api::make_object<td_api::chatPhoto>(
|
||||||
photo.id.get(), photo.date, get_minithumbnail_object(photo.minithumbnail),
|
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_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_animated_chat_photo_object(file_manager, small_animation), std::move(chat_photo_sticker));
|
||||||
get_chat_photo_sticker_object(photo.sticker_photo_size));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void photo_delete_thumbnail(Photo &photo) {
|
void photo_delete_thumbnail(Photo &photo) {
|
||||||
|
@ -130,6 +130,39 @@ unique_ptr<StickerPhotoSize> get_sticker_photo_size(Td *td,
|
|||||||
return std::move(result);
|
return std::move(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::chatPhotoSticker> StickerPhotoSize::get_chat_photo_sticker_object() const {
|
||||||
|
td_api::object_ptr<td_api::ChatPhotoStickerType> sticker_type;
|
||||||
|
switch (type) {
|
||||||
|
case StickerPhotoSize::Type::Sticker:
|
||||||
|
sticker_type = td_api::make_object<td_api::chatPhotoStickerTypeRegularOrMask>(sticker_set_id.get(), sticker_id);
|
||||||
|
break;
|
||||||
|
case StickerPhotoSize::Type::CustomEmoji:
|
||||||
|
sticker_type = td_api::make_object<td_api::chatPhotoStickerTypeCustomEmoji>(custom_emoji_id.get());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
CHECK(sticker_type != nullptr);
|
||||||
|
|
||||||
|
auto background_fill = [&](vector<int32> colors) -> td_api::object_ptr<td_api::BackgroundFill> {
|
||||||
|
switch (colors.size()) {
|
||||||
|
case 1:
|
||||||
|
return td_api::make_object<td_api::backgroundFillSolid>(colors[0]);
|
||||||
|
case 2:
|
||||||
|
return td_api::make_object<td_api::backgroundFillGradient>(colors[0], colors[1], 0);
|
||||||
|
case 3:
|
||||||
|
case 4:
|
||||||
|
return td_api::make_object<td_api::backgroundFillFreeformGradient>(std::move(colors));
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}(background_colors);
|
||||||
|
|
||||||
|
return td_api::make_object<td_api::chatPhotoSticker>(std::move(sticker_type), std::move(background_fill));
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(const StickerPhotoSize &lhs, const StickerPhotoSize &rhs) {
|
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 &&
|
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;
|
lhs.custom_emoji_id == rhs.custom_emoji_id && lhs.background_colors == rhs.background_colors;
|
||||||
|
@ -26,6 +26,8 @@ struct StickerPhotoSize {
|
|||||||
StickerSetId sticker_set_id;
|
StickerSetId sticker_set_id;
|
||||||
int64 sticker_id = 0;
|
int64 sticker_id = 0;
|
||||||
vector<int32> background_colors;
|
vector<int32> background_colors;
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::chatPhotoSticker> get_chat_photo_sticker_object() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
Result<unique_ptr<StickerPhotoSize>> get_sticker_photo_size(
|
Result<unique_ptr<StickerPhotoSize>> get_sticker_photo_size(
|
||||||
|
Loading…
Reference in New Issue
Block a user