Skip to content

Commit

Permalink
Check and fix max_video_file_size.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Feb 3, 2023
1 parent 7556ef4 commit 810b58d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion td/generate/scheme/td_api.tl
Original file line number Diff line number Diff line change
Expand Up @@ -4834,7 +4834,7 @@ autosaveSettingsScopeChat chat_id:int53 = AutosaveSettingsScope;
//@description Contains autosave settings for an autosave settings scope
//@autosave_photos True, if photo autosave is enabled
//@autosave_videos True, if video autosave is enabled
//@max_video_file_size The maximum size of a video file to be autosaved, in bytes; 0 if not limited
//@max_video_file_size The maximum size of a video file to be autosaved, in bytes; 512 KB - 4000 MB
scopeAutosaveSettings autosave_photos:Bool autosave_videos:Bool max_video_file_size:int53 = ScopeAutosaveSettings;

//@description Contains autosave settings for a chat, which overrides default settings for the corresponding scope
Expand Down
10 changes: 6 additions & 4 deletions td/telegram/AutosaveManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "td/utils/algorithm.h"
#include "td/utils/buffer.h"
#include "td/utils/misc.h"

namespace td {

Expand Down Expand Up @@ -128,7 +129,7 @@ AutosaveManager::DialogAutosaveSettings::DialogAutosaveSettings(const telegram_a
are_inited_ = true;
autosave_photos_ = settings->photos_;
autosave_videos_ = settings->videos_;
max_video_file_size_ = settings->video_max_size_;
max_video_file_size_ = clamp(settings->video_max_size_, MIN_MAX_VIDEO_FILE_SIZE, MAX_MAX_VIDEO_FILE_SIZE);
}

AutosaveManager::DialogAutosaveSettings::DialogAutosaveSettings(const td_api::scopeAutosaveSettings *settings) {
Expand All @@ -138,7 +139,7 @@ AutosaveManager::DialogAutosaveSettings::DialogAutosaveSettings(const td_api::sc
are_inited_ = true;
autosave_photos_ = settings->autosave_photos_;
autosave_videos_ = settings->autosave_videos_;
max_video_file_size_ = settings->max_video_file_size_;
max_video_file_size_ = clamp(settings->max_video_file_size_, MIN_MAX_VIDEO_FILE_SIZE, MAX_MAX_VIDEO_FILE_SIZE);
}

telegram_api::object_ptr<telegram_api::autoSaveSettings>
Expand Down Expand Up @@ -205,7 +206,6 @@ void AutosaveManager::reload_autosave_settings(Promise<td_api::object_ptr<td_api

void AutosaveManager::on_get_autosave_settings(
Result<telegram_api::object_ptr<telegram_api::account_autoSaveSettings>> r_settings) {
CHECK(!settings_.are_inited_);
if (G()->close_flag() && r_settings.is_ok()) {
r_settings = Global::request_aborted_error();
}
Expand All @@ -214,9 +214,10 @@ void AutosaveManager::on_get_autosave_settings(
}

auto settings = r_settings.move_as_ok();
settings_.are_inited_ = true;
td_->contacts_manager_->on_get_users(std::move(settings->users_), "on_get_autosave_settings");
td_->contacts_manager_->on_get_chats(std::move(settings->chats_), "on_get_autosave_settings");

settings_.are_inited_ = true;
settings_.user_settings_ = DialogAutosaveSettings(settings->users_settings_.get());
settings_.chat_settings_ = DialogAutosaveSettings(settings->chats_settings_.get());
settings_.broadcast_settings_ = DialogAutosaveSettings(settings->broadcasts_settings_.get());
Expand Down Expand Up @@ -275,6 +276,7 @@ void AutosaveManager::set_autosave_settings(td_api::object_ptr<td_api::AutosaveS
}
if (!dialog_id.is_valid()) {
new_settings.are_inited_ = true;
new_settings.max_video_file_size_ = DialogAutosaveSettings::DEFAULT_MAX_VIDEO_FILE_SIZE;
}
if (*old_settings == new_settings) {
return promise.set_value(Unit());
Expand Down
4 changes: 4 additions & 0 deletions td/telegram/AutosaveManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class AutosaveManager final : public Actor {
bool autosave_videos_ = false;
int64 max_video_file_size_ = 0;

static constexpr int64 MIN_MAX_VIDEO_FILE_SIZE = 512 * 1024;
static constexpr int64 DEFAULT_MAX_VIDEO_FILE_SIZE = 100 * 1024 * 1024;
static constexpr int64 MAX_MAX_VIDEO_FILE_SIZE = static_cast<int64>(4000) * 1024 * 1024;

DialogAutosaveSettings() = default;

explicit DialogAutosaveSettings(const telegram_api::autoSaveSettings *settings);
Expand Down

0 comments on commit 810b58d

Please sign in to comment.