Unify conversion function names.
GitOrigin-RevId: 10def5544dfd6a94ff89b15441006d102b512439
This commit is contained in:
parent
afcf7197ae
commit
9334243a5d
|
@ -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',
|
||||
|
|
|
@ -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 <tuple>
|
||||
|
@ -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<telegram_api::phoneCallProtocol> CallProtocol::as_telegram_api() const {
|
||||
tl_object_ptr<telegram_api::phoneCallProtocol> 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<telegram_api::phoneCallProtocol> CallProtocol::as_telegram_api() c
|
|||
vector<string>(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<td_api::callProtocol> 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<td_api::callProtocol> CallProtocol::get_call_protocol_object() const {
|
||||
return make_tl_object<td_api::callProtocol>(udp_p2p, udp_reflector, min_layer, max_layer,
|
||||
vector<string>(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<telegram_api::phoneConnection> CallConnection::as_telegram_api() const {
|
||||
tl_object_ptr<telegram_api::phoneConnection> CallConnection::get_input_phone_connection() const {
|
||||
return make_tl_object<telegram_api::phoneConnection>(id, ip, ipv6, port, BufferSlice(peer_tag));
|
||||
}
|
||||
tl_object_ptr<td_api::callConnection> CallConnection::as_td_api() const {
|
||||
|
||||
tl_object_ptr<td_api::callConnection> CallConnection::get_call_connection_object() const {
|
||||
return make_tl_object<td_api::callConnection>(id, ip, ipv6, port, peer_tag);
|
||||
}
|
||||
|
||||
// CallState
|
||||
tl_object_ptr<td_api::CallState> CallState::as_td_api() const {
|
||||
tl_object_ptr<td_api::CallState> CallState::get_call_state_object() const {
|
||||
switch (type) {
|
||||
case Type::Pending:
|
||||
return make_tl_object<td_api::callStatePending>(is_created, is_received);
|
||||
case Type::ExchangingKey:
|
||||
return make_tl_object<td_api::callStateExchangingKeys>();
|
||||
case Type::Ready: {
|
||||
std::vector<tl_object_ptr<td_api::callConnection>> v;
|
||||
for (auto &c : connections) {
|
||||
v.push_back(c.as_td_api());
|
||||
}
|
||||
return make_tl_object<td_api::callStateReady>(protocol.as_td_api(), std::move(v), config, key,
|
||||
vector<string>(emojis_fingerprint), allow_p2p);
|
||||
auto call_connections = transform(connections, [](auto &c) { return c.get_call_connection_object(); });
|
||||
return make_tl_object<td_api::callStateReady>(protocol.get_call_protocol_object(), std::move(call_connections),
|
||||
config, key, vector<string>(emojis_fingerprint), allow_p2p);
|
||||
}
|
||||
case Type::HangingUp:
|
||||
return make_tl_object<td_api::callStateHangingUp>();
|
||||
|
@ -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<td_api::updateCall>(
|
||||
make_tl_object<td_api::call>(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())));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,10 +34,15 @@ struct CallProtocol {
|
|||
int32 max_layer{65};
|
||||
vector<string> library_versions;
|
||||
|
||||
static CallProtocol from_telegram_api(const telegram_api::phoneCallProtocol &protocol);
|
||||
tl_object_ptr<telegram_api::phoneCallProtocol> as_telegram_api() const;
|
||||
static CallProtocol from_td_api(const td_api::callProtocol &protocol);
|
||||
tl_object_ptr<td_api::callProtocol> as_td_api() const;
|
||||
CallProtocol() = default;
|
||||
|
||||
explicit CallProtocol(const td_api::callProtocol &protocol);
|
||||
|
||||
explicit CallProtocol(const telegram_api::phoneCallProtocol &protocol);
|
||||
|
||||
tl_object_ptr<telegram_api::phoneCallProtocol> get_input_phone_call_protocol() const;
|
||||
|
||||
tl_object_ptr<td_api::callProtocol> 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<telegram_api::phoneConnection> as_telegram_api() const;
|
||||
tl_object_ptr<td_api::callConnection> as_td_api() const;
|
||||
explicit CallConnection(const telegram_api::phoneConnection &connection);
|
||||
|
||||
tl_object_ptr<telegram_api::phoneConnection> get_input_phone_connection() const;
|
||||
|
||||
tl_object_ptr<td_api::callConnection> get_call_connection_object() const;
|
||||
};
|
||||
|
||||
struct CallState {
|
||||
|
@ -71,7 +78,7 @@ struct CallState {
|
|||
|
||||
Status error;
|
||||
|
||||
tl_object_ptr<td_api::CallState> as_td_api() const;
|
||||
tl_object_ptr<td_api::CallState> get_call_state_object() const;
|
||||
};
|
||||
|
||||
class CallActor : public NetQueryCallback {
|
||||
|
|
|
@ -34,8 +34,8 @@ class CallId {
|
|||
return id;
|
||||
}
|
||||
|
||||
auto as_td_api() const {
|
||||
return make_tl_object<td_api::callId>(id);
|
||||
auto get_call_id_object() const {
|
||||
return td_api::make_object<td_api::callId>(id);
|
||||
}
|
||||
|
||||
bool operator==(const CallId &other) const {
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
namespace td {
|
||||
|
||||
tl_object_ptr<td_api::temporaryPasswordState> TempPasswordState::as_td_api() const {
|
||||
tl_object_ptr<td_api::temporaryPasswordState> TempPasswordState::get_temporary_password_state_object() const {
|
||||
if (!has_temp_password || valid_until <= G()->unix_time()) {
|
||||
return make_tl_object<td_api::temporaryPasswordState>(false, 0);
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ void PasswordManager::do_get_secure_secret(bool allow_recursive, string password
|
|||
}
|
||||
|
||||
void PasswordManager::get_temp_password_state(Promise<TempState> 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<TempPasswordState> 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<PasswordFullState> promise) {
|
||||
|
@ -625,7 +625,7 @@ void PasswordManager::get_state(Promise<State> 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());
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ struct TempPasswordState {
|
|||
string temp_password;
|
||||
int32 valid_until = 0; // unix_time
|
||||
|
||||
tl_object_ptr<td_api::temporaryPasswordState> as_td_api() const;
|
||||
tl_object_ptr<td_api::temporaryPasswordState> get_temporary_password_state_object() const;
|
||||
|
||||
template <class StorerT>
|
||||
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<td_api::emailAddressAuthenticationCodeInfo> code_info;
|
||||
if (!unconfirmed_recovery_email_address_pattern.empty()) {
|
||||
code_info = td_api::make_object<td_api::emailAddressAuthenticationCodeInfo>(
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
namespace td {
|
||||
|
||||
Result<PrivacyManager::UserPrivacySetting> PrivacyManager::UserPrivacySetting::from_td_api(
|
||||
Result<PrivacyManager::UserPrivacySetting> PrivacyManager::UserPrivacySetting::get_user_privacy_setting(
|
||||
tl_object_ptr<td_api::UserPrivacySetting> 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<td_api::UserPrivacySetting> PrivacyManager::UserPrivacySetting::as_td_api() const {
|
||||
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>();
|
||||
|
@ -90,7 +90,7 @@ tl_object_ptr<td_api::UserPrivacySetting> PrivacyManager::UserPrivacySetting::as
|
|||
return nullptr;
|
||||
}
|
||||
}
|
||||
tl_object_ptr<telegram_api::InputPrivacyKey> PrivacyManager::UserPrivacySetting::as_telegram_api() const {
|
||||
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>();
|
||||
|
@ -245,7 +245,8 @@ PrivacyManager::UserPrivacySettingRule::UserPrivacySettingRule(const telegram_ap
|
|||
}
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::UserPrivacySettingRule> PrivacyManager::UserPrivacySettingRule::as_td_api() const {
|
||||
tl_object_ptr<td_api::UserPrivacySettingRule>
|
||||
PrivacyManager::UserPrivacySettingRule::get_user_privacy_setting_rule_object() const {
|
||||
switch (type_) {
|
||||
case Type::AllowContacts:
|
||||
return make_tl_object<td_api::userPrivacySettingRuleAllowContacts>();
|
||||
|
@ -268,14 +269,14 @@ tl_object_ptr<td_api::UserPrivacySettingRule> PrivacyManager::UserPrivacySetting
|
|||
}
|
||||
}
|
||||
|
||||
tl_object_ptr<telegram_api::InputPrivacyRule> PrivacyManager::UserPrivacySettingRule::as_telegram_api() const {
|
||||
tl_object_ptr<telegram_api::InputPrivacyRule> PrivacyManager::UserPrivacySettingRule::get_input_privacy_rule() const {
|
||||
switch (type_) {
|
||||
case Type::AllowContacts:
|
||||
return make_tl_object<telegram_api::inputPrivacyValueAllowContacts>();
|
||||
case Type::AllowAll:
|
||||
return make_tl_object<telegram_api::inputPrivacyValueAllowAll>();
|
||||
case Type::AllowUsers:
|
||||
return make_tl_object<telegram_api::inputPrivacyValueAllowUsers>(user_ids_as_telegram_api());
|
||||
return make_tl_object<telegram_api::inputPrivacyValueAllowUsers>(get_input_users());
|
||||
case Type::AllowChatParticipants:
|
||||
return make_tl_object<telegram_api::inputPrivacyValueAllowChatParticipants>(vector<int32>{chat_ids_});
|
||||
case Type::RestrictContacts:
|
||||
|
@ -283,7 +284,7 @@ tl_object_ptr<telegram_api::InputPrivacyRule> PrivacyManager::UserPrivacySetting
|
|||
case Type::RestrictAll:
|
||||
return make_tl_object<telegram_api::inputPrivacyValueDisallowAll>();
|
||||
case Type::RestrictUsers:
|
||||
return make_tl_object<telegram_api::inputPrivacyValueDisallowUsers>(user_ids_as_telegram_api());
|
||||
return make_tl_object<telegram_api::inputPrivacyValueDisallowUsers>(get_input_users());
|
||||
case Type::RestrictChatParticipants:
|
||||
return make_tl_object<telegram_api::inputPrivacyValueDisallowChatParticipants>(vector<int32>{chat_ids_});
|
||||
default:
|
||||
|
@ -291,7 +292,7 @@ tl_object_ptr<telegram_api::InputPrivacyRule> PrivacyManager::UserPrivacySetting
|
|||
}
|
||||
}
|
||||
|
||||
Result<PrivacyManager::UserPrivacySettingRule> PrivacyManager::UserPrivacySettingRule::from_telegram_api(
|
||||
Result<PrivacyManager::UserPrivacySettingRule> PrivacyManager::UserPrivacySettingRule::get_user_privacy_setting_rule(
|
||||
tl_object_ptr<telegram_api::PrivacyRule> rule) {
|
||||
CHECK(rule != nullptr);
|
||||
UserPrivacySettingRule result(*rule);
|
||||
|
@ -316,8 +317,7 @@ Result<PrivacyManager::UserPrivacySettingRule> PrivacyManager::UserPrivacySettin
|
|||
return result;
|
||||
}
|
||||
|
||||
vector<tl_object_ptr<telegram_api::InputUser>> PrivacyManager::UserPrivacySettingRule::user_ids_as_telegram_api()
|
||||
const {
|
||||
vector<tl_object_ptr<telegram_api::InputUser>> PrivacyManager::UserPrivacySettingRule::get_input_users() const {
|
||||
vector<tl_object_ptr<telegram_api::InputUser>> 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<int32> PrivacyManager::UserPrivacySettingRule::get_restricted_user_ids()
|
|||
return {};
|
||||
}
|
||||
|
||||
Result<PrivacyManager::UserPrivacySettingRules> PrivacyManager::UserPrivacySettingRules::from_telegram_api(
|
||||
Result<PrivacyManager::UserPrivacySettingRules> PrivacyManager::UserPrivacySettingRules::get_user_privacy_setting_rules(
|
||||
tl_object_ptr<telegram_api::account_privacyRules> 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> PrivacyManager::UserPrivacySettingRules::from_telegram_api(
|
||||
Result<PrivacyManager::UserPrivacySettingRules> PrivacyManager::UserPrivacySettingRules::get_user_privacy_setting_rules(
|
||||
vector<tl_object_ptr<telegram_api::PrivacyRule>> 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> PrivacyManager::UserPrivacySettingRules::from_td_api(
|
||||
Result<PrivacyManager::UserPrivacySettingRules> PrivacyManager::UserPrivacySettingRules::get_user_privacy_setting_rules(
|
||||
tl_object_ptr<td_api::userPrivacySettingRules> rules) {
|
||||
if (!rules) {
|
||||
return Status::Error(5, "UserPrivacySettingRules must be non-empty");
|
||||
|
@ -390,13 +390,15 @@ Result<PrivacyManager::UserPrivacySettingRules> PrivacyManager::UserPrivacySetti
|
|||
return result;
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::userPrivacySettingRules> PrivacyManager::UserPrivacySettingRules::as_td_api() const {
|
||||
tl_object_ptr<td_api::userPrivacySettingRules>
|
||||
PrivacyManager::UserPrivacySettingRules::get_user_privacy_setting_rules_object() const {
|
||||
return make_tl_object<td_api::userPrivacySettingRules>(
|
||||
transform(rules_, [](const auto &rule) { return rule.as_td_api(); }));
|
||||
transform(rules_, [](const auto &rule) { return rule.get_user_privacy_setting_rule_object(); }));
|
||||
}
|
||||
|
||||
vector<tl_object_ptr<telegram_api::InputPrivacyRule>> PrivacyManager::UserPrivacySettingRules::as_telegram_api() const {
|
||||
auto result = transform(rules_, [](const auto &rule) { return rule.as_telegram_api(); });
|
||||
vector<tl_object_ptr<telegram_api::InputPrivacyRule>> 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<int32> PrivacyManager::UserPrivacySettingRules::get_restricted_user_ids()
|
|||
|
||||
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::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<td_api::UserPrivacySetting> 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<NetQueryPtr> x_net_query) {
|
||||
|
@ -438,20 +440,20 @@ void PrivacyManager::get_privacy(tl_object_ptr<td_api::UserPrivacySetting> key,
|
|||
TRY_RESULT(net_query, std::move(x_net_query));
|
||||
TRY_RESULT(rules, fetch_result<telegram_api::account_getPrivacy>(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<td_api::UserPrivacySetting> key,
|
||||
tl_object_ptr<td_api::userPrivacySettingRules> rules, Promise<Unit> 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<td_api::UserPrivacySetting> 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<NetQueryPtr> x_net_query) mutable {
|
||||
promise.set_result([&]() -> Result<Unit> {
|
||||
get_info(user_privacy_setting).has_set_query = false;
|
||||
TRY_RESULT(net_query, std::move(x_net_query));
|
||||
TRY_RESULT(rules, fetch_result<telegram_api::account_setPrivacy>(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<NetQueryPtr> x_net_query) mutable {
|
||||
promise.set_result([&]() -> Result<Unit> {
|
||||
get_info(user_privacy_setting).has_set_query = false;
|
||||
TRY_RESULT(net_query, std::move(x_net_query));
|
||||
TRY_RESULT(rules, fetch_result<telegram_api::account_setPrivacy>(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<telegram_api::updatePrivacy> 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<td_api::updateUserPrivacySettingRules>(user_privacy_setting.as_td_api(),
|
||||
info.rules.as_td_api()));
|
||||
send_closure(
|
||||
G()->td(), &Td::send_update,
|
||||
make_tl_object<td_api::updateUserPrivacySettingRules>(user_privacy_setting.get_user_privacy_setting_object(),
|
||||
info.rules.get_user_privacy_setting_rules_object()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,10 +49,13 @@ class PrivacyManager : public NetQueryCallback {
|
|||
Size
|
||||
};
|
||||
|
||||
static Result<UserPrivacySetting> from_td_api(tl_object_ptr<td_api::UserPrivacySetting> key);
|
||||
explicit UserPrivacySetting(const telegram_api::PrivacyKey &key);
|
||||
tl_object_ptr<td_api::UserPrivacySetting> as_td_api() const;
|
||||
tl_object_ptr<telegram_api::InputPrivacyKey> as_telegram_api() const;
|
||||
|
||||
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_;
|
||||
|
@ -67,10 +70,14 @@ class PrivacyManager : public NetQueryCallback {
|
|||
class UserPrivacySettingRule {
|
||||
public:
|
||||
UserPrivacySettingRule() = default;
|
||||
static Result<UserPrivacySettingRule> from_telegram_api(tl_object_ptr<telegram_api::PrivacyRule> rule);
|
||||
|
||||
explicit UserPrivacySettingRule(const td_api::UserPrivacySettingRule &rule);
|
||||
tl_object_ptr<td_api::UserPrivacySettingRule> as_td_api() const;
|
||||
tl_object_ptr<telegram_api::InputPrivacyRule> as_telegram_api() const;
|
||||
|
||||
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;
|
||||
|
||||
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<int32> user_ids_;
|
||||
vector<int32> chat_ids_;
|
||||
|
||||
vector<tl_object_ptr<telegram_api::InputUser>> user_ids_as_telegram_api() const;
|
||||
vector<tl_object_ptr<telegram_api::InputUser>> get_input_users() const;
|
||||
|
||||
void set_chat_ids(const vector<int64> &dialog_ids);
|
||||
|
||||
|
@ -105,11 +112,19 @@ class PrivacyManager : public NetQueryCallback {
|
|||
class UserPrivacySettingRules {
|
||||
public:
|
||||
UserPrivacySettingRules() = default;
|
||||
static Result<UserPrivacySettingRules> from_telegram_api(tl_object_ptr<telegram_api::account_privacyRules> rules);
|
||||
static Result<UserPrivacySettingRules> from_telegram_api(vector<tl_object_ptr<telegram_api::PrivacyRule>> rules);
|
||||
static Result<UserPrivacySettingRules> from_td_api(tl_object_ptr<td_api::userPrivacySettingRules> rules);
|
||||
tl_object_ptr<td_api::userPrivacySettingRules> as_td_api() const;
|
||||
vector<tl_object_ptr<telegram_api::InputPrivacyRule>> as_telegram_api() const;
|
||||
|
||||
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;
|
||||
|
||||
bool operator==(const UserPrivacySettingRules &other) const {
|
||||
return rules_ == other.rules_;
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
namespace td {
|
||||
|
||||
tl_object_ptr<td_api::databaseStatistics> DatabaseStats::as_td_api() const {
|
||||
tl_object_ptr<td_api::databaseStatistics> DatabaseStats::get_database_statistics_object() const {
|
||||
return make_tl_object<td_api::databaseStatistics>(debug);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ struct DatabaseStats {
|
|||
DatabaseStats() = default;
|
||||
explicit DatabaseStats(string debug) : debug(debug) {
|
||||
}
|
||||
tl_object_ptr<td_api::databaseStatistics> as_td_api() const;
|
||||
tl_object_ptr<td_api::databaseStatistics> get_database_statistics_object() const;
|
||||
};
|
||||
|
||||
class StorageManager : public Actor {
|
||||
|
|
|
@ -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<DialogId> 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<td_api::networkStatisticsEntryFile>(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<td_api::networkStatisticsEntryCall>(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<size_t>(request.limit_),
|
||||
std::move(query_promise));
|
||||
send_closure(top_dialog_manager_, &TopDialogManager::get_top_dialogs, get_top_dialog_category(*request.category_),
|
||||
narrow_cast<size_t>(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<td_api::ok>());
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<telegram_api::TopPeerCategory> top_dialog_category_as_telegram_api(TopDialogCategory category) {
|
||||
static tl_object_ptr<telegram_api::TopPeerCategory> get_top_peer_category(TopDialogCategory category) {
|
||||
switch (category) {
|
||||
case TopDialogCategory::Correspondent:
|
||||
return make_tl_object<telegram_api::topPeerCategoryCorrespondents>();
|
||||
|
@ -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<size_t>(dialog_category);
|
||||
CHECK(pos < by_category_.size());
|
||||
auto &top_dialogs = by_category_[pos];
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
namespace td {
|
||||
|
||||
tl_object_ptr<td_api::storageStatisticsFast> FileStatsFast::as_td_api() const {
|
||||
tl_object_ptr<td_api::storageStatisticsFast> FileStatsFast::get_storage_statistics_fast_object() const {
|
||||
return make_tl_object<td_api::storageStatisticsFast>(size, count, database_size, language_pack_database_size,
|
||||
log_size);
|
||||
}
|
||||
|
@ -131,8 +131,8 @@ void FileStats::apply_dialog_limit(int32 limit) {
|
|||
}
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::storageStatisticsByChat> as_td_api(DialogId dialog_id,
|
||||
const FileStats::StatByType &stat_by_type) {
|
||||
static tl_object_ptr<td_api::storageStatisticsByChat> get_storage_statistics_by_chat_object(
|
||||
DialogId dialog_id, const FileStats::StatByType &stat_by_type) {
|
||||
auto stats = make_tl_object<td_api::storageStatisticsByChat>(dialog_id.get(), 0, 0, Auto());
|
||||
int64 secure_raw_size = 0;
|
||||
int32 secure_raw_cnt = 0;
|
||||
|
@ -180,20 +180,20 @@ tl_object_ptr<td_api::storageStatisticsByChat> as_td_api(DialogId dialog_id,
|
|||
stats->size_ += size;
|
||||
stats->count_ += cnt;
|
||||
stats->by_file_type_.push_back(
|
||||
make_tl_object<td_api::storageStatisticsByFileType>(as_td_api(file_type), size, cnt));
|
||||
make_tl_object<td_api::storageStatisticsByFileType>(get_file_type_object(file_type), size, cnt));
|
||||
}
|
||||
return stats;
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::storageStatistics> FileStats::as_td_api() const {
|
||||
tl_object_ptr<td_api::storageStatistics> FileStats::get_storage_statistics_object() const {
|
||||
auto stats = make_tl_object<td_api::storageStatistics>(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) {
|
||||
|
|
|
@ -65,7 +65,7 @@ struct FileStatsFast {
|
|||
, language_pack_database_size(language_pack_database_size)
|
||||
, log_size(log_size) {
|
||||
}
|
||||
tl_object_ptr<td_api::storageStatisticsFast> as_td_api() const;
|
||||
tl_object_ptr<td_api::storageStatisticsFast> 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<td_api::storageStatistics> as_td_api() const;
|
||||
tl_object_ptr<td_api::storageStatistics> get_storage_statistics_object() const;
|
||||
std::vector<DialogId> get_dialog_ids() const;
|
||||
FileTypeStat get_total_nontemp_stat() const;
|
||||
|
||||
|
|
|
@ -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<td_api::FileType> as_td_api(FileType file_type) {
|
||||
tl_object_ptr<td_api::FileType> get_file_type_object(FileType file_type) {
|
||||
switch (file_type) {
|
||||
case FileType::Thumbnail:
|
||||
return make_tl_object<td_api::fileTypeThumbnail>();
|
||||
|
|
|
@ -41,9 +41,9 @@ enum class FileDirType : int8 { Secure, Common };
|
|||
|
||||
constexpr int32 MAX_FILE_TYPE = static_cast<int32>(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<td_api::FileType> as_td_api(FileType file_type);
|
||||
tl_object_ptr<td_api::FileType> get_file_type_object(FileType file_type);
|
||||
|
||||
CSlice get_file_type_name(FileType file_type);
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ void ConnectionCreator::set_net_stats_callback(std::shared_ptr<NetStatsCallback>
|
|||
void ConnectionCreator::add_proxy(int32 old_proxy_id, string server, int32 port, bool enable,
|
||||
td_api::object_ptr<td_api::ProxyType> proxy_type,
|
||||
Promise<td_api::object_ptr<td_api::proxy>> 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());
|
||||
}
|
||||
|
|
|
@ -34,12 +34,12 @@ struct NetworkStatsEntry {
|
|||
int64 count{0};
|
||||
double duration{0};
|
||||
|
||||
tl_object_ptr<td_api::NetworkStatisticsEntry> as_td_api() const {
|
||||
tl_object_ptr<td_api::NetworkStatisticsEntry> get_network_statistics_entry_object() const {
|
||||
if (is_call) {
|
||||
return make_tl_object<td_api::networkStatisticsEntryCall>(::td::as_td_api(net_type), tx, rx, duration);
|
||||
return make_tl_object<td_api::networkStatisticsEntryCall>(get_network_type_object(net_type), tx, rx, duration);
|
||||
} else {
|
||||
return make_tl_object<td_api::networkStatisticsEntryFile>(::td::as_td_api(file_type), ::td::as_td_api(net_type),
|
||||
tx, rx);
|
||||
return make_tl_object<td_api::networkStatisticsEntryFile>(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<NetworkStatsEntry> entries;
|
||||
|
||||
auto as_td_api() const {
|
||||
auto get_network_statistics_object() const {
|
||||
auto result = make_tl_object<td_api::networkStatistics>();
|
||||
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<size_t>(NetType::Size);
|
||||
}
|
||||
// TODO constexpr
|
||||
|
||||
static CSlice net_type_string(NetType type) {
|
||||
switch (type) {
|
||||
case NetType::Other:
|
||||
|
|
|
@ -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<td_api::NetworkType> &net_type) {
|
||||
inline NetType get_net_type(const tl_object_ptr<td_api::NetworkType> &net_type) {
|
||||
if (net_type == nullptr) {
|
||||
return NetType::Other;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ inline NetType from_td_api(const tl_object_ptr<td_api::NetworkType> &net_type) {
|
|||
}
|
||||
}
|
||||
|
||||
inline tl_object_ptr<td_api::NetworkType> as_td_api(NetType net_type) {
|
||||
inline tl_object_ptr<td_api::NetworkType> get_network_type_object(NetType net_type) {
|
||||
switch (net_type) {
|
||||
case NetType::Other:
|
||||
return make_tl_object<td_api::networkTypeOther>();
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
namespace td {
|
||||
|
||||
Result<Proxy> Proxy::from_td_api(string server, int port, td_api::ProxyType *proxy_type) {
|
||||
Result<Proxy> 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");
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class ProxyType;
|
|||
|
||||
class Proxy {
|
||||
public:
|
||||
static Result<Proxy> from_td_api(string server, int port, td_api::ProxyType *proxy_type);
|
||||
static Result<Proxy> create_proxy(string server, int port, td_api::ProxyType *proxy_type);
|
||||
|
||||
static Proxy socks5(string server, int32 port, string user, string password) {
|
||||
Proxy proxy;
|
||||
|
|
Loading…
Reference in New Issue