Check provided custom emoji and sticker identifiers.

This commit is contained in:
levlam 2023-01-23 12:50:39 +03:00
parent 69c6a485ba
commit fac51c9819
4 changed files with 28 additions and 7 deletions

View File

@ -388,7 +388,7 @@ document file_name:string mime_type:string minithumbnail:minithumbnail thumbnail
photo has_stickers:Bool minithumbnail:minithumbnail sizes:vector<photoSize> = Photo;
//@description Describes a sticker
//@id Unique sticker identifier within the set
//@id Unique sticker identifier within the set; 0 if none
//@set_id The identifier of the sticker set to which the sticker belongs; 0 if none
//@width Sticker width; as defined by the sender
//@height Sticker height; as defined by the sender

View File

@ -29,18 +29,18 @@ Result<unique_ptr<StickerPhotoSize>> get_sticker_photo_size(
result->type_ = StickerPhotoSize::Type::Sticker;
result->sticker_set_id_ = StickerSetId(type->sticker_set_id_);
result->sticker_id_ = type->sticker_id_;
//if (!td->stickers_manager_->have_sticker(result->sticker_set_id_, result->sticker_id_)) {
// return Status::Error(400, "Sticker not found");
//}
if (!td->stickers_manager_->have_sticker(result->sticker_set_id_, result->sticker_id_)) {
return Status::Error(400, "Sticker not found");
}
break;
}
case td_api::chatPhotoStickerTypeCustomEmoji::ID: {
auto type = static_cast<const td_api::chatPhotoStickerTypeCustomEmoji *>(sticker->type_.get());
result->type_ = StickerPhotoSize::Type::CustomEmoji;
result->custom_emoji_id_ = CustomEmojiId(type->custom_emoji_id_);
//if (!td->stickers_manager_->have_custom_emoji_id(result->custom_emoji_id_)) {
// return Status::Error(400, "Custom emoji not found");
//}
if (!td->stickers_manager_->have_custom_emoji(result->custom_emoji_id_)) {
return Status::Error(400, "Custom emoji not found");
}
break;
}
}

View File

@ -1945,6 +1945,23 @@ bool StickersManager::is_premium_custom_emoji(CustomEmojiId custom_emoji_id, boo
return s->is_premium_;
}
bool StickersManager::have_sticker(StickerSetId sticker_set_id, int64 sticker_id) {
auto sticker_set = get_sticker_set(sticker_set_id);
if (sticker_set == nullptr) {
return false;
}
for (auto file_id : sticker_set->sticker_ids_) {
if (get_sticker_id(file_id) == sticker_id) {
return true;
}
}
return false;
}
bool StickersManager::have_custom_emoji(CustomEmojiId custom_emoji_id) {
return custom_emoji_to_sticker_id_.count(custom_emoji_id) != 0;
}
int64 StickersManager::get_sticker_id(FileId sticker_id) const {
auto sticker_file_view = td_->file_manager_->get_file_view(sticker_id);
if (sticker_file_view.is_encrypted() || !sticker_file_view.has_remote_location() ||

View File

@ -69,6 +69,10 @@ class StickersManager final : public Actor {
bool is_premium_custom_emoji(CustomEmojiId custom_emoji_id, bool default_result) const;
bool have_sticker(StickerSetId sticker_set_id, int64 sticker_id);
bool have_custom_emoji(CustomEmojiId custom_emoji_id);
tl_object_ptr<td_api::sticker> get_sticker_object(FileId file_id, bool for_animated_emoji = false,
bool for_clicked_animated_emoji = false) const;