Add get_sticker_type function.

This commit is contained in:
levlam 2022-07-13 23:02:46 +03:00
parent ac4e76edf1
commit 7618c9aa64
3 changed files with 20 additions and 13 deletions

View File

@ -10,6 +10,23 @@
namespace td {
StickerFormat get_sticker_format(const td_api::object_ptr<td_api::StickerType> &type) {
CHECK(type != nullptr);
switch (type->get_id()) {
case td_api::stickerTypeStatic::ID:
return StickerFormat::Webp;
case td_api::stickerTypeAnimated::ID:
return StickerFormat::Tgs;
case td_api::stickerTypeVideo::ID:
return StickerFormat::Webm;
case td_api::stickerTypeMask::ID:
return StickerFormat::Webp;
default:
UNREACHABLE();
return StickerFormat::Unknown;
}
}
StickerFormat get_sticker_format_by_mime_type(Slice mime_type) {
if (mime_type == "application/x-tgsticker") {
return StickerFormat::Tgs;

View File

@ -18,6 +18,8 @@ namespace td {
// update store_sticker/store_sticker_set when this type changes
enum class StickerFormat : int32 { Unknown, Webp, Tgs, Webm };
StickerFormat get_sticker_format(const td_api::object_ptr<td_api::StickerType> &type);
StickerFormat get_sticker_format_by_mime_type(Slice mime_type);
StickerFormat get_sticker_format_by_extension(Slice extension);

View File

@ -5794,19 +5794,7 @@ Result<std::tuple<FileId, bool, bool, StickerFormat>> StickersManager::prepare_i
return Status::Error(400, "Sticker type must be non-empty");
}
switch (sticker->type_->get_id()) {
case td_api::stickerTypeStatic::ID:
return prepare_input_file(sticker->sticker_, StickerFormat::Webp, false);
case td_api::stickerTypeAnimated::ID:
return prepare_input_file(sticker->sticker_, StickerFormat::Tgs, false);
case td_api::stickerTypeVideo::ID:
return prepare_input_file(sticker->sticker_, StickerFormat::Webm, false);
case td_api::stickerTypeMask::ID:
return prepare_input_file(sticker->sticker_, StickerFormat::Webp, false);
default:
UNREACHABLE();
return {};
}
return prepare_input_file(sticker->sticker_, get_sticker_format(sticker->type_), false);
}
Result<std::tuple<FileId, bool, bool, StickerFormat>> StickersManager::prepare_input_file(