Support emoji stickers in get_max_sticker_file_size.

This commit is contained in:
levlam 2022-07-17 23:49:46 +03:00
parent 4442293acf
commit 7cd65d06a1
5 changed files with 14 additions and 10 deletions

View File

@ -21,6 +21,7 @@
#include "td/telegram/secret_api.h" #include "td/telegram/secret_api.h"
#include "td/telegram/StickerFormat.h" #include "td/telegram/StickerFormat.h"
#include "td/telegram/StickersManager.h" #include "td/telegram/StickersManager.h"
#include "td/telegram/StickerType.h"
#include "td/telegram/Td.h" #include "td/telegram/Td.h"
#include "td/telegram/td_api.h" #include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h" #include "td/telegram/telegram_api.h"
@ -422,7 +423,7 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
default_extension = Slice("webm"); default_extension = Slice("webm");
} }
if (file_type == FileType::Encrypted && document_type == Document::Type::Sticker && if (file_type == FileType::Encrypted && document_type == Document::Type::Sticker &&
size > get_max_sticker_file_size(sticker_format, false)) { size > get_max_sticker_file_size(sticker_format, StickerType::Regular, false)) {
document_type = Document::Type::General; document_type = Document::Type::General;
} }

View File

@ -146,15 +146,16 @@ bool is_sticker_format_vector(StickerFormat sticker_format) {
} }
} }
int64 get_max_sticker_file_size(StickerFormat sticker_format, bool for_thumbnail) { int64 get_max_sticker_file_size(StickerFormat sticker_format, StickerType sticker_type, bool for_thumbnail) {
bool is_emoji = sticker_type == StickerType::Emoji;
switch (sticker_format) { switch (sticker_format) {
case StickerFormat::Unknown: case StickerFormat::Unknown:
case StickerFormat::Webp: case StickerFormat::Webp:
return for_thumbnail ? (1 << 17) : (1 << 19); return for_thumbnail ? (1 << 17) : (is_emoji ? (1 << 17) : (1 << 19));
case StickerFormat::Tgs: case StickerFormat::Tgs:
return for_thumbnail ? (1 << 15) : (1 << 16); return for_thumbnail ? (1 << 15) : (1 << 16);
case StickerFormat::Webm: case StickerFormat::Webm:
return for_thumbnail ? (1 << 15) : (1 << 18); return for_thumbnail ? (1 << 15) : (is_emoji ? (1 << 16) : (1 << 18));
default: default:
UNREACHABLE(); UNREACHABLE();
return 0; return 0;

View File

@ -7,6 +7,7 @@
#pragma once #pragma once
#include "td/telegram/PhotoFormat.h" #include "td/telegram/PhotoFormat.h"
#include "td/telegram/StickerType.h"
#include "td/telegram/td_api.h" #include "td/telegram/td_api.h"
#include "td/utils/common.h" #include "td/utils/common.h"
@ -36,7 +37,7 @@ bool is_sticker_format_animated(StickerFormat sticker_format);
bool is_sticker_format_vector(StickerFormat sticker_format); bool is_sticker_format_vector(StickerFormat sticker_format);
int64 get_max_sticker_file_size(StickerFormat sticker_format, bool for_thumbnail); int64 get_max_sticker_file_size(StickerFormat sticker_format, StickerType sticker_type, bool for_thumbnail);
StringBuilder &operator<<(StringBuilder &string_builder, StickerFormat sticker_format); StringBuilder &operator<<(StringBuilder &string_builder, StickerFormat sticker_format);

View File

@ -6028,11 +6028,12 @@ Result<std::tuple<FileId, bool, bool, StickerFormat>> StickersManager::prepare_i
return Status::Error(400, "Sticker format must be non-empty"); return Status::Error(400, "Sticker format must be non-empty");
} }
return prepare_input_file(sticker->sticker_, get_sticker_format(sticker->format_), false); return prepare_input_file(sticker->sticker_, get_sticker_format(sticker->format_), get_sticker_type(sticker->type_),
false);
} }
Result<std::tuple<FileId, bool, bool, StickerFormat>> StickersManager::prepare_input_file( Result<std::tuple<FileId, bool, bool, StickerFormat>> StickersManager::prepare_input_file(
const tl_object_ptr<td_api::InputFile> &input_file, StickerFormat format, bool for_thumbnail) { const tl_object_ptr<td_api::InputFile> &input_file, StickerFormat format, StickerType type, bool for_thumbnail) {
auto file_type = format == StickerFormat::Tgs ? FileType::Sticker : FileType::Document; auto file_type = format == StickerFormat::Tgs ? FileType::Sticker : FileType::Document;
auto r_file_id = td_->file_manager_->get_input_file_id(file_type, input_file, DialogId(), for_thumbnail, false); auto r_file_id = td_->file_manager_->get_input_file_id(file_type, input_file, DialogId(), for_thumbnail, false);
if (r_file_id.is_error()) { if (r_file_id.is_error()) {
@ -6070,7 +6071,7 @@ Result<std::tuple<FileId, bool, bool, StickerFormat>> StickersManager::prepare_i
is_url = true; is_url = true;
} else { } else {
if (file_view.has_local_location() && if (file_view.has_local_location() &&
file_view.expected_size() > get_max_sticker_file_size(format, for_thumbnail)) { file_view.expected_size() > get_max_sticker_file_size(format, type, for_thumbnail)) {
return Status::Error(400, "File is too big"); return Status::Error(400, "File is too big");
} }
is_local = true; is_local = true;
@ -6547,7 +6548,7 @@ void StickersManager::do_set_sticker_set_thumbnail(UserId user_id, string short_
return promise.set_error(Status::Error(400, "Sticker set not found")); return promise.set_error(Status::Error(400, "Sticker set not found"));
} }
auto r_file_id = prepare_input_file(thumbnail, sticker_set->sticker_format, true); auto r_file_id = prepare_input_file(thumbnail, sticker_set->sticker_format, sticker_set->sticker_type, true);
if (r_file_id.is_error()) { if (r_file_id.is_error()) {
return promise.set_error(r_file_id.move_as_error()); return promise.set_error(r_file_id.move_as_error());
} }

View File

@ -668,7 +668,7 @@ class StickersManager final : public Actor {
std::pair<vector<FileId>, vector<FileId>> split_stickers_by_premium(const vector<FileId> &sticker_ids) const; std::pair<vector<FileId>, vector<FileId>> split_stickers_by_premium(const vector<FileId> &sticker_ids) const;
Result<std::tuple<FileId, bool, bool, StickerFormat>> prepare_input_file( Result<std::tuple<FileId, bool, bool, StickerFormat>> prepare_input_file(
const tl_object_ptr<td_api::InputFile> &input_file, StickerFormat format, bool for_thumbnail); const tl_object_ptr<td_api::InputFile> &input_file, StickerFormat format, StickerType type, bool for_thumbnail);
Result<std::tuple<FileId, bool, bool, StickerFormat>> prepare_input_sticker(td_api::inputSticker *sticker); Result<std::tuple<FileId, bool, bool, StickerFormat>> prepare_input_sticker(td_api::inputSticker *sticker);