2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
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
|
|
|
|
|
2019-09-03 20:16:10 +02:00
|
|
|
#include "td/telegram/net/NetQuery.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
#include "td/telegram/telegram_api.h"
|
2021-03-29 00:34:33 +02:00
|
|
|
#include "td/telegram/UserId.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"
|
|
|
|
#include "td/utils/Container.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 {
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class PrivacyManager final : public NetQueryCallback {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
|
|
|
explicit PrivacyManager(ActorShared<> parent) : parent_(std::move(parent)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
void update_privacy(tl_object_ptr<telegram_api::updatePrivacy> update);
|
|
|
|
|
|
|
|
private:
|
|
|
|
class UserPrivacySetting {
|
|
|
|
public:
|
2019-05-14 02:18:34 +02:00
|
|
|
enum class Type : int32 {
|
|
|
|
UserStatus,
|
|
|
|
ChatInvite,
|
|
|
|
Call,
|
|
|
|
PeerToPeerCall,
|
|
|
|
LinkInForwardedMessages,
|
|
|
|
UserProfilePhoto,
|
2019-09-03 16:13:03 +02:00
|
|
|
UserPhoneNumber,
|
2019-11-22 11:41:17 +01:00
|
|
|
FindByPhoneNumber,
|
2022-07-16 20:20:18 +02:00
|
|
|
VoiceMessages,
|
2019-05-14 02:18:34 +02:00
|
|
|
Size
|
|
|
|
};
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
explicit UserPrivacySetting(const telegram_api::PrivacyKey &key);
|
2020-06-22 03:28:03 +02:00
|
|
|
|
|
|
|
static Result<UserPrivacySetting> get_user_privacy_setting(tl_object_ptr<td_api::UserPrivacySetting> key);
|
|
|
|
|
|
|
|
tl_object_ptr<td_api::UserPrivacySetting> get_user_privacy_setting_object() const;
|
|
|
|
|
|
|
|
tl_object_ptr<telegram_api::InputPrivacyKey> get_input_privacy_key() const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
Type type() const {
|
|
|
|
return type_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Type type_;
|
|
|
|
|
|
|
|
explicit UserPrivacySetting(const td_api::UserPrivacySetting &key);
|
|
|
|
};
|
|
|
|
|
|
|
|
class UserPrivacySettingRule {
|
|
|
|
public:
|
|
|
|
UserPrivacySettingRule() = default;
|
2020-06-22 03:28:03 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
explicit UserPrivacySettingRule(const td_api::UserPrivacySettingRule &rule);
|
2020-06-22 03:28:03 +02:00
|
|
|
|
|
|
|
static Result<UserPrivacySettingRule> get_user_privacy_setting_rule(tl_object_ptr<telegram_api::PrivacyRule> rule);
|
|
|
|
|
|
|
|
tl_object_ptr<td_api::UserPrivacySettingRule> get_user_privacy_setting_rule_object() const;
|
|
|
|
|
|
|
|
tl_object_ptr<telegram_api::InputPrivacyRule> get_input_privacy_rule() const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
bool operator==(const UserPrivacySettingRule &other) const {
|
2019-09-03 20:16:10 +02:00
|
|
|
return type_ == other.type_ && user_ids_ == other.user_ids_ && chat_ids_ == other.chat_ids_;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-03-29 00:34:33 +02:00
|
|
|
vector<UserId> get_restricted_user_ids() const;
|
2020-04-19 11:53:07 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
private:
|
2018-04-19 15:08:30 +02:00
|
|
|
enum class Type : int32 {
|
2018-12-31 20:04:05 +01:00
|
|
|
AllowContacts,
|
|
|
|
AllowAll,
|
|
|
|
AllowUsers,
|
2019-09-03 20:16:10 +02:00
|
|
|
AllowChatParticipants,
|
2018-12-31 20:04:05 +01:00
|
|
|
RestrictContacts,
|
|
|
|
RestrictAll,
|
2019-09-03 20:16:10 +02:00
|
|
|
RestrictUsers,
|
|
|
|
RestrictChatParticipants
|
2018-12-31 20:04:05 +01:00
|
|
|
} type_ = Type::RestrictAll;
|
|
|
|
|
2021-03-29 00:34:33 +02:00
|
|
|
vector<UserId> user_ids_;
|
2021-09-03 11:27:59 +02:00
|
|
|
vector<int64> chat_ids_;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2020-06-22 03:28:03 +02:00
|
|
|
vector<tl_object_ptr<telegram_api::InputUser>> get_input_users() const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-09-03 20:16:10 +02:00
|
|
|
void set_chat_ids(const vector<int64> &dialog_ids);
|
|
|
|
|
|
|
|
vector<int64> chat_ids_as_dialog_ids() const;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
explicit UserPrivacySettingRule(const telegram_api::PrivacyRule &rule);
|
|
|
|
};
|
|
|
|
|
|
|
|
class UserPrivacySettingRules {
|
|
|
|
public:
|
|
|
|
UserPrivacySettingRules() = default;
|
2020-06-22 03:28:03 +02:00
|
|
|
|
|
|
|
static Result<UserPrivacySettingRules> get_user_privacy_setting_rules(
|
|
|
|
tl_object_ptr<telegram_api::account_privacyRules> rules);
|
|
|
|
|
|
|
|
static Result<UserPrivacySettingRules> get_user_privacy_setting_rules(
|
|
|
|
vector<tl_object_ptr<telegram_api::PrivacyRule>> rules);
|
|
|
|
|
|
|
|
static Result<UserPrivacySettingRules> get_user_privacy_setting_rules(
|
|
|
|
tl_object_ptr<td_api::userPrivacySettingRules> rules);
|
|
|
|
|
|
|
|
tl_object_ptr<td_api::userPrivacySettingRules> get_user_privacy_setting_rules_object() const;
|
|
|
|
|
|
|
|
vector<tl_object_ptr<telegram_api::InputPrivacyRule>> get_input_privacy_rules() const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
bool operator==(const UserPrivacySettingRules &other) const {
|
|
|
|
return rules_ == other.rules_;
|
|
|
|
}
|
|
|
|
|
2021-03-29 00:34:33 +02:00
|
|
|
vector<UserId> get_restricted_user_ids() const;
|
2020-04-19 11:53:07 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
private:
|
|
|
|
vector<UserPrivacySettingRule> rules_;
|
|
|
|
};
|
|
|
|
|
|
|
|
ActorShared<> parent_;
|
|
|
|
|
|
|
|
struct PrivacyInfo {
|
|
|
|
UserPrivacySettingRules rules;
|
|
|
|
vector<Promise<tl_object_ptr<td_api::userPrivacySettingRules>>> get_promises;
|
|
|
|
bool has_set_query = false;
|
|
|
|
bool is_synchronized = false;
|
|
|
|
};
|
|
|
|
std::array<PrivacyInfo, static_cast<size_t>(UserPrivacySetting::Type::Size)> info_;
|
|
|
|
|
|
|
|
PrivacyInfo &get_info(UserPrivacySetting key) {
|
|
|
|
return info_[static_cast<size_t>(key.type())];
|
|
|
|
}
|
|
|
|
|
2022-04-13 16:40:12 +02:00
|
|
|
void on_get_result(UserPrivacySetting user_privacy_setting, Result<UserPrivacySettingRules> r_privacy_rules);
|
2018-12-31 20:04:05 +01:00
|
|
|
void do_update_privacy(UserPrivacySetting user_privacy_setting, UserPrivacySettingRules &&privacy_rules,
|
|
|
|
bool from_update);
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void on_result(NetQueryPtr query) final;
|
2018-12-31 20:04:05 +01:00
|
|
|
Container<Promise<NetQueryPtr>> container_;
|
|
|
|
void send_with_promise(NetQueryPtr query, Promise<NetQueryPtr> promise);
|
2018-04-19 17:39:30 +02:00
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void hangup() final;
|
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
|