Support documentAttributeCustomEmoji.

This commit is contained in:
levlam 2022-07-14 17:11:36 +03:00
parent 5bdc4e207b
commit ea8f81187e
5 changed files with 35 additions and 15 deletions

View File

@ -76,6 +76,7 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
tl_object_ptr<telegram_api::documentAttributeVideo> video;
tl_object_ptr<telegram_api::documentAttributeAudio> audio;
tl_object_ptr<telegram_api::documentAttributeSticker> sticker;
tl_object_ptr<telegram_api::documentAttributeCustomEmoji> custom_emoji;
Dimensions dimensions;
string file_name;
bool has_stickers = false;
@ -111,7 +112,8 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
has_stickers = true;
break;
case telegram_api::documentAttributeCustomEmoji::ID:
// TODO
custom_emoji = move_tl_object_as<telegram_api::documentAttributeCustomEmoji>(attribute);
type_attributes++;
break;
default:
UNREACHABLE();
@ -133,7 +135,7 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
if ((video->flags_ & telegram_api::documentAttributeVideo::ROUND_MESSAGE_MASK) != 0) {
// video note without sound
animated = nullptr;
} else if (sticker != nullptr) {
} else if (sticker != nullptr || custom_emoji != nullptr) {
// sticker
type_attributes--;
animated = nullptr;
@ -142,7 +144,7 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
// video animation
video = nullptr;
}
} else if (sticker != nullptr) {
} else if (sticker != nullptr || custom_emoji != nullptr) {
// some stickers uploaded before release
type_attributes--;
video = nullptr;
@ -158,6 +160,11 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
type_attributes--;
sticker = nullptr;
}
if (animated != nullptr && custom_emoji != nullptr) {
// just in case
type_attributes--;
custom_emoji = nullptr;
}
auto document_type = default_document_type;
FileType file_type = FileType::Document;
@ -186,7 +193,7 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
file_type = FileType::Audio;
default_extension = Slice("mp3");
}
} else if (sticker != nullptr || default_document_type == Document::Type::Sticker) {
} else if (sticker != nullptr || custom_emoji != nullptr || default_document_type == Document::Type::Sticker) {
document_type = Document::Type::Sticker;
file_type = FileType::Sticker;
sticker_format = StickerFormat::Webp;
@ -214,8 +221,9 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
}
} else if (type_attributes >= 2) {
LOG(WARNING) << "Receive document with more than 1 type attribute: animated = " << to_string(animated)
<< ", sticker = " << to_string(sticker) << ", video = " << to_string(video)
<< ", audio = " << to_string(audio) << ", file_name = " << file_name << ", dimensions = " << dimensions
<< ", sticker = " << to_string(sticker) << ", custom_emoji = " << to_string(custom_emoji)
<< ", video = " << to_string(video) << ", audio = " << to_string(audio)
<< ", file_name = " << file_name << ", dimensions = " << dimensions
<< ", has_stickers = " << has_stickers;
}
@ -493,8 +501,8 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
minithumbnail = string();
}
td_->stickers_manager_->create_sticker(file_id, premium_animation_file_id, std::move(minithumbnail),
std::move(thumbnail), dimensions, std::move(sticker), sticker_format,
load_data_multipromise_ptr);
std::move(thumbnail), dimensions, std::move(sticker),
std::move(custom_emoji), sticker_format, load_data_multipromise_ptr);
break;
case Document::Type::Video:
td_->videos_manager_->create_video(file_id, std::move(minithumbnail), std::move(thumbnail),

View File

@ -1882,7 +1882,7 @@ static Result<InputMessageContent> create_input_message_content(
td->stickers_manager_->create_sticker(file_id, FileId(), string(), thumbnail,
get_dimensions(input_sticker->width_, input_sticker->height_, nullptr),
nullptr, StickerFormat::Unknown, nullptr);
nullptr, nullptr, StickerFormat::Unknown, nullptr);
content = make_unique<MessageSticker>(file_id, is_premium);
break;

View File

@ -357,6 +357,7 @@ PhotoSize get_web_document_photo_size(FileManager *file_manager, FileType file_t
case telegram_api::documentAttributeSticker::ID:
case telegram_api::documentAttributeVideo::ID:
case telegram_api::documentAttributeAudio::ID:
case telegram_api::documentAttributeCustomEmoji::ID:
LOG(ERROR) << "Unexpected web document attribute " << to_string(attribute);
break;
case telegram_api::documentAttributeFilename::ID:

View File

@ -2320,6 +2320,7 @@ std::pair<int64, FileId> StickersManager::on_get_sticker_document(tl_object_ptr<
Dimensions dimensions;
tl_object_ptr<telegram_api::documentAttributeSticker> sticker;
tl_object_ptr<telegram_api::documentAttributeCustomEmoji> custom_emoji;
for (auto &attribute : document->attributes_) {
switch (attribute->get_id()) {
case telegram_api::documentAttributeVideo::ID: {
@ -2335,11 +2336,14 @@ std::pair<int64, FileId> StickersManager::on_get_sticker_document(tl_object_ptr<
case telegram_api::documentAttributeSticker::ID:
sticker = move_tl_object_as<telegram_api::documentAttributeSticker>(attribute);
break;
case telegram_api::documentAttributeCustomEmoji::ID:
custom_emoji = move_tl_object_as<telegram_api::documentAttributeCustomEmoji>(attribute);
break;
default:
continue;
}
}
if (sticker == nullptr) {
if (sticker == nullptr && custom_emoji == nullptr) {
if (document->mime_type_ != "application/x-bad-tgsticker") {
LOG(ERROR) << "Have no attributeSticker in sticker " << to_string(document);
}
@ -2389,7 +2393,7 @@ std::pair<int64, FileId> StickersManager::on_get_sticker_document(tl_object_ptr<
}
create_sticker(sticker_id, premium_animation_file_id, std::move(minithumbnail), std::move(thumbnail), dimensions,
std::move(sticker), format, nullptr);
std::move(sticker), std::move(custom_emoji), format, nullptr);
return {document_id, sticker_id};
}
@ -2713,6 +2717,7 @@ void StickersManager::add_sticker_thumbnail(Sticker *s, PhotoSize thumbnail) {
void StickersManager::create_sticker(FileId file_id, FileId premium_animation_file_id, string minithumbnail,
PhotoSize thumbnail, Dimensions dimensions,
tl_object_ptr<telegram_api::documentAttributeSticker> sticker,
tl_object_ptr<telegram_api::documentAttributeCustomEmoji> custom_emoji,
StickerFormat format, MultiPromiseActor *load_data_multipromise_ptr) {
if (format == StickerFormat::Unknown && sticker == nullptr) {
auto old_sticker = get_sticker(file_id);
@ -2730,8 +2735,8 @@ void StickersManager::create_sticker(FileId file_id, FileId premium_animation_fi
}
}
if (is_sticker_format_vector(format) && dimensions.width == 0) {
dimensions.width = 512;
dimensions.height = 512;
dimensions.width = custom_emoji != nullptr ? 100 : 512;
dimensions.height = custom_emoji != nullptr ? 100 : 512;
}
auto s = make_unique<Sticker>();
@ -2759,9 +2764,14 @@ void StickersManager::create_sticker(FileId file_id, FileId premium_animation_fi
s->scale = sticker->mask_coords_->zoom_;
}
}
} else if (custom_emoji != nullptr) {
s->set_id = on_get_input_sticker_set(file_id, std::move(custom_emoji->stickerset_), load_data_multipromise_ptr);
s->alt = std::move(custom_emoji->alt_);
s->type = StickerType::Emoji;
}
s->format = format;
on_get_sticker(std::move(s), sticker != nullptr && load_data_multipromise_ptr == nullptr);
on_get_sticker(std::move(s),
(sticker != nullptr || custom_emoji != nullptr) && load_data_multipromise_ptr == nullptr);
}
bool StickersManager::has_input_media(FileId sticker_file_id, bool is_secret) const {
@ -5857,7 +5867,7 @@ Result<std::tuple<FileId, bool, bool, StickerFormat>> StickersManager::prepare_i
if (format == StickerFormat::Tgs) {
int32 width = for_thumbnail ? 100 : 512;
create_sticker(file_id, FileId(), string(), PhotoSize(), get_dimensions(width, width, "prepare_input_file"),
nullptr, format, nullptr);
nullptr, nullptr, format, nullptr);
} else if (format == StickerFormat::Webm) {
td_->documents_manager_->create_document(file_id, string(), PhotoSize(), "sticker.webm", "video/webm", false);
} else {

View File

@ -104,6 +104,7 @@ class StickersManager final : public Actor {
void create_sticker(FileId file_id, FileId premium_animation_file_id, string minithumbnail, PhotoSize thumbnail,
Dimensions dimensions, tl_object_ptr<telegram_api::documentAttributeSticker> sticker,
tl_object_ptr<telegram_api::documentAttributeCustomEmoji> custom_emoji,
StickerFormat sticker_format, MultiPromiseActor *load_data_multipromise_ptr);
bool has_input_media(FileId sticker_file_id, bool is_secret) const;