Move message content self-destruct time checks to create_input_message_content.

This commit is contained in:
levlam 2023-08-29 18:51:57 +03:00
parent 43db9e4882
commit 1a2bfad094
4 changed files with 10 additions and 9 deletions

View File

@ -2306,6 +2306,15 @@ static Result<InputMessageContent> create_input_message_content(
default:
UNREACHABLE();
}
static constexpr int32 MAX_PRIVATE_MESSAGE_TTL = 60; // server side limit
if (ttl < 0 || ttl > MAX_PRIVATE_MESSAGE_TTL) {
return Status::Error(400, "Invalid message content self-destruct time specified");
}
if (ttl > 0 && dialog_id.get_type() != DialogType::User) {
return Status::Error(400, "Message content self-destruct time can be specified only in private chats");
}
return InputMessageContent{std::move(content), disable_web_page_preview, clear_draft, ttl,
via_bot_user_id, std::move(emoji)};
}

View File

@ -25093,13 +25093,6 @@ Result<InputMessageContent> MessagesManager::process_input_message_content(
bool is_premium = td_->option_manager_->get_option_boolean("is_premium");
TRY_RESULT(content, get_input_message_content(dialog_id, std::move(input_message_content), td_, is_premium));
if (content.ttl < 0 || content.ttl > MAX_PRIVATE_MESSAGE_TTL) {
return Status::Error(400, "Invalid message content self-destruct time specified");
}
if (content.ttl > 0 && dialog_id.get_type() != DialogType::User) {
return Status::Error(400, "Message content self-destruct time can be specified only in private chats");
}
if (dialog_id != DialogId()) {
TRY_STATUS(can_send_message_content(dialog_id, content.content.get(), false, td_));
}

View File

@ -1708,7 +1708,6 @@ class MessagesManager final : public Actor {
static constexpr int32 MAX_RECENT_DIALOGS = 50; // some reasonable value
static constexpr size_t MAX_TITLE_LENGTH = 128; // server side limit for chat title
static constexpr size_t MAX_DESCRIPTION_LENGTH = 255; // server side limit for chat description
static constexpr int32 MAX_PRIVATE_MESSAGE_TTL = 60; // server side limit
static constexpr size_t MIN_DELETED_ASYNCHRONOUSLY_MESSAGES = 10;
static constexpr size_t MAX_UNLOADED_MESSAGES = 5000;

View File

@ -429,7 +429,7 @@ Result<PhotoSize> get_input_photo_size(FileManager *file_manager, FileId file_id
int32 type = 'i';
if (file_view.has_remote_location() && !file_view.remote_location().is_web()) {
auto photo_size_source = file_view.remote_location().get_source();
if (photo_size_source.get_type("create_input_message_content") == PhotoSizeSource::Type::Thumbnail) {
if (photo_size_source.get_type("get_input_photo_size") == PhotoSizeSource::Type::Thumbnail) {
auto old_type = photo_size_source.thumbnail().thumbnail_type;
if (old_type != 't') {
type = old_type;