Skip to content

Commit

Permalink
Move UserPrivacySetting to a separate header.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed May 8, 2023
1 parent c4504af commit 95f2961
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 173 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
139 changes: 0 additions & 139 deletions td/telegram/PrivacyManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,145 +21,6 @@

namespace td {

Result<PrivacyManager::UserPrivacySetting> PrivacyManager::UserPrivacySetting::get_user_privacy_setting(
tl_object_ptr<td_api::UserPrivacySetting> 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<td_api::UserPrivacySetting> PrivacyManager::UserPrivacySetting::get_user_privacy_setting_object() const {
switch (type_) {
case Type::UserStatus:
return make_tl_object<td_api::userPrivacySettingShowStatus>();
case Type::ChatInvite:
return make_tl_object<td_api::userPrivacySettingAllowChatInvites>();
case Type::Call:
return make_tl_object<td_api::userPrivacySettingAllowCalls>();
case Type::PeerToPeerCall:
return make_tl_object<td_api::userPrivacySettingAllowPeerToPeerCalls>();
case Type::LinkInForwardedMessages:
return make_tl_object<td_api::userPrivacySettingShowLinkInForwardedMessages>();
case Type::UserProfilePhoto:
return make_tl_object<td_api::userPrivacySettingShowProfilePhoto>();
case Type::UserPhoneNumber:
return make_tl_object<td_api::userPrivacySettingShowPhoneNumber>();
case Type::FindByPhoneNumber:
return make_tl_object<td_api::userPrivacySettingAllowFindingByPhoneNumber>();
case Type::VoiceMessages:
return make_tl_object<td_api::userPrivacySettingAllowPrivateVoiceAndVideoNoteMessages>();
case Type::UserBio:
return make_tl_object<td_api::userPrivacySettingShowBio>();
default:
UNREACHABLE();
return nullptr;
}
}
tl_object_ptr<telegram_api::InputPrivacyKey> PrivacyManager::UserPrivacySetting::get_input_privacy_key() const {
switch (type_) {
case Type::UserStatus:
return make_tl_object<telegram_api::inputPrivacyKeyStatusTimestamp>();
case Type::ChatInvite:
return make_tl_object<telegram_api::inputPrivacyKeyChatInvite>();
case Type::Call:
return make_tl_object<telegram_api::inputPrivacyKeyPhoneCall>();
case Type::PeerToPeerCall:
return make_tl_object<telegram_api::inputPrivacyKeyPhoneP2P>();
case Type::LinkInForwardedMessages:
return make_tl_object<telegram_api::inputPrivacyKeyForwards>();
case Type::UserProfilePhoto:
return make_tl_object<telegram_api::inputPrivacyKeyProfilePhoto>();
case Type::UserPhoneNumber:
return make_tl_object<telegram_api::inputPrivacyKeyPhoneNumber>();
case Type::FindByPhoneNumber:
return make_tl_object<telegram_api::inputPrivacyKeyAddedByPhone>();
case Type::VoiceMessages:
return make_tl_object<telegram_api::inputPrivacyKeyVoiceMessages>();
case Type::UserBio:
return make_tl_object<telegram_api::inputPrivacyKeyAbout>();
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<td_api::UserPrivacySetting> key,
Promise<tl_object_ptr<td_api::userPrivacySettingRules>> promise) {
auto r_user_privacy_setting = UserPrivacySetting::get_user_privacy_setting(std::move(key));
Expand Down
35 changes: 1 addition & 34 deletions td/telegram/PrivacyManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -36,40 +37,6 @@ class PrivacyManager final : public NetQueryCallback {
void update_privacy(tl_object_ptr<telegram_api::updatePrivacy> 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<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;

Type type() const {
return type_;
}

private:
Type type_;

explicit UserPrivacySetting(const td_api::UserPrivacySetting &key);
};

ActorShared<> parent_;

struct PrivacyInfo {
Expand Down
150 changes: 150 additions & 0 deletions td/telegram/UserPrivacySetting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
//
// Copyright Aliaksei Levin ([email protected]), Arseny Smirnov ([email protected]) 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> UserPrivacySetting::get_user_privacy_setting(
td_api::object_ptr<td_api::UserPrivacySetting> 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<td_api::UserPrivacySetting> UserPrivacySetting::get_user_privacy_setting_object() const {
switch (type_) {
case Type::UserStatus:
return make_tl_object<td_api::userPrivacySettingShowStatus>();
case Type::ChatInvite:
return make_tl_object<td_api::userPrivacySettingAllowChatInvites>();
case Type::Call:
return make_tl_object<td_api::userPrivacySettingAllowCalls>();
case Type::PeerToPeerCall:
return make_tl_object<td_api::userPrivacySettingAllowPeerToPeerCalls>();
case Type::LinkInForwardedMessages:
return make_tl_object<td_api::userPrivacySettingShowLinkInForwardedMessages>();
case Type::UserProfilePhoto:
return make_tl_object<td_api::userPrivacySettingShowProfilePhoto>();
case Type::UserPhoneNumber:
return make_tl_object<td_api::userPrivacySettingShowPhoneNumber>();
case Type::FindByPhoneNumber:
return make_tl_object<td_api::userPrivacySettingAllowFindingByPhoneNumber>();
case Type::VoiceMessages:
return make_tl_object<td_api::userPrivacySettingAllowPrivateVoiceAndVideoNoteMessages>();
case Type::UserBio:
return make_tl_object<td_api::userPrivacySettingShowBio>();
default:
UNREACHABLE();
return nullptr;
}
}
telegram_api::object_ptr<telegram_api::InputPrivacyKey> UserPrivacySetting::get_input_privacy_key() const {
switch (type_) {
case Type::UserStatus:
return make_tl_object<telegram_api::inputPrivacyKeyStatusTimestamp>();
case Type::ChatInvite:
return make_tl_object<telegram_api::inputPrivacyKeyChatInvite>();
case Type::Call:
return make_tl_object<telegram_api::inputPrivacyKeyPhoneCall>();
case Type::PeerToPeerCall:
return make_tl_object<telegram_api::inputPrivacyKeyPhoneP2P>();
case Type::LinkInForwardedMessages:
return make_tl_object<telegram_api::inputPrivacyKeyForwards>();
case Type::UserProfilePhoto:
return make_tl_object<telegram_api::inputPrivacyKeyProfilePhoto>();
case Type::UserPhoneNumber:
return make_tl_object<telegram_api::inputPrivacyKeyPhoneNumber>();
case Type::FindByPhoneNumber:
return make_tl_object<telegram_api::inputPrivacyKeyAddedByPhone>();
case Type::VoiceMessages:
return make_tl_object<telegram_api::inputPrivacyKeyVoiceMessages>();
case Type::UserBio:
return make_tl_object<telegram_api::inputPrivacyKeyAbout>();
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
Loading

0 comments on commit 95f2961

Please sign in to comment.