From 95f2961c9b40500523d564cd7c3f4c0a7ddf219d Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 8 May 2023 14:41:08 +0300 Subject: [PATCH] Move UserPrivacySetting to a separate header. --- CMakeLists.txt | 2 + td/telegram/PrivacyManager.cpp | 139 -------------------------- td/telegram/PrivacyManager.h | 35 +------ td/telegram/UserPrivacySetting.cpp | 150 +++++++++++++++++++++++++++++ td/telegram/UserPrivacySetting.h | 51 ++++++++++ 5 files changed, 204 insertions(+), 173 deletions(-) create mode 100644 td/telegram/UserPrivacySetting.cpp create mode 100644 td/telegram/UserPrivacySetting.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 068e947b5..7df922305 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -481,6 +481,7 @@ set(TDLIB_SOURCE td/telegram/TranslationManager.cpp td/telegram/UpdatesManager.cpp td/telegram/Usernames.cpp + td/telegram/UserPrivacySetting.cpp td/telegram/UserPrivacySettingRule.cpp td/telegram/Venue.cpp td/telegram/VideoNotesManager.cpp @@ -774,6 +775,7 @@ set(TDLIB_SOURCE td/telegram/UpdatesManager.h td/telegram/UserId.h td/telegram/Usernames.h + td/telegram/UserPrivacySetting.h td/telegram/UserPrivacySettingRule.h td/telegram/Venue.h td/telegram/Version.h diff --git a/td/telegram/PrivacyManager.cpp b/td/telegram/PrivacyManager.cpp index 6248e9805..77fa3c7f8 100644 --- a/td/telegram/PrivacyManager.cpp +++ b/td/telegram/PrivacyManager.cpp @@ -21,145 +21,6 @@ namespace td { -Result PrivacyManager::UserPrivacySetting::get_user_privacy_setting( - tl_object_ptr key) { - if (key == nullptr) { - return Status::Error(400, "UserPrivacySetting must be non-empty"); - } - return UserPrivacySetting(*key); -} - -PrivacyManager::UserPrivacySetting::UserPrivacySetting(const telegram_api::PrivacyKey &key) { - switch (key.get_id()) { - case telegram_api::privacyKeyStatusTimestamp::ID: - type_ = Type::UserStatus; - break; - case telegram_api::privacyKeyChatInvite::ID: - type_ = Type::ChatInvite; - break; - case telegram_api::privacyKeyPhoneCall::ID: - type_ = Type::Call; - break; - case telegram_api::privacyKeyPhoneP2P::ID: - type_ = Type::PeerToPeerCall; - break; - case telegram_api::privacyKeyForwards::ID: - type_ = Type::LinkInForwardedMessages; - break; - case telegram_api::privacyKeyProfilePhoto::ID: - type_ = Type::UserProfilePhoto; - break; - case telegram_api::privacyKeyPhoneNumber::ID: - type_ = Type::UserPhoneNumber; - break; - case telegram_api::privacyKeyAddedByPhone::ID: - type_ = Type::FindByPhoneNumber; - break; - case telegram_api::privacyKeyVoiceMessages::ID: - type_ = Type::VoiceMessages; - break; - case telegram_api::privacyKeyAbout::ID: - type_ = Type::UserBio; - break; - default: - UNREACHABLE(); - type_ = Type::UserStatus; - } -} - -tl_object_ptr PrivacyManager::UserPrivacySetting::get_user_privacy_setting_object() const { - switch (type_) { - case Type::UserStatus: - return make_tl_object(); - case Type::ChatInvite: - return make_tl_object(); - case Type::Call: - return make_tl_object(); - case Type::PeerToPeerCall: - return make_tl_object(); - case Type::LinkInForwardedMessages: - return make_tl_object(); - case Type::UserProfilePhoto: - return make_tl_object(); - case Type::UserPhoneNumber: - return make_tl_object(); - case Type::FindByPhoneNumber: - return make_tl_object(); - case Type::VoiceMessages: - return make_tl_object(); - case Type::UserBio: - return make_tl_object(); - default: - UNREACHABLE(); - return nullptr; - } -} -tl_object_ptr PrivacyManager::UserPrivacySetting::get_input_privacy_key() const { - switch (type_) { - case Type::UserStatus: - return make_tl_object(); - case Type::ChatInvite: - return make_tl_object(); - case Type::Call: - return make_tl_object(); - case Type::PeerToPeerCall: - return make_tl_object(); - case Type::LinkInForwardedMessages: - return make_tl_object(); - case Type::UserProfilePhoto: - return make_tl_object(); - case Type::UserPhoneNumber: - return make_tl_object(); - case Type::FindByPhoneNumber: - return make_tl_object(); - case Type::VoiceMessages: - return make_tl_object(); - case Type::UserBio: - return make_tl_object(); - default: - UNREACHABLE(); - return nullptr; - } -} - -PrivacyManager::UserPrivacySetting::UserPrivacySetting(const td_api::UserPrivacySetting &key) { - switch (key.get_id()) { - case td_api::userPrivacySettingShowStatus::ID: - type_ = Type::UserStatus; - break; - case td_api::userPrivacySettingAllowChatInvites::ID: - type_ = Type::ChatInvite; - break; - case td_api::userPrivacySettingAllowCalls::ID: - type_ = Type::Call; - break; - case td_api::userPrivacySettingAllowPeerToPeerCalls::ID: - type_ = Type::PeerToPeerCall; - break; - case td_api::userPrivacySettingShowLinkInForwardedMessages::ID: - type_ = Type::LinkInForwardedMessages; - break; - case td_api::userPrivacySettingShowProfilePhoto::ID: - type_ = Type::UserProfilePhoto; - break; - case td_api::userPrivacySettingShowPhoneNumber::ID: - type_ = Type::UserPhoneNumber; - break; - case td_api::userPrivacySettingAllowFindingByPhoneNumber::ID: - type_ = Type::FindByPhoneNumber; - break; - case td_api::userPrivacySettingAllowPrivateVoiceAndVideoNoteMessages::ID: - type_ = Type::VoiceMessages; - break; - case td_api::userPrivacySettingShowBio::ID: - type_ = Type::UserBio; - break; - default: - UNREACHABLE(); - type_ = Type::UserStatus; - } -} - void PrivacyManager::get_privacy(tl_object_ptr key, Promise> promise) { auto r_user_privacy_setting = UserPrivacySetting::get_user_privacy_setting(std::move(key)); diff --git a/td/telegram/PrivacyManager.h b/td/telegram/PrivacyManager.h index 06f2565f9..c67e81eb1 100644 --- a/td/telegram/PrivacyManager.h +++ b/td/telegram/PrivacyManager.h @@ -9,6 +9,7 @@ #include "td/telegram/net/NetQuery.h" #include "td/telegram/td_api.h" #include "td/telegram/telegram_api.h" +#include "td/telegram/UserPrivacySetting.h" #include "td/telegram/UserPrivacySettingRule.h" #include "td/actor/actor.h" @@ -36,40 +37,6 @@ class PrivacyManager final : public NetQueryCallback { void update_privacy(tl_object_ptr update); private: - class UserPrivacySetting { - public: - enum class Type : int32 { - UserStatus, - ChatInvite, - Call, - PeerToPeerCall, - LinkInForwardedMessages, - UserProfilePhoto, - UserPhoneNumber, - FindByPhoneNumber, - VoiceMessages, - UserBio, - Size - }; - - explicit UserPrivacySetting(const telegram_api::PrivacyKey &key); - - static Result get_user_privacy_setting(tl_object_ptr key); - - tl_object_ptr get_user_privacy_setting_object() const; - - tl_object_ptr get_input_privacy_key() const; - - Type type() const { - return type_; - } - - private: - Type type_; - - explicit UserPrivacySetting(const td_api::UserPrivacySetting &key); - }; - ActorShared<> parent_; struct PrivacyInfo { diff --git a/td/telegram/UserPrivacySetting.cpp b/td/telegram/UserPrivacySetting.cpp new file mode 100644 index 000000000..3aa9a6943 --- /dev/null +++ b/td/telegram/UserPrivacySetting.cpp @@ -0,0 +1,150 @@ +// +// 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) +// +#include "td/telegram/UserPrivacySetting.h" + +namespace td { + +Result UserPrivacySetting::get_user_privacy_setting( + td_api::object_ptr key) { + if (key == nullptr) { + return Status::Error(400, "UserPrivacySetting must be non-empty"); + } + return UserPrivacySetting(*key); +} + +UserPrivacySetting::UserPrivacySetting(const telegram_api::PrivacyKey &key) { + switch (key.get_id()) { + case telegram_api::privacyKeyStatusTimestamp::ID: + type_ = Type::UserStatus; + break; + case telegram_api::privacyKeyChatInvite::ID: + type_ = Type::ChatInvite; + break; + case telegram_api::privacyKeyPhoneCall::ID: + type_ = Type::Call; + break; + case telegram_api::privacyKeyPhoneP2P::ID: + type_ = Type::PeerToPeerCall; + break; + case telegram_api::privacyKeyForwards::ID: + type_ = Type::LinkInForwardedMessages; + break; + case telegram_api::privacyKeyProfilePhoto::ID: + type_ = Type::UserProfilePhoto; + break; + case telegram_api::privacyKeyPhoneNumber::ID: + type_ = Type::UserPhoneNumber; + break; + case telegram_api::privacyKeyAddedByPhone::ID: + type_ = Type::FindByPhoneNumber; + break; + case telegram_api::privacyKeyVoiceMessages::ID: + type_ = Type::VoiceMessages; + break; + case telegram_api::privacyKeyAbout::ID: + type_ = Type::UserBio; + break; + default: + UNREACHABLE(); + type_ = Type::UserStatus; + } +} + +td_api::object_ptr UserPrivacySetting::get_user_privacy_setting_object() const { + switch (type_) { + case Type::UserStatus: + return make_tl_object(); + case Type::ChatInvite: + return make_tl_object(); + case Type::Call: + return make_tl_object(); + case Type::PeerToPeerCall: + return make_tl_object(); + case Type::LinkInForwardedMessages: + return make_tl_object(); + case Type::UserProfilePhoto: + return make_tl_object(); + case Type::UserPhoneNumber: + return make_tl_object(); + case Type::FindByPhoneNumber: + return make_tl_object(); + case Type::VoiceMessages: + return make_tl_object(); + case Type::UserBio: + return make_tl_object(); + default: + UNREACHABLE(); + return nullptr; + } +} +telegram_api::object_ptr UserPrivacySetting::get_input_privacy_key() const { + switch (type_) { + case Type::UserStatus: + return make_tl_object(); + case Type::ChatInvite: + return make_tl_object(); + case Type::Call: + return make_tl_object(); + case Type::PeerToPeerCall: + return make_tl_object(); + case Type::LinkInForwardedMessages: + return make_tl_object(); + case Type::UserProfilePhoto: + return make_tl_object(); + case Type::UserPhoneNumber: + return make_tl_object(); + case Type::FindByPhoneNumber: + return make_tl_object(); + case Type::VoiceMessages: + return make_tl_object(); + case Type::UserBio: + return make_tl_object(); + default: + UNREACHABLE(); + return nullptr; + } +} + +UserPrivacySetting::UserPrivacySetting(const td_api::UserPrivacySetting &key) { + switch (key.get_id()) { + case td_api::userPrivacySettingShowStatus::ID: + type_ = Type::UserStatus; + break; + case td_api::userPrivacySettingAllowChatInvites::ID: + type_ = Type::ChatInvite; + break; + case td_api::userPrivacySettingAllowCalls::ID: + type_ = Type::Call; + break; + case td_api::userPrivacySettingAllowPeerToPeerCalls::ID: + type_ = Type::PeerToPeerCall; + break; + case td_api::userPrivacySettingShowLinkInForwardedMessages::ID: + type_ = Type::LinkInForwardedMessages; + break; + case td_api::userPrivacySettingShowProfilePhoto::ID: + type_ = Type::UserProfilePhoto; + break; + case td_api::userPrivacySettingShowPhoneNumber::ID: + type_ = Type::UserPhoneNumber; + break; + case td_api::userPrivacySettingAllowFindingByPhoneNumber::ID: + type_ = Type::FindByPhoneNumber; + break; + case td_api::userPrivacySettingAllowPrivateVoiceAndVideoNoteMessages::ID: + type_ = Type::VoiceMessages; + break; + case td_api::userPrivacySettingShowBio::ID: + type_ = Type::UserBio; + break; + default: + UNREACHABLE(); + type_ = Type::UserStatus; + } +} + +} // namespace td diff --git a/td/telegram/UserPrivacySetting.h b/td/telegram/UserPrivacySetting.h new file mode 100644 index 000000000..b69a6f836 --- /dev/null +++ b/td/telegram/UserPrivacySetting.h @@ -0,0 +1,51 @@ +// +// 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 + +#include "td/telegram/td_api.h" +#include "td/telegram/telegram_api.h" + +#include "td/utils/common.h" +#include "td/utils/Status.h" + +namespace td { + +class UserPrivacySetting { + public: + enum class Type : int32 { + UserStatus, + ChatInvite, + Call, + PeerToPeerCall, + LinkInForwardedMessages, + UserProfilePhoto, + UserPhoneNumber, + FindByPhoneNumber, + VoiceMessages, + UserBio, + Size + }; + + explicit UserPrivacySetting(const telegram_api::PrivacyKey &key); + + static Result get_user_privacy_setting(td_api::object_ptr key); + + td_api::object_ptr get_user_privacy_setting_object() const; + + telegram_api::object_ptr get_input_privacy_key() const; + + Type type() const { + return type_; + } + + private: + Type type_; + + explicit UserPrivacySetting(const td_api::UserPrivacySetting &key); +}; + +} // namespace td