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);
|
|
|
|
|
2023-02-06 17:53:21 +01:00
|
|
|
void reload_autosave_settings();
|
2023-02-03 11:07:43 +01:00
|
|
|
|
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);
|
|
|
|
|
2023-02-03 11:07:43 +01:00
|
|
|
void clear_autosave_settings_excpetions(Promise<Unit> &&promise);
|
|
|
|
|
2023-02-05 08:04:19 +01:00
|
|
|
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
|
|
|
|
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-06 17:53:21 +01:00
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const;
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser);
|
2023-02-03 10:39:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct AutosaveSettings {
|
|
|
|
bool are_inited_ = false;
|
2023-02-06 17:53:21 +01:00
|
|
|
bool are_being_reloaded_ = false;
|
|
|
|
bool need_reload_ = false;
|
2023-02-03 10:39:23 +01:00
|
|
|
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-06 17:53:21 +01:00
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const;
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser);
|
2023-02-03 10:39:23 +01:00
|
|
|
};
|
|
|
|
|
2023-02-03 08:41:31 +01:00
|
|
|
void tear_down() final;
|
|
|
|
|
2023-02-06 17:53:21 +01:00
|
|
|
string get_autosave_settings_database_key();
|
|
|
|
|
|
|
|
void load_autosave_settings(Promise<td_api::object_ptr<td_api::autosaveSettings>> &&promise);
|
|
|
|
|
|
|
|
void on_load_autosave_settings_from_database(string value);
|
|
|
|
|
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-06 17:53:21 +01:00
|
|
|
void save_autosave_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
|