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