tdlight/td/telegram/AutosaveManager.h

94 lines
3.2 KiB
C
Raw Normal View History

2023-02-03 08:41:31 +01:00
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
2023-02-03 10:39:23 +01:00
#include "td/telegram/DialogId.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
2023-02-03 08:41:31 +01:00
#include "td/actor/actor.h"
#include "td/utils/common.h"
2023-02-03 10:39:23 +01:00
#include "td/utils/FlatHashMap.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
2023-02-03 08:41:31 +01:00
namespace td {
class Td;
class AutosaveManager final : public Actor {
public:
AutosaveManager(Td *td, ActorShared<> parent);
void reload_autosave_settings(Promise<td_api::object_ptr<td_api::autosaveSettings>> &&promise);
2023-02-03 10:39:23 +01:00
void get_autosave_settings(Promise<td_api::object_ptr<td_api::autosaveSettings>> &&promise);
2023-02-03 13:58:15 +01:00
void set_autosave_settings(td_api::object_ptr<td_api::AutosaveSettingsScope> &&scope,
td_api::object_ptr<td_api::scopeAutosaveSettings> &&settings, Promise<Unit> &&promise);
void clear_autosave_settings_excpetions(Promise<Unit> &&promise);
2023-02-03 08:41:31 +01:00
private:
2023-02-03 10:39:23 +01:00
struct DialogAutosaveSettings {
2023-02-03 13:58:15 +01:00
bool are_inited_ = false;
2023-02-03 10:39:23 +01:00
bool autosave_photos_ = false;
bool autosave_videos_ = false;
int64 max_video_file_size_ = 0;
2023-02-03 14:49:17 +01:00
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;
2023-02-03 10:39:23 +01:00
DialogAutosaveSettings() = default;
explicit DialogAutosaveSettings(const telegram_api::autoSaveSettings *settings);
2023-02-03 13:58:15 +01:00
explicit DialogAutosaveSettings(const td_api::scopeAutosaveSettings *settings);
telegram_api::object_ptr<telegram_api::autoSaveSettings> get_input_auto_save_settings() const;
2023-02-03 11:45:51 +01:00
td_api::object_ptr<td_api::scopeAutosaveSettings> get_scope_autosave_settings_object() const;
2023-02-03 10:39:23 +01:00
2023-02-03 11:45:51 +01:00
td_api::object_ptr<td_api::autosaveSettingsException> get_autosave_settings_exception_object(
DialogId dialog_id) const;
2023-02-03 13:58:15 +01:00
bool operator==(const DialogAutosaveSettings &other) const;
2023-02-04 01:32:16 +01:00
bool operator!=(const DialogAutosaveSettings &other) const;
2023-02-03 10:39:23 +01:00
};
struct AutosaveSettings {
bool are_inited_ = false;
DialogAutosaveSettings user_settings_;
DialogAutosaveSettings chat_settings_;
DialogAutosaveSettings broadcast_settings_;
FlatHashMap<DialogId, DialogAutosaveSettings, DialogIdHash> exceptions_;
td_api::object_ptr<td_api::autosaveSettings> get_autosave_settings_object() const;
};
2023-02-03 08:41:31 +01:00
void tear_down() final;
2023-02-03 10:39:23 +01:00
void on_get_autosave_settings(Result<telegram_api::object_ptr<telegram_api::account_autoSaveSettings>> r_settings);
2023-02-04 01:32:16 +01:00
static td_api::object_ptr<td_api::updateAutosaveSettings> get_update_autosave_settings(
td_api::object_ptr<td_api::AutosaveSettingsScope> &&scope, const DialogAutosaveSettings &settings);
void send_update_autosave_settings(td_api::object_ptr<td_api::AutosaveSettingsScope> &&scope,
const DialogAutosaveSettings &settings);
2023-02-03 08:41:31 +01:00
Td *td_;
ActorShared<> parent_;
2023-02-03 10:39:23 +01:00
AutosaveSettings settings_;
vector<Promise<td_api::object_ptr<td_api::autosaveSettings>>> load_settings_queries_;
2023-02-03 08:41:31 +01:00
};
} // namespace td