2018-12-31 20:04:05 +01:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
#include "td/telegram/telegram_api.h"
|
2023-05-08 13:41:08 +02:00
|
|
|
#include "td/telegram/UserPrivacySetting.h"
|
2023-05-08 12:50:51 +02:00
|
|
|
#include "td/telegram/UserPrivacySettingRule.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-07-03 21:29:04 +02:00
|
|
|
#include "td/actor/actor.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
2022-06-27 12:30:18 +02:00
|
|
|
#include "td/utils/Promise.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/Status.h"
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2023-05-08 14:23:57 +02:00
|
|
|
class Td;
|
|
|
|
|
|
|
|
class PrivacyManager final : public Actor {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
2023-05-08 14:23:57 +02:00
|
|
|
PrivacyManager(Td *td, ActorShared<> parent);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
void get_privacy(tl_object_ptr<td_api::UserPrivacySetting> key,
|
|
|
|
Promise<tl_object_ptr<td_api::userPrivacySettingRules>> promise);
|
|
|
|
|
|
|
|
void set_privacy(tl_object_ptr<td_api::UserPrivacySetting> key, tl_object_ptr<td_api::userPrivacySettingRules> rules,
|
2018-12-28 23:48:32 +01:00
|
|
|
Promise<Unit> promise);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2023-05-08 13:54:57 +02:00
|
|
|
void on_update_privacy(tl_object_ptr<telegram_api::updatePrivacy> update);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct PrivacyInfo {
|
2023-05-08 19:35:47 +02:00
|
|
|
UserPrivacySettingRules rules_;
|
2023-05-08 19:54:35 +02:00
|
|
|
UserPrivacySettingRules pending_rules_;
|
2023-05-08 19:35:47 +02:00
|
|
|
vector<Promise<tl_object_ptr<td_api::userPrivacySettingRules>>> get_promises_;
|
2023-05-08 19:54:35 +02:00
|
|
|
vector<Promise<Unit>> set_promises_;
|
2023-05-08 19:35:47 +02:00
|
|
|
bool has_set_query_ = false;
|
|
|
|
bool is_synchronized_ = false;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
2023-05-08 14:23:57 +02:00
|
|
|
|
|
|
|
void tear_down() final;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
PrivacyInfo &get_info(UserPrivacySetting key) {
|
|
|
|
return info_[static_cast<size_t>(key.type())];
|
|
|
|
}
|
|
|
|
|
2023-05-08 14:23:57 +02:00
|
|
|
void on_get_user_privacy_settings(UserPrivacySetting user_privacy_setting,
|
|
|
|
Result<UserPrivacySettingRules> r_privacy_rules);
|
|
|
|
|
2023-05-08 19:54:35 +02:00
|
|
|
void set_privacy_impl(UserPrivacySetting user_privacy_setting, UserPrivacySettingRules &&privacy_rules,
|
|
|
|
Promise<Unit> &&promise);
|
|
|
|
|
2023-05-08 14:23:57 +02:00
|
|
|
void on_set_user_privacy_settings(UserPrivacySetting user_privacy_setting,
|
|
|
|
Result<UserPrivacySettingRules> r_privacy_rules, Promise<Unit> &&promise);
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void do_update_privacy(UserPrivacySetting user_privacy_setting, UserPrivacySettingRules &&privacy_rules,
|
|
|
|
bool from_update);
|
|
|
|
|
2023-05-08 14:23:57 +02:00
|
|
|
std::array<PrivacyInfo, static_cast<size_t>(UserPrivacySetting::Type::Size)> info_;
|
2018-04-19 17:39:30 +02:00
|
|
|
|
2023-05-08 14:23:57 +02:00
|
|
|
Td *td_;
|
|
|
|
ActorShared<> parent_;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
2019-09-02 02:51:41 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|