2023-05-08 12:50:51 +02: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-07-03 18:20:41 +02:00
|
|
|
#include "td/telegram/DialogId.h"
|
2023-05-08 12:50:51 +02:00
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
#include "td/telegram/telegram_api.h"
|
|
|
|
#include "td/telegram/UserId.h"
|
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/Status.h"
|
2023-05-08 17:30:44 +02:00
|
|
|
#include "td/utils/tl_helpers.h"
|
2023-05-08 12:50:51 +02:00
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2023-07-03 19:03:26 +02:00
|
|
|
class Dependencies;
|
2023-05-08 13:15:32 +02:00
|
|
|
class Td;
|
|
|
|
|
2023-05-08 12:50:51 +02:00
|
|
|
class UserPrivacySettingRule {
|
|
|
|
public:
|
|
|
|
UserPrivacySettingRule() = default;
|
|
|
|
|
2023-05-08 13:15:32 +02:00
|
|
|
UserPrivacySettingRule(Td *td, const td_api::UserPrivacySettingRule &rule);
|
2023-05-08 12:50:51 +02:00
|
|
|
|
2023-07-03 18:20:41 +02:00
|
|
|
UserPrivacySettingRule(Td *td, const telegram_api::object_ptr<telegram_api::PrivacyRule> &rule);
|
2023-05-08 12:50:51 +02:00
|
|
|
|
2023-05-08 13:15:32 +02:00
|
|
|
td_api::object_ptr<td_api::UserPrivacySettingRule> get_user_privacy_setting_rule_object(Td *td) const;
|
2023-05-08 12:50:51 +02:00
|
|
|
|
2023-05-08 13:15:32 +02:00
|
|
|
telegram_api::object_ptr<telegram_api::InputPrivacyRule> get_input_privacy_rule(Td *td) const;
|
2023-05-08 12:50:51 +02:00
|
|
|
|
|
|
|
bool operator==(const UserPrivacySettingRule &other) const {
|
2023-07-03 18:20:41 +02:00
|
|
|
return type_ == other.type_ && user_ids_ == other.user_ids_ && dialog_ids_ == other.dialog_ids_;
|
2023-05-08 12:50:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
vector<UserId> get_restricted_user_ids() const;
|
|
|
|
|
2023-07-03 19:03:26 +02:00
|
|
|
void add_dependencies(Dependencies &dependencies) const;
|
|
|
|
|
2023-05-08 17:30:44 +02:00
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const {
|
|
|
|
td::store(type_, storer);
|
|
|
|
if (type_ == Type::AllowUsers || type_ == Type::RestrictUsers) {
|
|
|
|
td::store(user_ids_, storer);
|
|
|
|
}
|
|
|
|
if (type_ == Type::AllowChatParticipants || type_ == Type::RestrictChatParticipants) {
|
2023-07-03 18:20:41 +02:00
|
|
|
td::store(dialog_ids_, storer);
|
2023-05-08 17:30:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser) {
|
|
|
|
td::parse(type_, parser);
|
|
|
|
if (type_ == Type::AllowUsers || type_ == Type::RestrictUsers) {
|
|
|
|
td::parse(user_ids_, parser);
|
2023-07-03 18:30:50 +02:00
|
|
|
for (auto user_id : user_ids_) {
|
|
|
|
if (!user_id.is_valid()) {
|
|
|
|
parser.set_error("Failed to parse user identifiers");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (type_ == Type::AllowChatParticipants || type_ == Type::RestrictChatParticipants) {
|
2023-07-03 18:20:41 +02:00
|
|
|
td::parse(dialog_ids_, parser);
|
2023-07-03 18:30:50 +02:00
|
|
|
for (auto dialog_id : dialog_ids_) {
|
|
|
|
auto dialog_type = dialog_id.get_type();
|
|
|
|
if (!dialog_id.is_valid() || (dialog_type != DialogType::Chat && dialog_type != DialogType::Channel)) {
|
|
|
|
parser.set_error("Failed to parse chat identifiers");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (type_ != Type::AllowContacts && type_ != Type::AllowCloseFriends && type_ != Type::AllowAll &&
|
|
|
|
type_ != Type::RestrictContacts && type_ != Type::RestrictAll) {
|
|
|
|
parser.set_error("Invalid privacy rule type");
|
2023-05-08 17:30:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-08 12:50:51 +02:00
|
|
|
private:
|
|
|
|
enum class Type : int32 {
|
|
|
|
AllowContacts,
|
|
|
|
AllowCloseFriends,
|
|
|
|
AllowAll,
|
|
|
|
AllowUsers,
|
|
|
|
AllowChatParticipants,
|
|
|
|
RestrictContacts,
|
|
|
|
RestrictAll,
|
|
|
|
RestrictUsers,
|
|
|
|
RestrictChatParticipants
|
|
|
|
} type_ = Type::RestrictAll;
|
|
|
|
|
2023-07-18 15:00:06 +02:00
|
|
|
friend class UserPrivacySettingRules;
|
|
|
|
|
2023-05-08 12:50:51 +02:00
|
|
|
vector<UserId> user_ids_;
|
2023-07-03 18:20:41 +02:00
|
|
|
vector<DialogId> dialog_ids_;
|
2023-05-08 12:50:51 +02:00
|
|
|
|
2023-05-08 13:15:32 +02:00
|
|
|
vector<telegram_api::object_ptr<telegram_api::InputUser>> get_input_users(Td *td) const;
|
2023-05-08 12:50:51 +02:00
|
|
|
|
2023-07-03 18:20:41 +02:00
|
|
|
vector<int64> get_input_chat_ids(Td *td) const;
|
2023-05-08 12:50:51 +02:00
|
|
|
|
2023-07-03 18:20:41 +02:00
|
|
|
void set_dialog_ids(Td *td, const vector<int64> &chat_ids);
|
2023-05-08 12:50:51 +02:00
|
|
|
|
2023-07-03 18:20:41 +02:00
|
|
|
void set_dialog_ids_from_server(Td *td, const vector<int64> &chat_ids);
|
2023-05-08 12:50:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class UserPrivacySettingRules {
|
|
|
|
public:
|
|
|
|
UserPrivacySettingRules() = default;
|
|
|
|
|
2023-05-08 13:54:57 +02:00
|
|
|
static UserPrivacySettingRules get_user_privacy_setting_rules(
|
2023-05-08 13:15:32 +02:00
|
|
|
Td *td, telegram_api::object_ptr<telegram_api::account_privacyRules> rules);
|
2023-05-08 12:50:51 +02:00
|
|
|
|
2023-05-08 13:54:57 +02:00
|
|
|
static UserPrivacySettingRules get_user_privacy_setting_rules(
|
2023-05-08 13:15:32 +02:00
|
|
|
Td *td, vector<telegram_api::object_ptr<telegram_api::PrivacyRule>> rules);
|
2023-05-08 12:50:51 +02:00
|
|
|
|
|
|
|
static Result<UserPrivacySettingRules> get_user_privacy_setting_rules(
|
2023-05-08 13:15:32 +02:00
|
|
|
Td *td, td_api::object_ptr<td_api::userPrivacySettingRules> rules);
|
2023-05-08 12:50:51 +02:00
|
|
|
|
2023-07-18 15:00:06 +02:00
|
|
|
static Result<UserPrivacySettingRules> get_user_privacy_setting_rules(
|
|
|
|
Td *td, td_api::object_ptr<td_api::StoryPrivacySettings> settings);
|
|
|
|
|
2023-05-08 13:15:32 +02:00
|
|
|
td_api::object_ptr<td_api::userPrivacySettingRules> get_user_privacy_setting_rules_object(Td *td) const;
|
2023-05-08 12:50:51 +02:00
|
|
|
|
2023-07-18 15:00:06 +02:00
|
|
|
td_api::object_ptr<td_api::StoryPrivacySettings> get_story_privacy_settings_object(Td *td) const;
|
|
|
|
|
2023-05-08 13:15:32 +02:00
|
|
|
vector<telegram_api::object_ptr<telegram_api::InputPrivacyRule>> get_input_privacy_rules(Td *td) const;
|
2023-05-08 12:50:51 +02:00
|
|
|
|
|
|
|
bool operator==(const UserPrivacySettingRules &other) const {
|
|
|
|
return rules_ == other.rules_;
|
|
|
|
}
|
|
|
|
|
2023-06-13 13:01:30 +02:00
|
|
|
bool operator!=(const UserPrivacySettingRules &other) const {
|
|
|
|
return !(rules_ == other.rules_);
|
|
|
|
}
|
|
|
|
|
2023-05-08 12:50:51 +02:00
|
|
|
vector<UserId> get_restricted_user_ids() const;
|
|
|
|
|
2023-07-03 19:03:26 +02:00
|
|
|
void add_dependencies(Dependencies &dependencies) const;
|
|
|
|
|
2023-05-08 17:30:44 +02:00
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const {
|
|
|
|
td::store(rules_, storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser) {
|
|
|
|
td::parse(rules_, parser);
|
|
|
|
}
|
|
|
|
|
2023-05-08 12:50:51 +02:00
|
|
|
private:
|
|
|
|
vector<UserPrivacySettingRule> rules_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|