diff --git a/SplitSource.php b/SplitSource.php index 1c33db4d2..910be1ffc 100644 --- a/SplitSource.php +++ b/SplitSource.php @@ -281,7 +281,7 @@ function split_file($file, $chunks, $undo) { 'secret_chats_manager[_(-][^.]|SecretChatsManager' => 'SecretChatsManager', 'stickers_manager[_(-][^.]|StickersManager' => 'StickersManager', '[>](td_db[(][)]|get_td_db_impl[(])|TdDb[^A-Za-z]' => 'TdDb', - 'TopDialogCategory|top_dialog_category_from_td_api' => 'TopDialogCategory', + 'TopDialogCategory|get_top_dialog_category' => 'TopDialogCategory', 'top_dialog_manager[_(-][^.]|TopDialogManager' => 'TopDialogManager', 'updates_manager[_(-][^.]|UpdatesManager|get_difference[)]' => 'UpdatesManager', 'WebPageId(Hash)?' => 'WebPageId', diff --git a/td/telegram/CallActor.cpp b/td/telegram/CallActor.cpp index 1df247eb6..6ac0d8529 100644 --- a/td/telegram/CallActor.cpp +++ b/td/telegram/CallActor.cpp @@ -28,6 +28,7 @@ #include "td/utils/common.h" #include "td/utils/crypto.h" #include "td/utils/logging.h" +#include "td/utils/misc.h" #include "td/utils/Random.h" #include @@ -35,17 +36,15 @@ namespace td { -CallProtocol CallProtocol::from_telegram_api(const telegram_api::phoneCallProtocol &protocol) { - CallProtocol res; - res.udp_p2p = protocol.udp_p2p_; - res.udp_reflector = protocol.udp_reflector_; - res.min_layer = protocol.min_layer_; - res.max_layer = protocol.max_layer_; - res.library_versions = protocol.library_versions_; - return res; +CallProtocol::CallProtocol(const telegram_api::phoneCallProtocol &protocol) + : udp_p2p(protocol.udp_p2p_) + , udp_reflector(protocol.udp_reflector_) + , min_layer(protocol.min_layer_) + , max_layer(protocol.max_layer_) + , library_versions(protocol.library_versions_) { } -tl_object_ptr CallProtocol::as_telegram_api() const { +tl_object_ptr CallProtocol::get_input_phone_call_protocol() const { int32 flags = 0; if (udp_p2p) { flags |= telegram_api::phoneCallProtocol::UDP_P2P_MASK; @@ -57,51 +56,45 @@ tl_object_ptr CallProtocol::as_telegram_api() c vector(library_versions)); } -CallProtocol CallProtocol::from_td_api(const td_api::callProtocol &protocol) { - CallProtocol res; - res.udp_p2p = protocol.udp_p2p_; - res.udp_reflector = protocol.udp_reflector_; - res.min_layer = protocol.min_layer_; - res.max_layer = protocol.max_layer_; - res.library_versions = protocol.library_versions_; - return res; +CallProtocol::CallProtocol(const td_api::callProtocol &protocol) + : udp_p2p(protocol.udp_p2p_) + , udp_reflector(protocol.udp_reflector_) + , min_layer(protocol.min_layer_) + , max_layer(protocol.max_layer_) + , library_versions(protocol.library_versions_) { } -tl_object_ptr CallProtocol::as_td_api() const { +CallConnection::CallConnection(const telegram_api::phoneConnection &connection) + : id(connection.id_) + , ip(connection.ip_) + , ipv6(connection.ipv6_) + , port(connection.port_) + , peer_tag(connection.peer_tag_.as_slice().str()) { +} + +tl_object_ptr CallProtocol::get_call_protocol_object() const { return make_tl_object(udp_p2p, udp_reflector, min_layer, max_layer, vector(library_versions)); } -CallConnection CallConnection::from_telegram_api(const telegram_api::phoneConnection &connection) { - CallConnection res; - res.id = connection.id_; - res.ip = connection.ip_; - res.ipv6 = connection.ipv6_; - res.port = connection.port_; - res.peer_tag = connection.peer_tag_.as_slice().str(); - return res; -} -tl_object_ptr CallConnection::as_telegram_api() const { +tl_object_ptr CallConnection::get_input_phone_connection() const { return make_tl_object(id, ip, ipv6, port, BufferSlice(peer_tag)); } -tl_object_ptr CallConnection::as_td_api() const { + +tl_object_ptr CallConnection::get_call_connection_object() const { return make_tl_object(id, ip, ipv6, port, peer_tag); } -// CallState -tl_object_ptr CallState::as_td_api() const { +tl_object_ptr CallState::get_call_state_object() const { switch (type) { case Type::Pending: return make_tl_object(is_created, is_received); case Type::ExchangingKey: return make_tl_object(); case Type::Ready: { - std::vector> v; - for (auto &c : connections) { - v.push_back(c.as_td_api()); - } - return make_tl_object(protocol.as_td_api(), std::move(v), config, key, - vector(emojis_fingerprint), allow_p2p); + auto call_connections = transform(connections, [](auto &c) { return c.get_call_connection_object(); }); + return make_tl_object(protocol.get_call_protocol_object(), std::move(call_connections), + config, key, vector(emojis_fingerprint), allow_p2p); } case Type::HangingUp: return make_tl_object(); @@ -428,9 +421,9 @@ Status CallActor::do_update_call(telegram_api::phoneCall &call) { get_emojis_fingerprint(call_state_.key, is_outgoing_ ? dh_handshake_.get_g_b() : dh_handshake_.get_g_a()); for (auto &connection : call.connections_) { - call_state_.connections.push_back(CallConnection::from_telegram_api(*connection)); + call_state_.connections.push_back(CallConnection(*connection)); } - call_state_.protocol = CallProtocol::from_telegram_api(*call.protocol_); + call_state_.protocol = CallProtocol(*call.protocol_); call_state_.allow_p2p = (call.flags_ & telegram_api::phoneCall::P2P_ALLOWED_MASK) != 0; call_state_.type = CallState::Type::Ready; call_state_need_flush_ = true; @@ -575,7 +568,7 @@ void CallActor::try_send_request_query() { } auto tl_query = telegram_api::phone_requestCall(flags, false /*ignored*/, std::move(input_user_), Random::secure_int32(), BufferSlice(dh_handshake_.get_g_b_hash()), - call_state_.protocol.as_telegram_api()); + call_state_.protocol.get_input_phone_call_protocol()); auto query = G()->net_query_creator().create(tl_query); state_ = State::WaitRequestResult; int32 call_receive_timeout_ms = G()->shared_config().get_option_integer("call_receive_timeout_ms", 20000); @@ -608,9 +601,9 @@ void CallActor::try_send_accept_query() { return; } dh_handshake_.set_config(dh_config_->g, dh_config_->prime); - auto tl_query = - telegram_api::phone_acceptCall(get_input_phone_call("try_send_accept_query"), - BufferSlice(dh_handshake_.get_g_b()), call_state_.protocol.as_telegram_api()); + auto tl_query = telegram_api::phone_acceptCall(get_input_phone_call("try_send_accept_query"), + BufferSlice(dh_handshake_.get_g_b()), + call_state_.protocol.get_input_phone_call_protocol()); auto query = G()->net_query_creator().create(tl_query); state_ = State::WaitAcceptResult; send_with_promise(std::move(query), PromiseCreator::lambda([actor_id = actor_id(this)](NetQueryPtr net_query) { @@ -634,7 +627,7 @@ void CallActor::try_send_confirm_query() { } auto tl_query = telegram_api::phone_confirmCall(get_input_phone_call("try_send_confirm_query"), BufferSlice(dh_handshake_.get_g_b()), call_state_.key_fingerprint, - call_state_.protocol.as_telegram_api()); + call_state_.protocol.get_input_phone_call_protocol()); auto query = G()->net_query_creator().create(tl_query); state_ = State::WaitConfirmResult; send_with_promise(std::move(query), PromiseCreator::lambda([actor_id = actor_id(this)](NetQueryPtr net_query) { @@ -708,7 +701,7 @@ void CallActor::flush_call_state() { send_closure(G()->td(), &Td::send_update, make_tl_object( make_tl_object(local_call_id_.get(), is_outgoing_ ? user_id_.get() : call_admin_id_, - is_outgoing_, call_state_.as_td_api()))); + is_outgoing_, call_state_.get_call_state_object()))); } } diff --git a/td/telegram/CallActor.h b/td/telegram/CallActor.h index fe57d9926..589696561 100644 --- a/td/telegram/CallActor.h +++ b/td/telegram/CallActor.h @@ -34,10 +34,15 @@ struct CallProtocol { int32 max_layer{65}; vector library_versions; - static CallProtocol from_telegram_api(const telegram_api::phoneCallProtocol &protocol); - tl_object_ptr as_telegram_api() const; - static CallProtocol from_td_api(const td_api::callProtocol &protocol); - tl_object_ptr as_td_api() const; + CallProtocol() = default; + + explicit CallProtocol(const td_api::callProtocol &protocol); + + explicit CallProtocol(const telegram_api::phoneCallProtocol &protocol); + + tl_object_ptr get_input_phone_call_protocol() const; + + tl_object_ptr get_call_protocol_object() const; }; struct CallConnection { @@ -47,9 +52,11 @@ struct CallConnection { int32 port; string peer_tag; - static CallConnection from_telegram_api(const telegram_api::phoneConnection &connection); - tl_object_ptr as_telegram_api() const; - tl_object_ptr as_td_api() const; + explicit CallConnection(const telegram_api::phoneConnection &connection); + + tl_object_ptr get_input_phone_connection() const; + + tl_object_ptr get_call_connection_object() const; }; struct CallState { @@ -71,7 +78,7 @@ struct CallState { Status error; - tl_object_ptr as_td_api() const; + tl_object_ptr get_call_state_object() const; }; class CallActor : public NetQueryCallback { diff --git a/td/telegram/CallId.h b/td/telegram/CallId.h index 21c27a2b9..c5ba8c514 100644 --- a/td/telegram/CallId.h +++ b/td/telegram/CallId.h @@ -34,8 +34,8 @@ class CallId { return id; } - auto as_td_api() const { - return make_tl_object(id); + auto get_call_id_object() const { + return td_api::make_object(id); } bool operator==(const CallId &other) const { diff --git a/td/telegram/PasswordManager.cpp b/td/telegram/PasswordManager.cpp index 6f4af18dd..5d2b64c8e 100644 --- a/td/telegram/PasswordManager.cpp +++ b/td/telegram/PasswordManager.cpp @@ -26,7 +26,7 @@ namespace td { -tl_object_ptr TempPasswordState::as_td_api() const { +tl_object_ptr TempPasswordState::get_temporary_password_state_object() const { if (!has_temp_password || valid_until <= G()->unix_time()) { return make_tl_object(false, 0); } @@ -234,7 +234,7 @@ void PasswordManager::do_get_secure_secret(bool allow_recursive, string password } void PasswordManager::get_temp_password_state(Promise promise) /*const*/ { - promise.set_value(temp_password_state_.as_td_api()); + promise.set_value(temp_password_state_.get_temporary_password_state_object()); } TempPasswordState PasswordManager::get_temp_password_state_sync() { @@ -298,7 +298,7 @@ void PasswordManager::on_finish_create_temp_password(Result r } temp_password_state_ = result.move_as_ok(); G()->td_db()->get_binlog_pmc()->set("temp_password", log_event_store(temp_password_state_).as_slice().str()); - create_temp_password_promise_.set_value(temp_password_state_.as_td_api()); + create_temp_password_promise_.set_value(temp_password_state_.get_temporary_password_state_object()); } void PasswordManager::get_full_state(string password, Promise promise) { @@ -625,7 +625,7 @@ void PasswordManager::get_state(Promise promise) { if (r_state.is_error()) { return promise.set_error(r_state.move_as_error()); } - promise.set_value(r_state.move_as_ok().as_td_api()); + promise.set_value(r_state.move_as_ok().get_password_state_object()); })); } diff --git a/td/telegram/PasswordManager.h b/td/telegram/PasswordManager.h index aad9a0b70..74625f2f6 100644 --- a/td/telegram/PasswordManager.h +++ b/td/telegram/PasswordManager.h @@ -30,7 +30,7 @@ struct TempPasswordState { string temp_password; int32 valid_until = 0; // unix_time - tl_object_ptr as_td_api() const; + tl_object_ptr get_temporary_password_state_object() const; template void store(StorerT &storer) const { @@ -116,7 +116,7 @@ class PasswordManager : public NetQueryCallback { string new_secure_salt; - State as_td_api() const { + State get_password_state_object() const { td_api::object_ptr code_info; if (!unconfirmed_recovery_email_address_pattern.empty()) { code_info = td_api::make_object( diff --git a/td/telegram/PrivacyManager.cpp b/td/telegram/PrivacyManager.cpp index d33c5f749..9d856ef12 100644 --- a/td/telegram/PrivacyManager.cpp +++ b/td/telegram/PrivacyManager.cpp @@ -27,7 +27,7 @@ namespace td { -Result PrivacyManager::UserPrivacySetting::from_td_api( +Result PrivacyManager::UserPrivacySetting::get_user_privacy_setting( tl_object_ptr key) { if (!key) { return Status::Error(5, "UserPrivacySetting must be non-empty"); @@ -67,7 +67,7 @@ PrivacyManager::UserPrivacySetting::UserPrivacySetting(const telegram_api::Priva } } -tl_object_ptr PrivacyManager::UserPrivacySetting::as_td_api() const { +tl_object_ptr PrivacyManager::UserPrivacySetting::get_user_privacy_setting_object() const { switch (type_) { case Type::UserStatus: return make_tl_object(); @@ -90,7 +90,7 @@ tl_object_ptr PrivacyManager::UserPrivacySetting::as return nullptr; } } -tl_object_ptr PrivacyManager::UserPrivacySetting::as_telegram_api() const { +tl_object_ptr PrivacyManager::UserPrivacySetting::get_input_privacy_key() const { switch (type_) { case Type::UserStatus: return make_tl_object(); @@ -245,7 +245,8 @@ PrivacyManager::UserPrivacySettingRule::UserPrivacySettingRule(const telegram_ap } } -tl_object_ptr PrivacyManager::UserPrivacySettingRule::as_td_api() const { +tl_object_ptr +PrivacyManager::UserPrivacySettingRule::get_user_privacy_setting_rule_object() const { switch (type_) { case Type::AllowContacts: return make_tl_object(); @@ -268,14 +269,14 @@ tl_object_ptr PrivacyManager::UserPrivacySetting } } -tl_object_ptr PrivacyManager::UserPrivacySettingRule::as_telegram_api() const { +tl_object_ptr PrivacyManager::UserPrivacySettingRule::get_input_privacy_rule() const { switch (type_) { case Type::AllowContacts: return make_tl_object(); case Type::AllowAll: return make_tl_object(); case Type::AllowUsers: - return make_tl_object(user_ids_as_telegram_api()); + return make_tl_object(get_input_users()); case Type::AllowChatParticipants: return make_tl_object(vector{chat_ids_}); case Type::RestrictContacts: @@ -283,7 +284,7 @@ tl_object_ptr PrivacyManager::UserPrivacySetting case Type::RestrictAll: return make_tl_object(); case Type::RestrictUsers: - return make_tl_object(user_ids_as_telegram_api()); + return make_tl_object(get_input_users()); case Type::RestrictChatParticipants: return make_tl_object(vector{chat_ids_}); default: @@ -291,7 +292,7 @@ tl_object_ptr PrivacyManager::UserPrivacySetting } } -Result PrivacyManager::UserPrivacySettingRule::from_telegram_api( +Result PrivacyManager::UserPrivacySettingRule::get_user_privacy_setting_rule( tl_object_ptr rule) { CHECK(rule != nullptr); UserPrivacySettingRule result(*rule); @@ -316,8 +317,7 @@ Result PrivacyManager::UserPrivacySettin return result; } -vector> PrivacyManager::UserPrivacySettingRule::user_ids_as_telegram_api() - const { +vector> PrivacyManager::UserPrivacySettingRule::get_input_users() const { vector> result; for (auto user_id : user_ids_) { auto input_user = G()->td().get_actor_unsafe()->contacts_manager_->get_input_user(UserId(user_id)); @@ -354,28 +354,28 @@ vector PrivacyManager::UserPrivacySettingRule::get_restricted_user_ids() return {}; } -Result PrivacyManager::UserPrivacySettingRules::from_telegram_api( +Result PrivacyManager::UserPrivacySettingRules::get_user_privacy_setting_rules( tl_object_ptr rules) { G()->td().get_actor_unsafe()->contacts_manager_->on_get_users(std::move(rules->users_), "on get privacy rules"); G()->td().get_actor_unsafe()->contacts_manager_->on_get_chats(std::move(rules->chats_), "on get privacy rules"); - return from_telegram_api(std::move(rules->rules_)); + return get_user_privacy_setting_rules(std::move(rules->rules_)); } -Result PrivacyManager::UserPrivacySettingRules::from_telegram_api( +Result PrivacyManager::UserPrivacySettingRules::get_user_privacy_setting_rules( vector> rules) { UserPrivacySettingRules result; for (auto &rule : rules) { - TRY_RESULT(new_rule, UserPrivacySettingRule::from_telegram_api(std::move(rule))); + TRY_RESULT(new_rule, UserPrivacySettingRule::get_user_privacy_setting_rule(std::move(rule))); result.rules_.push_back(new_rule); } - if (!result.rules_.empty() && - result.rules_.back().as_td_api()->get_id() == td_api::userPrivacySettingRuleRestrictAll::ID) { + if (!result.rules_.empty() && result.rules_.back().get_user_privacy_setting_rule_object()->get_id() == + td_api::userPrivacySettingRuleRestrictAll::ID) { result.rules_.pop_back(); } return result; } -Result PrivacyManager::UserPrivacySettingRules::from_td_api( +Result PrivacyManager::UserPrivacySettingRules::get_user_privacy_setting_rules( tl_object_ptr rules) { if (!rules) { return Status::Error(5, "UserPrivacySettingRules must be non-empty"); @@ -390,13 +390,15 @@ Result PrivacyManager::UserPrivacySetti return result; } -tl_object_ptr PrivacyManager::UserPrivacySettingRules::as_td_api() const { +tl_object_ptr +PrivacyManager::UserPrivacySettingRules::get_user_privacy_setting_rules_object() const { return make_tl_object( - transform(rules_, [](const auto &rule) { return rule.as_td_api(); })); + transform(rules_, [](const auto &rule) { return rule.get_user_privacy_setting_rule_object(); })); } -vector> PrivacyManager::UserPrivacySettingRules::as_telegram_api() const { - auto result = transform(rules_, [](const auto &rule) { return rule.as_telegram_api(); }); +vector> PrivacyManager::UserPrivacySettingRules::get_input_privacy_rules() + const { + auto result = transform(rules_, [](const auto &rule) { return rule.get_input_privacy_rule(); }); if (!result.empty() && result.back()->get_id() == telegram_api::inputPrivacyValueDisallowAll::ID) { result.pop_back(); } @@ -415,14 +417,14 @@ vector PrivacyManager::UserPrivacySettingRules::get_restricted_user_ids() void PrivacyManager::get_privacy(tl_object_ptr key, Promise> promise) { - auto r_user_privacy_setting = UserPrivacySetting::from_td_api(std::move(key)); + auto r_user_privacy_setting = UserPrivacySetting::get_user_privacy_setting(std::move(key)); if (r_user_privacy_setting.is_error()) { return promise.set_error(r_user_privacy_setting.move_as_error()); } auto user_privacy_setting = r_user_privacy_setting.move_as_ok(); auto &info = get_info(user_privacy_setting); if (info.is_synchronized) { - return promise.set_value(info.rules.as_td_api()); + return promise.set_value(info.rules.get_user_privacy_setting_rules_object()); } info.get_promises.push_back(std::move(promise)); if (info.get_promises.size() > 1u) { @@ -430,7 +432,7 @@ void PrivacyManager::get_privacy(tl_object_ptr key, return; } auto net_query = - G()->net_query_creator().create(telegram_api::account_getPrivacy(user_privacy_setting.as_telegram_api())); + G()->net_query_creator().create(telegram_api::account_getPrivacy(user_privacy_setting.get_input_privacy_key())); send_with_promise(std::move(net_query), PromiseCreator::lambda([this, user_privacy_setting](Result x_net_query) { @@ -438,20 +440,20 @@ void PrivacyManager::get_privacy(tl_object_ptr key, TRY_RESULT(net_query, std::move(x_net_query)); TRY_RESULT(rules, fetch_result(std::move(net_query))); LOG(INFO) << "Receive " << to_string(rules); - return UserPrivacySettingRules::from_telegram_api(std::move(rules)); + return UserPrivacySettingRules::get_user_privacy_setting_rules(std::move(rules)); }()); })); } void PrivacyManager::set_privacy(tl_object_ptr key, tl_object_ptr rules, Promise promise) { - auto r_user_privacy_setting = UserPrivacySetting::from_td_api(std::move(key)); + auto r_user_privacy_setting = UserPrivacySetting::get_user_privacy_setting(std::move(key)); if (r_user_privacy_setting.is_error()) { return promise.set_error(r_user_privacy_setting.move_as_error()); } auto user_privacy_setting = r_user_privacy_setting.move_as_ok(); - auto r_privacy_rules = UserPrivacySettingRules::from_td_api(std::move(rules)); + auto r_privacy_rules = UserPrivacySettingRules::get_user_privacy_setting_rules(std::move(rules)); if (r_privacy_rules.is_error()) { return promise.set_error(r_privacy_rules.move_as_error()); } @@ -462,30 +464,30 @@ void PrivacyManager::set_privacy(tl_object_ptr key, // TODO cancel previous query return promise.set_error(Status::Error(5, "Another set_privacy query is active")); } - auto net_query = G()->net_query_creator().create( - telegram_api::account_setPrivacy(user_privacy_setting.as_telegram_api(), privacy_rules.as_telegram_api())); + auto net_query = G()->net_query_creator().create(telegram_api::account_setPrivacy( + user_privacy_setting.get_input_privacy_key(), privacy_rules.get_input_privacy_rules())); info.has_set_query = true; - send_with_promise(std::move(net_query), - PromiseCreator::lambda([this, user_privacy_setting, - promise = std::move(promise)](Result x_net_query) mutable { - promise.set_result([&]() -> Result { - get_info(user_privacy_setting).has_set_query = false; - TRY_RESULT(net_query, std::move(x_net_query)); - TRY_RESULT(rules, fetch_result(std::move(net_query))); - LOG(INFO) << "Receive " << to_string(rules); - TRY_RESULT(privacy_rules, UserPrivacySettingRules::from_telegram_api(std::move(rules))); - do_update_privacy(user_privacy_setting, std::move(privacy_rules), true); - return Unit(); - }()); - })); + send_with_promise( + std::move(net_query), PromiseCreator::lambda([this, user_privacy_setting, promise = std::move(promise)]( + Result x_net_query) mutable { + promise.set_result([&]() -> Result { + get_info(user_privacy_setting).has_set_query = false; + TRY_RESULT(net_query, std::move(x_net_query)); + TRY_RESULT(rules, fetch_result(std::move(net_query))); + LOG(INFO) << "Receive " << to_string(rules); + TRY_RESULT(privacy_rules, UserPrivacySettingRules::get_user_privacy_setting_rules(std::move(rules))); + do_update_privacy(user_privacy_setting, std::move(privacy_rules), true); + return Unit(); + }()); + })); } void PrivacyManager::update_privacy(tl_object_ptr update) { CHECK(update != nullptr); CHECK(update->key_ != nullptr); UserPrivacySetting user_privacy_setting(*update->key_); - auto r_privacy_rules = UserPrivacySettingRules::from_telegram_api(std::move(update->rules_)); + auto r_privacy_rules = UserPrivacySettingRules::get_user_privacy_setting_rules(std::move(update->rules_)); if (r_privacy_rules.is_error()) { LOG(INFO) << "Skip updatePrivacy: " << r_privacy_rules.error().message(); auto &info = get_info(user_privacy_setting); @@ -504,7 +506,7 @@ void PrivacyManager::on_get_result(UserPrivacySetting user_privacy_setting, if (privacy_rules.is_error()) { promise.set_error(privacy_rules.error().clone()); } else { - promise.set_value(privacy_rules.ok().as_td_api()); + promise.set_value(privacy_rules.ok().get_user_privacy_setting_rules_object()); } } if (privacy_rules.is_ok()) { @@ -548,9 +550,10 @@ void PrivacyManager::do_update_privacy(UserPrivacySetting user_privacy_setting, } info.rules = std::move(privacy_rules); - send_closure(G()->td(), &Td::send_update, - make_tl_object(user_privacy_setting.as_td_api(), - info.rules.as_td_api())); + send_closure( + G()->td(), &Td::send_update, + make_tl_object(user_privacy_setting.get_user_privacy_setting_object(), + info.rules.get_user_privacy_setting_rules_object())); } } diff --git a/td/telegram/PrivacyManager.h b/td/telegram/PrivacyManager.h index 74a0e4b2b..906054c31 100644 --- a/td/telegram/PrivacyManager.h +++ b/td/telegram/PrivacyManager.h @@ -49,10 +49,13 @@ class PrivacyManager : public NetQueryCallback { Size }; - static Result from_td_api(tl_object_ptr key); explicit UserPrivacySetting(const telegram_api::PrivacyKey &key); - tl_object_ptr as_td_api() const; - tl_object_ptr as_telegram_api() const; + + 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_; @@ -67,10 +70,14 @@ class PrivacyManager : public NetQueryCallback { class UserPrivacySettingRule { public: UserPrivacySettingRule() = default; - static Result from_telegram_api(tl_object_ptr rule); + explicit UserPrivacySettingRule(const td_api::UserPrivacySettingRule &rule); - tl_object_ptr as_td_api() const; - tl_object_ptr as_telegram_api() const; + + static Result get_user_privacy_setting_rule(tl_object_ptr rule); + + tl_object_ptr get_user_privacy_setting_rule_object() const; + + tl_object_ptr get_input_privacy_rule() const; bool operator==(const UserPrivacySettingRule &other) const { return type_ == other.type_ && user_ids_ == other.user_ids_ && chat_ids_ == other.chat_ids_; @@ -93,7 +100,7 @@ class PrivacyManager : public NetQueryCallback { vector user_ids_; vector chat_ids_; - vector> user_ids_as_telegram_api() const; + vector> get_input_users() const; void set_chat_ids(const vector &dialog_ids); @@ -105,11 +112,19 @@ class PrivacyManager : public NetQueryCallback { class UserPrivacySettingRules { public: UserPrivacySettingRules() = default; - static Result from_telegram_api(tl_object_ptr rules); - static Result from_telegram_api(vector> rules); - static Result from_td_api(tl_object_ptr rules); - tl_object_ptr as_td_api() const; - vector> as_telegram_api() const; + + static Result get_user_privacy_setting_rules( + tl_object_ptr rules); + + static Result get_user_privacy_setting_rules( + vector> rules); + + static Result get_user_privacy_setting_rules( + tl_object_ptr rules); + + tl_object_ptr get_user_privacy_setting_rules_object() const; + + vector> get_input_privacy_rules() const; bool operator==(const UserPrivacySettingRules &other) const { return rules_ == other.rules_; diff --git a/td/telegram/StorageManager.cpp b/td/telegram/StorageManager.cpp index 886c3071b..270d778bc 100644 --- a/td/telegram/StorageManager.cpp +++ b/td/telegram/StorageManager.cpp @@ -26,7 +26,7 @@ namespace td { -tl_object_ptr DatabaseStats::as_td_api() const { +tl_object_ptr DatabaseStats::get_database_statistics_object() const { return make_tl_object(debug); } diff --git a/td/telegram/StorageManager.h b/td/telegram/StorageManager.h index 7af4086d5..a6a07071e 100644 --- a/td/telegram/StorageManager.h +++ b/td/telegram/StorageManager.h @@ -26,7 +26,7 @@ struct DatabaseStats { DatabaseStats() = default; explicit DatabaseStats(string debug) : debug(debug) { } - tl_object_ptr as_td_api() const; + tl_object_ptr get_database_statistics_object() const; }; class StorageManager : public Actor { diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 31d906a45..8d8c0d21f 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5105,7 +5105,7 @@ void Td::on_request(uint64 id, const td_api::getFile &request) { void Td::on_request(uint64 id, td_api::getRemoteFile &request) { CLEAN_INPUT_STRING(request.remote_file_id_); - auto file_type = request.file_type_ == nullptr ? FileType::Temp : from_td_api(*request.file_type_); + auto file_type = request.file_type_ == nullptr ? FileType::Temp : get_file_type(*request.file_type_); auto r_file_id = file_manager_->from_persistent_id(request.remote_file_id_, file_type); if (r_file_id.is_error()) { send_closure(actor_id(this), &Td::send_error, id, r_file_id.move_as_error()); @@ -5120,7 +5120,7 @@ void Td::on_request(uint64 id, td_api::getStorageStatistics &request) { if (result.is_error()) { promise.set_error(result.move_as_error()); } else { - promise.set_value(result.ok().as_td_api()); + promise.set_value(result.ok().get_storage_statistics_object()); } }); send_closure(storage_manager_, &StorageManager::get_storage_stats, false /*need_all_files*/, request.chat_limit_, @@ -5133,7 +5133,7 @@ void Td::on_request(uint64 id, td_api::getStorageStatisticsFast &request) { if (result.is_error()) { promise.set_error(result.move_as_error()); } else { - promise.set_value(result.ok().as_td_api()); + promise.set_value(result.ok().get_storage_statistics_fast_object()); } }); send_closure(storage_manager_, &StorageManager::get_storage_stats_fast, std::move(query_promise)); @@ -5144,7 +5144,7 @@ void Td::on_request(uint64 id, td_api::getDatabaseStatistics &request) { if (result.is_error()) { promise.set_error(result.move_as_error()); } else { - promise.set_value(result.ok().as_td_api()); + promise.set_value(result.ok().get_database_statistics_object()); } }); send_closure(storage_manager_, &StorageManager::get_database_stats, std::move(query_promise)); @@ -5157,7 +5157,7 @@ void Td::on_request(uint64 id, td_api::optimizeStorage &request) { return send_error_raw(id, 400, "File type must be non-empty"); } - file_types.push_back(from_td_api(*file_type)); + file_types.push_back(get_file_type(*file_type)); } std::vector owner_dialog_ids; for (auto chat_id : request.chat_ids_) { @@ -5184,7 +5184,7 @@ void Td::on_request(uint64 id, td_api::optimizeStorage &request) { if (result.is_error()) { promise.set_error(result.move_as_error()); } else { - promise.set_value(result.ok().as_td_api()); + promise.set_value(result.ok().get_storage_statistics_object()); } }); send_closure(storage_manager_, &StorageManager::run_gc, std::move(parameters), @@ -5197,7 +5197,7 @@ void Td::on_request(uint64 id, td_api::getNetworkStatistics &request) { if (result.is_error()) { promise.set_error(result.move_as_error()); } else { - promise.set_value(result.ok().as_td_api()); + promise.set_value(result.ok().get_network_statistics_object()); } }); send_closure(net_stats_manager_, &NetStatsManager::get_network_stats, request.only_current_, @@ -5221,9 +5221,9 @@ void Td::on_request(uint64 id, td_api::addNetworkStatistics &request) { auto file_entry = move_tl_object_as(request.entry_); entry.is_call = false; if (file_entry->file_type_ != nullptr) { - entry.file_type = from_td_api(*file_entry->file_type_); + entry.file_type = get_file_type(*file_entry->file_type_); } - entry.net_type = from_td_api(file_entry->network_type_); + entry.net_type = get_net_type(file_entry->network_type_); entry.rx = file_entry->received_bytes_; entry.tx = file_entry->sent_bytes_; break; @@ -5231,7 +5231,7 @@ void Td::on_request(uint64 id, td_api::addNetworkStatistics &request) { case td_api::networkStatisticsEntryCall::ID: { auto call_entry = move_tl_object_as(request.entry_); entry.is_call = true; - entry.net_type = from_td_api(call_entry->network_type_); + entry.net_type = get_net_type(call_entry->network_type_); entry.rx = call_entry->received_bytes_; entry.tx = call_entry->sent_bytes_; entry.duration = call_entry->duration_; @@ -5263,7 +5263,7 @@ void Td::on_request(uint64 id, td_api::addNetworkStatistics &request) { void Td::on_request(uint64 id, const td_api::setNetworkType &request) { CREATE_OK_REQUEST_PROMISE(); - send_closure(state_manager_, &StateManager::on_network, from_td_api(request.type_)); + send_closure(state_manager_, &StateManager::on_network, get_net_type(request.type_)); promise.set_value(Unit()); } @@ -5279,7 +5279,7 @@ void Td::on_request(uint64 id, const td_api::setAutoDownloadSettings &request) { if (request.settings_ == nullptr) { return send_error_raw(id, 400, "New settings must be non-empty"); } - set_auto_download_settings(this, from_td_api(request.type_), get_auto_download_settings(request.settings_), + set_auto_download_settings(this, get_net_type(request.type_), get_auto_download_settings(request.settings_), std::move(promise)); } @@ -5299,9 +5299,8 @@ void Td::on_request(uint64 id, td_api::getTopChats &request) { promise.set_value(MessagesManager::get_chats_object(result.ok())); } }); - send_closure(top_dialog_manager_, &TopDialogManager::get_top_dialogs, - top_dialog_category_from_td_api(*request.category_), narrow_cast(request.limit_), - std::move(query_promise)); + send_closure(top_dialog_manager_, &TopDialogManager::get_top_dialogs, get_top_dialog_category(*request.category_), + narrow_cast(request.limit_), std::move(query_promise)); } void Td::on_request(uint64 id, const td_api::removeTopChat &request) { @@ -5314,9 +5313,8 @@ void Td::on_request(uint64 id, const td_api::removeTopChat &request) { if (!dialog_id.is_valid()) { return send_error_raw(id, 400, "Invalid chat identifier"); } - send_closure(top_dialog_manager_, &TopDialogManager::remove_dialog, - top_dialog_category_from_td_api(*request.category_), dialog_id, - messages_manager_->get_input_peer(dialog_id, AccessRights::Read)); + send_closure(top_dialog_manager_, &TopDialogManager::remove_dialog, get_top_dialog_category(*request.category_), + dialog_id, messages_manager_->get_input_peer(dialog_id, AccessRights::Read)); send_closure(actor_id(this), &Td::send_result, id, td_api::make_object()); } @@ -5819,7 +5817,7 @@ void Td::on_request(uint64 id, td_api::createCall &request) { if (result.is_error()) { promise.set_error(result.move_as_error()); } else { - promise.set_value(result.ok().as_td_api()); + promise.set_value(result.ok().get_call_id_object()); } }); @@ -5838,7 +5836,7 @@ void Td::on_request(uint64 id, td_api::createCall &request) { } send_closure(G()->call_manager(), &CallManager::create_call, user_id, std::move(input_user), - CallProtocol::from_td_api(*request.protocol_), false, std::move(query_promise)); + CallProtocol(*request.protocol_), false, std::move(query_promise)); } void Td::on_request(uint64 id, td_api::discardCall &request) { @@ -5855,7 +5853,7 @@ void Td::on_request(uint64 id, td_api::acceptCall &request) { return promise.set_error(Status::Error(5, "Call protocol must be non-empty")); } send_closure(G()->call_manager(), &CallManager::accept_call, CallId(request.call_id_), - CallProtocol::from_td_api(*request.protocol_), std::move(promise)); + CallProtocol(*request.protocol_), std::move(promise)); } void Td::on_request(uint64 id, td_api::sendCallRating &request) { @@ -6240,7 +6238,7 @@ void Td::on_request(uint64 id, td_api::uploadFile &request) { return send_error_raw(id, 5, "Upload priority must be in [1;32] range"); } - auto file_type = request.file_type_ == nullptr ? FileType::Temp : from_td_api(*request.file_type_); + auto file_type = request.file_type_ == nullptr ? FileType::Temp : get_file_type(*request.file_type_); bool is_secret = file_type == FileType::Encrypted || file_type == FileType::EncryptedThumbnail; bool is_secure = file_type == FileType::Secure; auto r_file_id = file_manager_->get_input_file_id(file_type, request.file_, DialogId(), false, is_secret, @@ -7984,7 +7982,7 @@ void Td::on_request(uint64 id, const td_api::testNetwork &request) { } void Td::on_request(uint64 id, td_api::testProxy &request) { - auto r_proxy = Proxy::from_td_api(std::move(request.server_), request.port_, request.type_.get()); + auto r_proxy = Proxy::create_proxy(std::move(request.server_), request.port_, request.type_.get()); if (r_proxy.is_error()) { return send_closure(actor_id(this), &Td::send_error, id, r_proxy.move_as_error()); } diff --git a/td/telegram/TopDialogCategory.h b/td/telegram/TopDialogCategory.h index f7f08524d..5dd0d9cf6 100644 --- a/td/telegram/TopDialogCategory.h +++ b/td/telegram/TopDialogCategory.h @@ -24,7 +24,7 @@ enum class TopDialogCategory : int32 { Size }; -inline TopDialogCategory top_dialog_category_from_td_api(const td_api::TopChatCategory &category) { +inline TopDialogCategory get_top_dialog_category(const td_api::TopChatCategory &category) { switch (category.get_id()) { case td_api::topChatCategoryUsers::ID: return TopDialogCategory::Correspondent; diff --git a/td/telegram/TopDialogManager.cpp b/td/telegram/TopDialogManager.cpp index c2d5f369d..1c03e4b2e 100644 --- a/td/telegram/TopDialogManager.cpp +++ b/td/telegram/TopDialogManager.cpp @@ -59,7 +59,7 @@ static CSlice top_dialog_category_name(TopDialogCategory category) { } } -static TopDialogCategory top_dialog_category_from_telegram_api(const telegram_api::TopPeerCategory &category) { +static TopDialogCategory get_top_dialog_category(const telegram_api::TopPeerCategory &category) { switch (category.get_id()) { case telegram_api::topPeerCategoryCorrespondents::ID: return TopDialogCategory::Correspondent; @@ -82,7 +82,7 @@ static TopDialogCategory top_dialog_category_from_telegram_api(const telegram_ap } } -static tl_object_ptr top_dialog_category_as_telegram_api(TopDialogCategory category) { +static tl_object_ptr get_top_peer_category(TopDialogCategory category) { switch (category) { case TopDialogCategory::Correspondent: return make_tl_object(); @@ -199,8 +199,7 @@ void TopDialogManager::remove_dialog(TopDialogCategory category, DialogId dialog LOG(INFO) << "Remove " << top_dialog_category_name(category) << " rating of " << dialog_id; if (input_peer != nullptr) { - auto query = - telegram_api::contacts_resetTopPeerRating(top_dialog_category_as_telegram_api(category), std::move(input_peer)); + auto query = telegram_api::contacts_resetTopPeerRating(get_top_peer_category(category), std::move(input_peer)); auto net_query = G()->net_query_creator().create(query); G()->net_query_dispatcher().dispatch_with_callback(std::move(net_query), actor_shared(this, 1)); } @@ -470,7 +469,7 @@ void TopDialogManager::on_result(NetQueryPtr net_query) { send_closure(G()->contacts_manager(), &ContactsManager::on_get_chats, std::move(top_peers->chats_), "on get top chats"); for (auto &category : top_peers->categories_) { - auto dialog_category = top_dialog_category_from_telegram_api(*category->category_); + auto dialog_category = get_top_dialog_category(*category->category_); auto pos = static_cast(dialog_category); CHECK(pos < by_category_.size()); auto &top_dialogs = by_category_[pos]; diff --git a/td/telegram/files/FileStats.cpp b/td/telegram/files/FileStats.cpp index 8ff1c6dd3..f37c6a743 100644 --- a/td/telegram/files/FileStats.cpp +++ b/td/telegram/files/FileStats.cpp @@ -19,7 +19,7 @@ namespace td { -tl_object_ptr FileStatsFast::as_td_api() const { +tl_object_ptr FileStatsFast::get_storage_statistics_fast_object() const { return make_tl_object(size, count, database_size, language_pack_database_size, log_size); } @@ -131,8 +131,8 @@ void FileStats::apply_dialog_limit(int32 limit) { } } -tl_object_ptr as_td_api(DialogId dialog_id, - const FileStats::StatByType &stat_by_type) { +static tl_object_ptr get_storage_statistics_by_chat_object( + DialogId dialog_id, const FileStats::StatByType &stat_by_type) { auto stats = make_tl_object(dialog_id.get(), 0, 0, Auto()); int64 secure_raw_size = 0; int32 secure_raw_cnt = 0; @@ -180,20 +180,20 @@ tl_object_ptr as_td_api(DialogId dialog_id, stats->size_ += size; stats->count_ += cnt; stats->by_file_type_.push_back( - make_tl_object(as_td_api(file_type), size, cnt)); + make_tl_object(get_file_type_object(file_type), size, cnt)); } return stats; } -tl_object_ptr FileStats::as_td_api() const { +tl_object_ptr FileStats::get_storage_statistics_object() const { auto stats = make_tl_object(0, 0, Auto()); if (!split_by_owner_dialog_id) { stats->by_chat_.reserve(1); - stats->by_chat_.push_back(::td::as_td_api(DialogId(), stat_by_type)); + stats->by_chat_.push_back(get_storage_statistics_by_chat_object(DialogId(), stat_by_type)); } else { stats->by_chat_.reserve(stat_by_owner_dialog_id.size()); for (auto &by_dialog : stat_by_owner_dialog_id) { - stats->by_chat_.push_back(::td::as_td_api(by_dialog.first, by_dialog.second)); + stats->by_chat_.push_back(get_storage_statistics_by_chat_object(by_dialog.first, by_dialog.second)); } std::sort(stats->by_chat_.begin(), stats->by_chat_.end(), [](const auto &x, const auto &y) { if (x->chat_id_ == 0 || y->chat_id_ == 0) { diff --git a/td/telegram/files/FileStats.h b/td/telegram/files/FileStats.h index 888aa1794..a0e3c08af 100644 --- a/td/telegram/files/FileStats.h +++ b/td/telegram/files/FileStats.h @@ -65,7 +65,7 @@ struct FileStatsFast { , language_pack_database_size(language_pack_database_size) , log_size(log_size) { } - tl_object_ptr as_td_api() const; + tl_object_ptr get_storage_statistics_fast_object() const; }; struct FileStats { @@ -83,7 +83,7 @@ struct FileStats { void add(FullFileInfo &&info); void apply_dialog_limit(int32 limit); - tl_object_ptr as_td_api() const; + tl_object_ptr get_storage_statistics_object() const; std::vector get_dialog_ids() const; FileTypeStat get_total_nontemp_stat() const; diff --git a/td/telegram/files/FileType.cpp b/td/telegram/files/FileType.cpp index b5f010845..0e9ed15c4 100644 --- a/td/telegram/files/FileType.cpp +++ b/td/telegram/files/FileType.cpp @@ -8,7 +8,7 @@ namespace td { -FileType from_td_api(const td_api::FileType &file_type) { +FileType get_file_type(const td_api::FileType &file_type) { switch (file_type.get_id()) { case td_api::fileTypeThumbnail::ID: return FileType::Thumbnail; @@ -48,7 +48,7 @@ FileType from_td_api(const td_api::FileType &file_type) { } } -tl_object_ptr as_td_api(FileType file_type) { +tl_object_ptr get_file_type_object(FileType file_type) { switch (file_type) { case FileType::Thumbnail: return make_tl_object(); diff --git a/td/telegram/files/FileType.h b/td/telegram/files/FileType.h index ffbbafb71..abc172b7b 100644 --- a/td/telegram/files/FileType.h +++ b/td/telegram/files/FileType.h @@ -41,9 +41,9 @@ enum class FileDirType : int8 { Secure, Common }; constexpr int32 MAX_FILE_TYPE = static_cast(FileType::Size); -FileType from_td_api(const td_api::FileType &file_type); +FileType get_file_type(const td_api::FileType &file_type); -tl_object_ptr as_td_api(FileType file_type); +tl_object_ptr get_file_type_object(FileType file_type); CSlice get_file_type_name(FileType file_type); diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp index db7f51de6..0bc008013 100644 --- a/td/telegram/net/ConnectionCreator.cpp +++ b/td/telegram/net/ConnectionCreator.cpp @@ -139,7 +139,7 @@ void ConnectionCreator::set_net_stats_callback(std::shared_ptr void ConnectionCreator::add_proxy(int32 old_proxy_id, string server, int32 port, bool enable, td_api::object_ptr proxy_type, Promise> promise) { - auto r_proxy = Proxy::from_td_api(std::move(server), port, proxy_type.get()); + auto r_proxy = Proxy::create_proxy(std::move(server), port, proxy_type.get()); if (r_proxy.is_error()) { return promise.set_error(r_proxy.move_as_error()); } diff --git a/td/telegram/net/NetStatsManager.h b/td/telegram/net/NetStatsManager.h index cab1756eb..e5eb3a2f3 100644 --- a/td/telegram/net/NetStatsManager.h +++ b/td/telegram/net/NetStatsManager.h @@ -34,12 +34,12 @@ struct NetworkStatsEntry { int64 count{0}; double duration{0}; - tl_object_ptr as_td_api() const { + tl_object_ptr get_network_statistics_entry_object() const { if (is_call) { - return make_tl_object(::td::as_td_api(net_type), tx, rx, duration); + return make_tl_object(get_network_type_object(net_type), tx, rx, duration); } else { - return make_tl_object(::td::as_td_api(file_type), ::td::as_td_api(net_type), - tx, rx); + return make_tl_object(get_file_type_object(file_type), + get_network_type_object(net_type), tx, rx); } } }; @@ -48,13 +48,13 @@ struct NetworkStats { int32 since = 0; std::vector entries; - auto as_td_api() const { + auto get_network_statistics_object() const { auto result = make_tl_object(); result->since_date_ = since; result->entries_.reserve(entries.size()); for (const auto &entry : entries) { if ((entry.rx != 0 || entry.tx != 0) && entry.file_type != FileType::SecureRaw) { - result->entries_.push_back(entry.as_td_api()); + result->entries_.push_back(entry.get_network_statistics_entry_object()); } } return result; @@ -83,7 +83,7 @@ class NetStatsManager : public Actor { static constexpr size_t net_type_size() { return static_cast(NetType::Size); } - // TODO constexpr + static CSlice net_type_string(NetType type) { switch (type) { case NetType::Other: diff --git a/td/telegram/net/NetType.h b/td/telegram/net/NetType.h index 8faea2a86..e79b96f59 100644 --- a/td/telegram/net/NetType.h +++ b/td/telegram/net/NetType.h @@ -14,7 +14,7 @@ namespace td { enum class NetType : int8 { Other, WiFi, Mobile, MobileRoaming, Size, None, Unknown }; -inline NetType from_td_api(const tl_object_ptr &net_type) { +inline NetType get_net_type(const tl_object_ptr &net_type) { if (net_type == nullptr) { return NetType::Other; } @@ -35,7 +35,7 @@ inline NetType from_td_api(const tl_object_ptr &net_type) { } } -inline tl_object_ptr as_td_api(NetType net_type) { +inline tl_object_ptr get_network_type_object(NetType net_type) { switch (net_type) { case NetType::Other: return make_tl_object(); diff --git a/td/telegram/net/Proxy.cpp b/td/telegram/net/Proxy.cpp index 0e6e2e09a..d84b4166d 100644 --- a/td/telegram/net/Proxy.cpp +++ b/td/telegram/net/Proxy.cpp @@ -10,7 +10,7 @@ namespace td { -Result Proxy::from_td_api(string server, int port, td_api::ProxyType *proxy_type) { +Result Proxy::create_proxy(string server, int port, td_api::ProxyType *proxy_type) { if (proxy_type == nullptr) { return Status::Error(400, "Proxy type must be non-empty"); } diff --git a/td/telegram/net/Proxy.h b/td/telegram/net/Proxy.h index 947930c39..a25f7fd80 100644 --- a/td/telegram/net/Proxy.h +++ b/td/telegram/net/Proxy.h @@ -22,7 +22,7 @@ class ProxyType; class Proxy { public: - static Result from_td_api(string server, int port, td_api::ProxyType *proxy_type); + static Result create_proxy(string server, int port, td_api::ProxyType *proxy_type); static Proxy socks5(string server, int32 port, string user, string password) { Proxy proxy;