Move account-related methods to AccountManager.
This commit is contained in:
parent
162b5cc636
commit
793e2ed0be
@ -285,7 +285,6 @@ set(TDLIB_SOURCE
|
||||
td/mtproto/Transport.cpp
|
||||
td/mtproto/utils.cpp
|
||||
|
||||
td/telegram/Account.cpp
|
||||
td/telegram/AccountManager.cpp
|
||||
td/telegram/AnimationsManager.cpp
|
||||
td/telegram/Application.cpp
|
||||
@ -536,7 +535,6 @@ set(TDLIB_SOURCE
|
||||
td/mtproto/utils.h
|
||||
|
||||
td/telegram/AccessRights.h
|
||||
td/telegram/Account.h
|
||||
td/telegram/AccountManager.h
|
||||
td/telegram/AffectedHistory.h
|
||||
td/telegram/AnimationsManager.h
|
||||
|
@ -1,686 +0,0 @@
|
||||
//
|
||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#include "td/telegram/Account.h"
|
||||
|
||||
#include "td/telegram/ContactsManager.h"
|
||||
#include "td/telegram/DeviceTokenManager.h"
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/net/NetQueryCreator.h"
|
||||
#include "td/telegram/Td.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
#include "td/telegram/UserId.h"
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
|
||||
#include "td/utils/algorithm.h"
|
||||
#include "td/utils/base64.h"
|
||||
#include "td/utils/buffer.h"
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/misc.h"
|
||||
#include "td/utils/Slice.h"
|
||||
#include "td/utils/Status.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace td {
|
||||
|
||||
static td_api::object_ptr<td_api::SessionType> get_session_type_object(
|
||||
const tl_object_ptr<telegram_api::authorization> &authorization) {
|
||||
auto contains = [](const string &str, const char *substr) {
|
||||
return str.find(substr) != string::npos;
|
||||
};
|
||||
|
||||
const string &app_name = authorization->app_name_;
|
||||
auto device_model = to_lower(authorization->device_model_);
|
||||
auto platform = to_lower(authorization->platform_);
|
||||
auto system_version = to_lower(authorization->system_version_);
|
||||
|
||||
if (device_model.find("xbox") != string::npos) {
|
||||
return td_api::make_object<td_api::sessionTypeXbox>();
|
||||
}
|
||||
|
||||
bool is_web = [&] {
|
||||
CSlice web_name("Web");
|
||||
auto pos = app_name.find(web_name.c_str());
|
||||
if (pos == string::npos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto next_character = app_name[pos + web_name.size()];
|
||||
return !('a' <= next_character && next_character <= 'z');
|
||||
}();
|
||||
|
||||
if (is_web) {
|
||||
if (contains(device_model, "brave")) {
|
||||
return td_api::make_object<td_api::sessionTypeBrave>();
|
||||
} else if (contains(device_model, "vivaldi")) {
|
||||
return td_api::make_object<td_api::sessionTypeVivaldi>();
|
||||
} else if (contains(device_model, "opera") || contains(device_model, "opr")) {
|
||||
return td_api::make_object<td_api::sessionTypeOpera>();
|
||||
} else if (contains(device_model, "edg")) {
|
||||
return td_api::make_object<td_api::sessionTypeEdge>();
|
||||
} else if (contains(device_model, "chrome")) {
|
||||
return td_api::make_object<td_api::sessionTypeChrome>();
|
||||
} else if (contains(device_model, "firefox") || contains(device_model, "fxios")) {
|
||||
return td_api::make_object<td_api::sessionTypeFirefox>();
|
||||
} else if (contains(device_model, "safari")) {
|
||||
return td_api::make_object<td_api::sessionTypeSafari>();
|
||||
}
|
||||
}
|
||||
|
||||
if (begins_with(platform, "android") || contains(system_version, "android")) {
|
||||
return td_api::make_object<td_api::sessionTypeAndroid>();
|
||||
} else if (begins_with(platform, "windows") || contains(system_version, "windows")) {
|
||||
return td_api::make_object<td_api::sessionTypeWindows>();
|
||||
} else if (begins_with(platform, "ubuntu") || contains(system_version, "ubuntu")) {
|
||||
return td_api::make_object<td_api::sessionTypeUbuntu>();
|
||||
} else if (begins_with(platform, "linux") || contains(system_version, "linux")) {
|
||||
return td_api::make_object<td_api::sessionTypeLinux>();
|
||||
}
|
||||
|
||||
auto is_ios = begins_with(platform, "ios") || contains(system_version, "ios");
|
||||
auto is_macos = begins_with(platform, "macos") || contains(system_version, "macos");
|
||||
if (is_ios && contains(device_model, "iphone")) {
|
||||
return td_api::make_object<td_api::sessionTypeIphone>();
|
||||
} else if (is_ios && contains(device_model, "ipad")) {
|
||||
return td_api::make_object<td_api::sessionTypeIpad>();
|
||||
} else if (is_macos && contains(device_model, "mac")) {
|
||||
return td_api::make_object<td_api::sessionTypeMac>();
|
||||
} else if (is_ios || is_macos) {
|
||||
return td_api::make_object<td_api::sessionTypeApple>();
|
||||
}
|
||||
|
||||
return td_api::make_object<td_api::sessionTypeUnknown>();
|
||||
}
|
||||
|
||||
static td_api::object_ptr<td_api::session> convert_authorization_object(
|
||||
tl_object_ptr<telegram_api::authorization> &&authorization) {
|
||||
CHECK(authorization != nullptr);
|
||||
return td_api::make_object<td_api::session>(
|
||||
authorization->hash_, authorization->current_, authorization->password_pending_, authorization->unconfirmed_,
|
||||
!authorization->encrypted_requests_disabled_, !authorization->call_requests_disabled_,
|
||||
get_session_type_object(authorization), authorization->api_id_, authorization->app_name_,
|
||||
authorization->app_version_, authorization->official_app_, authorization->device_model_, authorization->platform_,
|
||||
authorization->system_version_, authorization->date_created_, authorization->date_active_, authorization->ip_,
|
||||
authorization->country_, authorization->region_);
|
||||
}
|
||||
|
||||
class SetDefaultHistoryTtlQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit SetDefaultHistoryTtlQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(int32 account_ttl) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_setDefaultHistoryTTL(account_ttl), {{"me"}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::messages_setDefaultHistoryTTL>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
bool result = result_ptr.move_as_ok();
|
||||
if (!result) {
|
||||
return on_error(Status::Error(500, "Internal Server Error: failed to set default message TTL"));
|
||||
}
|
||||
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class GetDefaultHistoryTtlQuery final : public Td::ResultHandler {
|
||||
Promise<int32> promise_;
|
||||
|
||||
public:
|
||||
explicit GetDefaultHistoryTtlQuery(Promise<int32> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send() {
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_getDefaultHistoryTTL()));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::messages_getDefaultHistoryTTL>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto ptr = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for GetDefaultHistoryTtlQuery: " << to_string(ptr);
|
||||
|
||||
promise_.set_value(std::move(ptr->period_));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class SetAccountTtlQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit SetAccountTtlQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(int32 account_ttl) {
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::account_setAccountTTL(make_tl_object<telegram_api::accountDaysTTL>(account_ttl)), {{"me"}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_setAccountTTL>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
bool result = result_ptr.move_as_ok();
|
||||
if (!result) {
|
||||
return on_error(Status::Error(500, "Internal Server Error: failed to set account TTL"));
|
||||
}
|
||||
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class GetAccountTtlQuery final : public Td::ResultHandler {
|
||||
Promise<int32> promise_;
|
||||
|
||||
public:
|
||||
explicit GetAccountTtlQuery(Promise<int32> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send() {
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_getAccountTTL()));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_getAccountTTL>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto ptr = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for GetAccountTtlQuery: " << to_string(ptr);
|
||||
|
||||
promise_.set_value(std::move(ptr->days_));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class AcceptLoginTokenQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::session>> promise_;
|
||||
|
||||
public:
|
||||
explicit AcceptLoginTokenQuery(Promise<td_api::object_ptr<td_api::session>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(const string &login_token) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::auth_acceptLoginToken(BufferSlice(login_token))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::auth_acceptLoginToken>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
LOG(DEBUG) << "Receive result for AcceptLoginTokenQuery: " << to_string(result_ptr.ok());
|
||||
promise_.set_value(convert_authorization_object(result_ptr.move_as_ok()));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class GetAuthorizationsQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::sessions>> promise_;
|
||||
|
||||
public:
|
||||
explicit GetAuthorizationsQuery(Promise<td_api::object_ptr<td_api::sessions>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send() {
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_getAuthorizations()));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_getAuthorizations>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto ptr = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for GetAuthorizationsQuery: " << to_string(ptr);
|
||||
|
||||
auto ttl_days = ptr->authorization_ttl_days_;
|
||||
if (ttl_days <= 0 || ttl_days > 366) {
|
||||
LOG(ERROR) << "Receive invalid inactive sessions TTL " << ttl_days;
|
||||
ttl_days = 180;
|
||||
}
|
||||
|
||||
auto results = td_api::make_object<td_api::sessions>(
|
||||
transform(std::move(ptr->authorizations_), convert_authorization_object), ttl_days);
|
||||
std::sort(results->sessions_.begin(), results->sessions_.end(),
|
||||
[](const td_api::object_ptr<td_api::session> &lhs, const td_api::object_ptr<td_api::session> &rhs) {
|
||||
if (lhs->is_current_ != rhs->is_current_) {
|
||||
return lhs->is_current_;
|
||||
}
|
||||
if (lhs->is_password_pending_ != rhs->is_password_pending_) {
|
||||
return lhs->is_password_pending_;
|
||||
}
|
||||
return lhs->last_active_date_ > rhs->last_active_date_;
|
||||
});
|
||||
|
||||
promise_.set_value(std::move(results));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class ResetAuthorizationQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit ResetAuthorizationQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(int64 authorization_id) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_resetAuthorization(authorization_id)));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_resetAuthorization>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
bool result = result_ptr.move_as_ok();
|
||||
LOG_IF(WARNING, !result) << "Failed to terminate session";
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class ResetAuthorizationsQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit ResetAuthorizationsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send() {
|
||||
send_query(G()->net_query_creator().create(telegram_api::auth_resetAuthorizations()));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::auth_resetAuthorizations>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
bool result = result_ptr.move_as_ok();
|
||||
LOG_IF(WARNING, !result) << "Failed to terminate all sessions";
|
||||
send_closure(td_->device_token_manager_, &DeviceTokenManager::reregister_device);
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class ChangeAuthorizationSettingsQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit ChangeAuthorizationSettingsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(int64 hash, bool set_encrypted_requests_disabled, bool encrypted_requests_disabled,
|
||||
bool set_call_requests_disabled, bool call_requests_disabled) {
|
||||
int32 flags = 0;
|
||||
if (set_encrypted_requests_disabled) {
|
||||
flags |= telegram_api::account_changeAuthorizationSettings::ENCRYPTED_REQUESTS_DISABLED_MASK;
|
||||
}
|
||||
if (set_call_requests_disabled) {
|
||||
flags |= telegram_api::account_changeAuthorizationSettings::CALL_REQUESTS_DISABLED_MASK;
|
||||
}
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::account_changeAuthorizationSettings(flags, false /*ignored*/, hash, encrypted_requests_disabled,
|
||||
call_requests_disabled),
|
||||
{{"me"}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_changeAuthorizationSettings>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
bool result = result_ptr.move_as_ok();
|
||||
LOG_IF(WARNING, !result) << "Failed to change session settings";
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class SetAuthorizationTtlQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit SetAuthorizationTtlQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(int32 authorization_ttl_days) {
|
||||
send_query(
|
||||
G()->net_query_creator().create(telegram_api::account_setAuthorizationTTL(authorization_ttl_days), {{"me"}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_setAuthorizationTTL>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
bool result = result_ptr.move_as_ok();
|
||||
LOG_IF(WARNING, !result) << "Failed to set inactive session TTL";
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class GetWebAuthorizationsQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::connectedWebsites>> promise_;
|
||||
|
||||
public:
|
||||
explicit GetWebAuthorizationsQuery(Promise<td_api::object_ptr<td_api::connectedWebsites>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send() {
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_getWebAuthorizations()));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_getWebAuthorizations>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto ptr = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for GetWebAuthorizationsQuery: " << to_string(ptr);
|
||||
|
||||
td_->contacts_manager_->on_get_users(std::move(ptr->users_), "GetWebAuthorizationsQuery");
|
||||
|
||||
auto results = td_api::make_object<td_api::connectedWebsites>();
|
||||
results->websites_.reserve(ptr->authorizations_.size());
|
||||
for (auto &authorization : ptr->authorizations_) {
|
||||
CHECK(authorization != nullptr);
|
||||
UserId bot_user_id(authorization->bot_id_);
|
||||
if (!bot_user_id.is_valid()) {
|
||||
LOG(ERROR) << "Receive invalid bot " << bot_user_id;
|
||||
bot_user_id = UserId();
|
||||
}
|
||||
|
||||
results->websites_.push_back(td_api::make_object<td_api::connectedWebsite>(
|
||||
authorization->hash_, authorization->domain_,
|
||||
td_->contacts_manager_->get_user_id_object(bot_user_id, "GetWebAuthorizationsQuery"), authorization->browser_,
|
||||
authorization->platform_, authorization->date_created_, authorization->date_active_, authorization->ip_,
|
||||
authorization->region_));
|
||||
}
|
||||
|
||||
promise_.set_value(std::move(results));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class ResetWebAuthorizationQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit ResetWebAuthorizationQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(int64 hash) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_resetWebAuthorization(hash)));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_resetWebAuthorization>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
bool result = result_ptr.move_as_ok();
|
||||
LOG_IF(WARNING, !result) << "Failed to disconnect website";
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class ResetWebAuthorizationsQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit ResetWebAuthorizationsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send() {
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_resetWebAuthorizations()));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_resetWebAuthorizations>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
bool result = result_ptr.move_as_ok();
|
||||
LOG_IF(WARNING, !result) << "Failed to disconnect all websites";
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class ExportContactTokenQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::userLink>> promise_;
|
||||
|
||||
public:
|
||||
explicit ExportContactTokenQuery(Promise<td_api::object_ptr<td_api::userLink>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send() {
|
||||
send_query(G()->net_query_creator().create(telegram_api::contacts_exportContactToken()));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::contacts_exportContactToken>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto ptr = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for ExportContactTokenQuery: " << to_string(ptr);
|
||||
promise_.set_value(td_api::make_object<td_api::userLink>(
|
||||
ptr->url_, td::max(static_cast<int32>(ptr->expires_ - G()->unix_time()), static_cast<int32>(1))));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class ImportContactTokenQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::user>> promise_;
|
||||
|
||||
public:
|
||||
explicit ImportContactTokenQuery(Promise<td_api::object_ptr<td_api::user>> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(const string &token) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::contacts_importContactToken(token)));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::contacts_importContactToken>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto user = result_ptr.move_as_ok();
|
||||
LOG(DEBUG) << "Receive result for ImportContactTokenQuery: " << to_string(user);
|
||||
|
||||
auto user_id = ContactsManager::get_user_id(user);
|
||||
td_->contacts_manager_->on_get_user(std::move(user), "ImportContactTokenQuery");
|
||||
promise_.set_value(td_->contacts_manager_->get_user_object(user_id));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class InvalidateSignInCodesQuery final : public Td::ResultHandler {
|
||||
public:
|
||||
void send(vector<string> &&codes) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_invalidateSignInCodes(std::move(codes))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_invalidateSignInCodes>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
LOG(DEBUG) << "Receive result for InvalidateSignInCodesQuery: " << result_ptr.ok();
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
LOG(DEBUG) << "Receive error for InvalidateSignInCodesQuery: " << status;
|
||||
}
|
||||
};
|
||||
|
||||
void set_default_message_ttl(Td *td, int32 message_ttl, Promise<Unit> &&promise) {
|
||||
td->create_handler<SetDefaultHistoryTtlQuery>(std::move(promise))->send(message_ttl);
|
||||
}
|
||||
|
||||
void get_default_message_ttl(Td *td, Promise<int32> &&promise) {
|
||||
td->create_handler<GetDefaultHistoryTtlQuery>(std::move(promise))->send();
|
||||
}
|
||||
|
||||
void set_account_ttl(Td *td, int32 account_ttl, Promise<Unit> &&promise) {
|
||||
td->create_handler<SetAccountTtlQuery>(std::move(promise))->send(account_ttl);
|
||||
}
|
||||
|
||||
void get_account_ttl(Td *td, Promise<int32> &&promise) {
|
||||
td->create_handler<GetAccountTtlQuery>(std::move(promise))->send();
|
||||
}
|
||||
|
||||
void confirm_qr_code_authentication(Td *td, const string &link,
|
||||
Promise<td_api::object_ptr<td_api::session>> &&promise) {
|
||||
Slice prefix("tg://login?token=");
|
||||
if (!begins_with(to_lower(link), prefix)) {
|
||||
return promise.set_error(Status::Error(400, "AUTH_TOKEN_INVALID"));
|
||||
}
|
||||
auto r_token = base64url_decode(Slice(link).substr(prefix.size()));
|
||||
if (r_token.is_error()) {
|
||||
return promise.set_error(Status::Error(400, "AUTH_TOKEN_INVALID"));
|
||||
}
|
||||
td->create_handler<AcceptLoginTokenQuery>(std::move(promise))->send(r_token.ok());
|
||||
}
|
||||
|
||||
void get_active_sessions(Td *td, Promise<td_api::object_ptr<td_api::sessions>> &&promise) {
|
||||
td->create_handler<GetAuthorizationsQuery>(std::move(promise))->send();
|
||||
}
|
||||
|
||||
void terminate_session(Td *td, int64 session_id, Promise<Unit> &&promise) {
|
||||
td->create_handler<ResetAuthorizationQuery>(std::move(promise))->send(session_id);
|
||||
}
|
||||
|
||||
void terminate_all_other_sessions(Td *td, Promise<Unit> &&promise) {
|
||||
td->create_handler<ResetAuthorizationsQuery>(std::move(promise))->send();
|
||||
}
|
||||
|
||||
void toggle_session_can_accept_calls(Td *td, int64 session_id, bool can_accept_calls, Promise<Unit> &&promise) {
|
||||
td->create_handler<ChangeAuthorizationSettingsQuery>(std::move(promise))
|
||||
->send(session_id, false, false, true, !can_accept_calls);
|
||||
}
|
||||
|
||||
void toggle_session_can_accept_secret_chats(Td *td, int64 session_id, bool can_accept_secret_chats,
|
||||
Promise<Unit> &&promise) {
|
||||
td->create_handler<ChangeAuthorizationSettingsQuery>(std::move(promise))
|
||||
->send(session_id, true, !can_accept_secret_chats, false, false);
|
||||
}
|
||||
|
||||
void set_inactive_session_ttl_days(Td *td, int32 authorization_ttl_days, Promise<Unit> &&promise) {
|
||||
td->create_handler<SetAuthorizationTtlQuery>(std::move(promise))->send(authorization_ttl_days);
|
||||
}
|
||||
|
||||
void get_connected_websites(Td *td, Promise<td_api::object_ptr<td_api::connectedWebsites>> &&promise) {
|
||||
td->create_handler<GetWebAuthorizationsQuery>(std::move(promise))->send();
|
||||
}
|
||||
|
||||
void disconnect_website(Td *td, int64 website_id, Promise<Unit> &&promise) {
|
||||
td->create_handler<ResetWebAuthorizationQuery>(std::move(promise))->send(website_id);
|
||||
}
|
||||
|
||||
void disconnect_all_websites(Td *td, Promise<Unit> &&promise) {
|
||||
td->create_handler<ResetWebAuthorizationsQuery>(std::move(promise))->send();
|
||||
}
|
||||
|
||||
void export_contact_token(Td *td, Promise<td_api::object_ptr<td_api::userLink>> &&promise) {
|
||||
td->create_handler<ExportContactTokenQuery>(std::move(promise))->send();
|
||||
}
|
||||
|
||||
void import_contact_token(Td *td, const string &token, Promise<td_api::object_ptr<td_api::user>> &&promise) {
|
||||
td->create_handler<ImportContactTokenQuery>(std::move(promise))->send(token);
|
||||
}
|
||||
|
||||
void invalidate_authentication_codes(Td *td, vector<string> &&authentication_codes) {
|
||||
td->create_handler<InvalidateSignInCodesQuery>()->send(std::move(authentication_codes));
|
||||
}
|
||||
|
||||
} // namespace td
|
@ -1,53 +0,0 @@
|
||||
//
|
||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/td_api.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/Promise.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
class Td;
|
||||
|
||||
void set_default_message_ttl(Td *td, int32 message_ttl, Promise<Unit> &&promise);
|
||||
|
||||
void get_default_message_ttl(Td *td, Promise<int32> &&promise);
|
||||
|
||||
void set_account_ttl(Td *td, int32 account_ttl, Promise<Unit> &&promise);
|
||||
|
||||
void get_account_ttl(Td *td, Promise<int32> &&promise);
|
||||
|
||||
void confirm_qr_code_authentication(Td *td, const string &link, Promise<td_api::object_ptr<td_api::session>> &&promise);
|
||||
|
||||
void get_active_sessions(Td *td, Promise<td_api::object_ptr<td_api::sessions>> &&promise);
|
||||
|
||||
void terminate_session(Td *td, int64 session_id, Promise<Unit> &&promise);
|
||||
|
||||
void terminate_all_other_sessions(Td *td, Promise<Unit> &&promise);
|
||||
|
||||
void toggle_session_can_accept_calls(Td *td, int64 session_id, bool can_accept_calls, Promise<Unit> &&promise);
|
||||
|
||||
void toggle_session_can_accept_secret_chats(Td *td, int64 session_id, bool can_accept_secret_chats,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
void set_inactive_session_ttl_days(Td *td, int32 authorization_ttl_days, Promise<Unit> &&promise);
|
||||
|
||||
void get_connected_websites(Td *td, Promise<td_api::object_ptr<td_api::connectedWebsites>> &&promise);
|
||||
|
||||
void disconnect_website(Td *td, int64 website_id, Promise<Unit> &&promise);
|
||||
|
||||
void disconnect_all_websites(Td *td, Promise<Unit> &&promise);
|
||||
|
||||
void export_contact_token(Td *td, Promise<td_api::object_ptr<td_api::userLink>> &&promise);
|
||||
|
||||
void import_contact_token(Td *td, const string &token, Promise<td_api::object_ptr<td_api::user>> &&promise);
|
||||
|
||||
void invalidate_authentication_codes(Td *td, vector<string> &&authentication_codes);
|
||||
|
||||
} // namespace td
|
@ -6,8 +6,601 @@
|
||||
//
|
||||
#include "td/telegram/AccountManager.h"
|
||||
|
||||
#include "td/telegram/ContactsManager.h"
|
||||
#include "td/telegram/DeviceTokenManager.h"
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/net/NetQueryCreator.h"
|
||||
#include "td/telegram/Td.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
#include "td/telegram/UserId.h"
|
||||
|
||||
#include "td/utils/algorithm.h"
|
||||
#include "td/utils/base64.h"
|
||||
#include "td/utils/buffer.h"
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/misc.h"
|
||||
#include "td/utils/Slice.h"
|
||||
#include "td/utils/Status.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace td {
|
||||
|
||||
static td_api::object_ptr<td_api::SessionType> get_session_type_object(
|
||||
const tl_object_ptr<telegram_api::authorization> &authorization) {
|
||||
auto contains = [](const string &str, const char *substr) {
|
||||
return str.find(substr) != string::npos;
|
||||
};
|
||||
|
||||
const string &app_name = authorization->app_name_;
|
||||
auto device_model = to_lower(authorization->device_model_);
|
||||
auto platform = to_lower(authorization->platform_);
|
||||
auto system_version = to_lower(authorization->system_version_);
|
||||
|
||||
if (device_model.find("xbox") != string::npos) {
|
||||
return td_api::make_object<td_api::sessionTypeXbox>();
|
||||
}
|
||||
|
||||
bool is_web = [&] {
|
||||
CSlice web_name("Web");
|
||||
auto pos = app_name.find(web_name.c_str());
|
||||
if (pos == string::npos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto next_character = app_name[pos + web_name.size()];
|
||||
return !('a' <= next_character && next_character <= 'z');
|
||||
}();
|
||||
|
||||
if (is_web) {
|
||||
if (contains(device_model, "brave")) {
|
||||
return td_api::make_object<td_api::sessionTypeBrave>();
|
||||
} else if (contains(device_model, "vivaldi")) {
|
||||
return td_api::make_object<td_api::sessionTypeVivaldi>();
|
||||
} else if (contains(device_model, "opera") || contains(device_model, "opr")) {
|
||||
return td_api::make_object<td_api::sessionTypeOpera>();
|
||||
} else if (contains(device_model, "edg")) {
|
||||
return td_api::make_object<td_api::sessionTypeEdge>();
|
||||
} else if (contains(device_model, "chrome")) {
|
||||
return td_api::make_object<td_api::sessionTypeChrome>();
|
||||
} else if (contains(device_model, "firefox") || contains(device_model, "fxios")) {
|
||||
return td_api::make_object<td_api::sessionTypeFirefox>();
|
||||
} else if (contains(device_model, "safari")) {
|
||||
return td_api::make_object<td_api::sessionTypeSafari>();
|
||||
}
|
||||
}
|
||||
|
||||
if (begins_with(platform, "android") || contains(system_version, "android")) {
|
||||
return td_api::make_object<td_api::sessionTypeAndroid>();
|
||||
} else if (begins_with(platform, "windows") || contains(system_version, "windows")) {
|
||||
return td_api::make_object<td_api::sessionTypeWindows>();
|
||||
} else if (begins_with(platform, "ubuntu") || contains(system_version, "ubuntu")) {
|
||||
return td_api::make_object<td_api::sessionTypeUbuntu>();
|
||||
} else if (begins_with(platform, "linux") || contains(system_version, "linux")) {
|
||||
return td_api::make_object<td_api::sessionTypeLinux>();
|
||||
}
|
||||
|
||||
auto is_ios = begins_with(platform, "ios") || contains(system_version, "ios");
|
||||
auto is_macos = begins_with(platform, "macos") || contains(system_version, "macos");
|
||||
if (is_ios && contains(device_model, "iphone")) {
|
||||
return td_api::make_object<td_api::sessionTypeIphone>();
|
||||
} else if (is_ios && contains(device_model, "ipad")) {
|
||||
return td_api::make_object<td_api::sessionTypeIpad>();
|
||||
} else if (is_macos && contains(device_model, "mac")) {
|
||||
return td_api::make_object<td_api::sessionTypeMac>();
|
||||
} else if (is_ios || is_macos) {
|
||||
return td_api::make_object<td_api::sessionTypeApple>();
|
||||
}
|
||||
|
||||
return td_api::make_object<td_api::sessionTypeUnknown>();
|
||||
}
|
||||
|
||||
static td_api::object_ptr<td_api::session> convert_authorization_object(
|
||||
tl_object_ptr<telegram_api::authorization> &&authorization) {
|
||||
CHECK(authorization != nullptr);
|
||||
return td_api::make_object<td_api::session>(
|
||||
authorization->hash_, authorization->current_, authorization->password_pending_, authorization->unconfirmed_,
|
||||
!authorization->encrypted_requests_disabled_, !authorization->call_requests_disabled_,
|
||||
get_session_type_object(authorization), authorization->api_id_, authorization->app_name_,
|
||||
authorization->app_version_, authorization->official_app_, authorization->device_model_, authorization->platform_,
|
||||
authorization->system_version_, authorization->date_created_, authorization->date_active_, authorization->ip_,
|
||||
authorization->country_, authorization->region_);
|
||||
}
|
||||
|
||||
class SetDefaultHistoryTtlQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit SetDefaultHistoryTtlQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(int32 account_ttl) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_setDefaultHistoryTTL(account_ttl), {{"me"}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::messages_setDefaultHistoryTTL>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
bool result = result_ptr.move_as_ok();
|
||||
if (!result) {
|
||||
return on_error(Status::Error(500, "Internal Server Error: failed to set default message TTL"));
|
||||
}
|
||||
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class GetDefaultHistoryTtlQuery final : public Td::ResultHandler {
|
||||
Promise<int32> promise_;
|
||||
|
||||
public:
|
||||
explicit GetDefaultHistoryTtlQuery(Promise<int32> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send() {
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_getDefaultHistoryTTL()));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::messages_getDefaultHistoryTTL>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto ptr = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for GetDefaultHistoryTtlQuery: " << to_string(ptr);
|
||||
|
||||
promise_.set_value(std::move(ptr->period_));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class SetAccountTtlQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit SetAccountTtlQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(int32 account_ttl) {
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::account_setAccountTTL(make_tl_object<telegram_api::accountDaysTTL>(account_ttl)), {{"me"}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_setAccountTTL>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
bool result = result_ptr.move_as_ok();
|
||||
if (!result) {
|
||||
return on_error(Status::Error(500, "Internal Server Error: failed to set account TTL"));
|
||||
}
|
||||
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class GetAccountTtlQuery final : public Td::ResultHandler {
|
||||
Promise<int32> promise_;
|
||||
|
||||
public:
|
||||
explicit GetAccountTtlQuery(Promise<int32> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send() {
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_getAccountTTL()));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_getAccountTTL>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto ptr = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for GetAccountTtlQuery: " << to_string(ptr);
|
||||
|
||||
promise_.set_value(std::move(ptr->days_));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class AcceptLoginTokenQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::session>> promise_;
|
||||
|
||||
public:
|
||||
explicit AcceptLoginTokenQuery(Promise<td_api::object_ptr<td_api::session>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(const string &login_token) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::auth_acceptLoginToken(BufferSlice(login_token))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::auth_acceptLoginToken>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
LOG(DEBUG) << "Receive result for AcceptLoginTokenQuery: " << to_string(result_ptr.ok());
|
||||
promise_.set_value(convert_authorization_object(result_ptr.move_as_ok()));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class GetAuthorizationsQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::sessions>> promise_;
|
||||
|
||||
public:
|
||||
explicit GetAuthorizationsQuery(Promise<td_api::object_ptr<td_api::sessions>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send() {
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_getAuthorizations()));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_getAuthorizations>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto ptr = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for GetAuthorizationsQuery: " << to_string(ptr);
|
||||
|
||||
auto ttl_days = ptr->authorization_ttl_days_;
|
||||
if (ttl_days <= 0 || ttl_days > 366) {
|
||||
LOG(ERROR) << "Receive invalid inactive sessions TTL " << ttl_days;
|
||||
ttl_days = 180;
|
||||
}
|
||||
|
||||
auto results = td_api::make_object<td_api::sessions>(
|
||||
transform(std::move(ptr->authorizations_), convert_authorization_object), ttl_days);
|
||||
std::sort(results->sessions_.begin(), results->sessions_.end(),
|
||||
[](const td_api::object_ptr<td_api::session> &lhs, const td_api::object_ptr<td_api::session> &rhs) {
|
||||
if (lhs->is_current_ != rhs->is_current_) {
|
||||
return lhs->is_current_;
|
||||
}
|
||||
if (lhs->is_password_pending_ != rhs->is_password_pending_) {
|
||||
return lhs->is_password_pending_;
|
||||
}
|
||||
return lhs->last_active_date_ > rhs->last_active_date_;
|
||||
});
|
||||
|
||||
promise_.set_value(std::move(results));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class ResetAuthorizationQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit ResetAuthorizationQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(int64 authorization_id) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_resetAuthorization(authorization_id)));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_resetAuthorization>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
bool result = result_ptr.move_as_ok();
|
||||
LOG_IF(WARNING, !result) << "Failed to terminate session";
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class ResetAuthorizationsQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit ResetAuthorizationsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send() {
|
||||
send_query(G()->net_query_creator().create(telegram_api::auth_resetAuthorizations()));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::auth_resetAuthorizations>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
bool result = result_ptr.move_as_ok();
|
||||
LOG_IF(WARNING, !result) << "Failed to terminate all sessions";
|
||||
send_closure(td_->device_token_manager_, &DeviceTokenManager::reregister_device);
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class ChangeAuthorizationSettingsQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit ChangeAuthorizationSettingsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(int64 hash, bool set_encrypted_requests_disabled, bool encrypted_requests_disabled,
|
||||
bool set_call_requests_disabled, bool call_requests_disabled) {
|
||||
int32 flags = 0;
|
||||
if (set_encrypted_requests_disabled) {
|
||||
flags |= telegram_api::account_changeAuthorizationSettings::ENCRYPTED_REQUESTS_DISABLED_MASK;
|
||||
}
|
||||
if (set_call_requests_disabled) {
|
||||
flags |= telegram_api::account_changeAuthorizationSettings::CALL_REQUESTS_DISABLED_MASK;
|
||||
}
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::account_changeAuthorizationSettings(flags, false /*ignored*/, hash, encrypted_requests_disabled,
|
||||
call_requests_disabled),
|
||||
{{"me"}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_changeAuthorizationSettings>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
bool result = result_ptr.move_as_ok();
|
||||
LOG_IF(WARNING, !result) << "Failed to change session settings";
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class SetAuthorizationTtlQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit SetAuthorizationTtlQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(int32 authorization_ttl_days) {
|
||||
send_query(
|
||||
G()->net_query_creator().create(telegram_api::account_setAuthorizationTTL(authorization_ttl_days), {{"me"}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_setAuthorizationTTL>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
bool result = result_ptr.move_as_ok();
|
||||
LOG_IF(WARNING, !result) << "Failed to set inactive session TTL";
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class GetWebAuthorizationsQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::connectedWebsites>> promise_;
|
||||
|
||||
public:
|
||||
explicit GetWebAuthorizationsQuery(Promise<td_api::object_ptr<td_api::connectedWebsites>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send() {
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_getWebAuthorizations()));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_getWebAuthorizations>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto ptr = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for GetWebAuthorizationsQuery: " << to_string(ptr);
|
||||
|
||||
td_->contacts_manager_->on_get_users(std::move(ptr->users_), "GetWebAuthorizationsQuery");
|
||||
|
||||
auto results = td_api::make_object<td_api::connectedWebsites>();
|
||||
results->websites_.reserve(ptr->authorizations_.size());
|
||||
for (auto &authorization : ptr->authorizations_) {
|
||||
CHECK(authorization != nullptr);
|
||||
UserId bot_user_id(authorization->bot_id_);
|
||||
if (!bot_user_id.is_valid()) {
|
||||
LOG(ERROR) << "Receive invalid bot " << bot_user_id;
|
||||
bot_user_id = UserId();
|
||||
}
|
||||
|
||||
results->websites_.push_back(td_api::make_object<td_api::connectedWebsite>(
|
||||
authorization->hash_, authorization->domain_,
|
||||
td_->contacts_manager_->get_user_id_object(bot_user_id, "GetWebAuthorizationsQuery"), authorization->browser_,
|
||||
authorization->platform_, authorization->date_created_, authorization->date_active_, authorization->ip_,
|
||||
authorization->region_));
|
||||
}
|
||||
|
||||
promise_.set_value(std::move(results));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class ResetWebAuthorizationQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit ResetWebAuthorizationQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(int64 hash) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_resetWebAuthorization(hash)));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_resetWebAuthorization>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
bool result = result_ptr.move_as_ok();
|
||||
LOG_IF(WARNING, !result) << "Failed to disconnect website";
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class ResetWebAuthorizationsQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit ResetWebAuthorizationsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send() {
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_resetWebAuthorizations()));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_resetWebAuthorizations>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
bool result = result_ptr.move_as_ok();
|
||||
LOG_IF(WARNING, !result) << "Failed to disconnect all websites";
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class ExportContactTokenQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::userLink>> promise_;
|
||||
|
||||
public:
|
||||
explicit ExportContactTokenQuery(Promise<td_api::object_ptr<td_api::userLink>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send() {
|
||||
send_query(G()->net_query_creator().create(telegram_api::contacts_exportContactToken()));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::contacts_exportContactToken>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto ptr = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for ExportContactTokenQuery: " << to_string(ptr);
|
||||
promise_.set_value(td_api::make_object<td_api::userLink>(
|
||||
ptr->url_, td::max(static_cast<int32>(ptr->expires_ - G()->unix_time()), static_cast<int32>(1))));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class ImportContactTokenQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::user>> promise_;
|
||||
|
||||
public:
|
||||
explicit ImportContactTokenQuery(Promise<td_api::object_ptr<td_api::user>> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(const string &token) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::contacts_importContactToken(token)));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::contacts_importContactToken>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto user = result_ptr.move_as_ok();
|
||||
LOG(DEBUG) << "Receive result for ImportContactTokenQuery: " << to_string(user);
|
||||
|
||||
auto user_id = ContactsManager::get_user_id(user);
|
||||
td_->contacts_manager_->on_get_user(std::move(user), "ImportContactTokenQuery");
|
||||
promise_.set_value(td_->contacts_manager_->get_user_object(user_id));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class InvalidateSignInCodesQuery final : public Td::ResultHandler {
|
||||
public:
|
||||
void send(vector<string> &&codes) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_invalidateSignInCodes(std::move(codes))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_invalidateSignInCodes>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
LOG(DEBUG) << "Receive result for InvalidateSignInCodesQuery: " << result_ptr.ok();
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
LOG(DEBUG) << "Receive error for InvalidateSignInCodesQuery: " << status;
|
||||
}
|
||||
};
|
||||
|
||||
AccountManager::AccountManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
|
||||
}
|
||||
|
||||
@ -15,6 +608,86 @@ void AccountManager::tear_down() {
|
||||
parent_.reset();
|
||||
}
|
||||
|
||||
void AccountManager::set_default_message_ttl(int32 message_ttl, Promise<Unit> &&promise) {
|
||||
td_->create_handler<SetDefaultHistoryTtlQuery>(std::move(promise))->send(message_ttl);
|
||||
}
|
||||
|
||||
void AccountManager::get_default_message_ttl(Promise<int32> &&promise) {
|
||||
td_->create_handler<GetDefaultHistoryTtlQuery>(std::move(promise))->send();
|
||||
}
|
||||
|
||||
void AccountManager::set_account_ttl(int32 account_ttl, Promise<Unit> &&promise) {
|
||||
td_->create_handler<SetAccountTtlQuery>(std::move(promise))->send(account_ttl);
|
||||
}
|
||||
|
||||
void AccountManager::get_account_ttl(Promise<int32> &&promise) {
|
||||
td_->create_handler<GetAccountTtlQuery>(std::move(promise))->send();
|
||||
}
|
||||
|
||||
void AccountManager::confirm_qr_code_authentication(const string &link,
|
||||
Promise<td_api::object_ptr<td_api::session>> &&promise) {
|
||||
Slice prefix("tg://login?token=");
|
||||
if (!begins_with(to_lower(link), prefix)) {
|
||||
return promise.set_error(Status::Error(400, "AUTH_TOKEN_INVALID"));
|
||||
}
|
||||
auto r_token = base64url_decode(Slice(link).substr(prefix.size()));
|
||||
if (r_token.is_error()) {
|
||||
return promise.set_error(Status::Error(400, "AUTH_TOKEN_INVALID"));
|
||||
}
|
||||
td_->create_handler<AcceptLoginTokenQuery>(std::move(promise))->send(r_token.ok());
|
||||
}
|
||||
|
||||
void AccountManager::get_active_sessions(Promise<td_api::object_ptr<td_api::sessions>> &&promise) {
|
||||
td_->create_handler<GetAuthorizationsQuery>(std::move(promise))->send();
|
||||
}
|
||||
|
||||
void AccountManager::terminate_session(int64 session_id, Promise<Unit> &&promise) {
|
||||
td_->create_handler<ResetAuthorizationQuery>(std::move(promise))->send(session_id);
|
||||
}
|
||||
|
||||
void AccountManager::terminate_all_other_sessions(Promise<Unit> &&promise) {
|
||||
td_->create_handler<ResetAuthorizationsQuery>(std::move(promise))->send();
|
||||
}
|
||||
|
||||
void AccountManager::toggle_session_can_accept_calls(int64 session_id, bool can_accept_calls, Promise<Unit> &&promise) {
|
||||
td_->create_handler<ChangeAuthorizationSettingsQuery>(std::move(promise))
|
||||
->send(session_id, false, false, true, !can_accept_calls);
|
||||
}
|
||||
|
||||
void AccountManager::toggle_session_can_accept_secret_chats(int64 session_id, bool can_accept_secret_chats,
|
||||
Promise<Unit> &&promise) {
|
||||
td_->create_handler<ChangeAuthorizationSettingsQuery>(std::move(promise))
|
||||
->send(session_id, true, !can_accept_secret_chats, false, false);
|
||||
}
|
||||
|
||||
void AccountManager::set_inactive_session_ttl_days(int32 authorization_ttl_days, Promise<Unit> &&promise) {
|
||||
td_->create_handler<SetAuthorizationTtlQuery>(std::move(promise))->send(authorization_ttl_days);
|
||||
}
|
||||
|
||||
void AccountManager::get_connected_websites(Promise<td_api::object_ptr<td_api::connectedWebsites>> &&promise) {
|
||||
td_->create_handler<GetWebAuthorizationsQuery>(std::move(promise))->send();
|
||||
}
|
||||
|
||||
void AccountManager::disconnect_website(int64 website_id, Promise<Unit> &&promise) {
|
||||
td_->create_handler<ResetWebAuthorizationQuery>(std::move(promise))->send(website_id);
|
||||
}
|
||||
|
||||
void AccountManager::disconnect_all_websites(Promise<Unit> &&promise) {
|
||||
td_->create_handler<ResetWebAuthorizationsQuery>(std::move(promise))->send();
|
||||
}
|
||||
|
||||
void AccountManager::export_contact_token(Promise<td_api::object_ptr<td_api::userLink>> &&promise) {
|
||||
td_->create_handler<ExportContactTokenQuery>(std::move(promise))->send();
|
||||
}
|
||||
|
||||
void AccountManager::import_contact_token(const string &token, Promise<td_api::object_ptr<td_api::user>> &&promise) {
|
||||
td_->create_handler<ImportContactTokenQuery>(std::move(promise))->send(token);
|
||||
}
|
||||
|
||||
void AccountManager::invalidate_authentication_codes(vector<string> &&authentication_codes) {
|
||||
td_->create_handler<InvalidateSignInCodesQuery>()->send(std::move(authentication_codes));
|
||||
}
|
||||
|
||||
void AccountManager::get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const {
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "td/actor/actor.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/Promise.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
@ -20,6 +21,40 @@ class AccountManager final : public Actor {
|
||||
public:
|
||||
AccountManager(Td *td, ActorShared<> parent);
|
||||
|
||||
void set_default_message_ttl(int32 message_ttl, Promise<Unit> &&promise);
|
||||
|
||||
void get_default_message_ttl(Promise<int32> &&promise);
|
||||
|
||||
void set_account_ttl(int32 account_ttl, Promise<Unit> &&promise);
|
||||
|
||||
void get_account_ttl(Promise<int32> &&promise);
|
||||
|
||||
void confirm_qr_code_authentication(const string &link, Promise<td_api::object_ptr<td_api::session>> &&promise);
|
||||
|
||||
void get_active_sessions(Promise<td_api::object_ptr<td_api::sessions>> &&promise);
|
||||
|
||||
void terminate_session(int64 session_id, Promise<Unit> &&promise);
|
||||
|
||||
void terminate_all_other_sessions(Promise<Unit> &&promise);
|
||||
|
||||
void toggle_session_can_accept_calls(int64 session_id, bool can_accept_calls, Promise<Unit> &&promise);
|
||||
|
||||
void toggle_session_can_accept_secret_chats(int64 session_id, bool can_accept_secret_chats, Promise<Unit> &&promise);
|
||||
|
||||
void set_inactive_session_ttl_days(int32 authorization_ttl_days, Promise<Unit> &&promise);
|
||||
|
||||
void get_connected_websites(Promise<td_api::object_ptr<td_api::connectedWebsites>> &&promise);
|
||||
|
||||
void disconnect_website(int64 website_id, Promise<Unit> &&promise);
|
||||
|
||||
void disconnect_all_websites(Promise<Unit> &&promise);
|
||||
|
||||
void export_contact_token(Promise<td_api::object_ptr<td_api::userLink>> &&promise);
|
||||
|
||||
void import_contact_token(const string &token, Promise<td_api::object_ptr<td_api::user>> &&promise);
|
||||
|
||||
void invalidate_authentication_codes(vector<string> &&authentication_codes);
|
||||
|
||||
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
||||
|
||||
private:
|
||||
|
@ -6,7 +6,7 @@
|
||||
//
|
||||
#include "td/telegram/ContactsManager.h"
|
||||
|
||||
#include "td/telegram/Account.h"
|
||||
#include "td/telegram/AccountManager.h"
|
||||
#include "td/telegram/AnimationsManager.h"
|
||||
#include "td/telegram/AuthManager.h"
|
||||
#include "td/telegram/BlockListId.h"
|
||||
@ -16856,11 +16856,7 @@ void ContactsManager::get_user_link_impl(Promise<td_api::object_ptr<td_api::user
|
||||
return promise.set_value(td_api::make_object<td_api::userLink>(
|
||||
LinkManager::get_public_dialog_link(u->usernames.get_first_username(), true), 0));
|
||||
}
|
||||
export_contact_token(td_, std::move(promise));
|
||||
}
|
||||
|
||||
void ContactsManager::search_user_by_token(string token, Promise<td_api::object_ptr<td_api::user>> &&promise) {
|
||||
import_contact_token(td_, token, std::move(promise));
|
||||
td_->account_manager_->export_contact_token(std::move(promise));
|
||||
}
|
||||
|
||||
void ContactsManager::send_get_me_query(Td *td, Promise<Unit> &&promise) {
|
||||
|
@ -585,8 +585,6 @@ class ContactsManager final : public Actor {
|
||||
|
||||
void get_user_link(Promise<td_api::object_ptr<td_api::userLink>> &&promise);
|
||||
|
||||
void search_user_by_token(string token, Promise<td_api::object_ptr<td_api::user>> &&promise);
|
||||
|
||||
static void send_get_me_query(Td *td, Promise<Unit> &&promise);
|
||||
UserId get_me(Promise<Unit> &&promise);
|
||||
bool get_user(UserId user_id, int left_tries, Promise<Unit> &&promise);
|
||||
|
@ -6,7 +6,7 @@
|
||||
//
|
||||
#include "td/telegram/MessagesManager.h"
|
||||
|
||||
#include "td/telegram/Account.h"
|
||||
#include "td/telegram/AccountManager.h"
|
||||
#include "td/telegram/AuthManager.h"
|
||||
#include "td/telegram/BackgroundInfo.hpp"
|
||||
#include "td/telegram/BlockListId.h"
|
||||
@ -20233,7 +20233,7 @@ Status MessagesManager::view_messages(DialogId dialog_id, vector<MessageId> mess
|
||||
update_viewed_messages_timeout_.add_timeout_in(dialog_id.get(), UPDATE_VIEWED_MESSAGES_PERIOD);
|
||||
}
|
||||
if (!authentication_codes.empty()) {
|
||||
invalidate_authentication_codes(td_, std::move(authentication_codes));
|
||||
td_->account_manager_->invalidate_authentication_codes(std::move(authentication_codes));
|
||||
}
|
||||
if (!screenshotted_secret_message_ids.empty()) {
|
||||
send_screenshot_taken_notification_message(d);
|
||||
@ -28353,7 +28353,7 @@ Result<td_api::object_ptr<td_api::messages>> MessagesManager::forward_messages(
|
||||
}
|
||||
|
||||
if (!authentication_codes.empty()) {
|
||||
invalidate_authentication_codes(td_, std::move(authentication_codes));
|
||||
td_->account_manager_->invalidate_authentication_codes(std::move(authentication_codes));
|
||||
}
|
||||
|
||||
return get_messages_object(-1, std::move(result), false);
|
||||
|
@ -6,7 +6,6 @@
|
||||
//
|
||||
#include "td/telegram/Td.h"
|
||||
|
||||
#include "td/telegram/Account.h"
|
||||
#include "td/telegram/AccountManager.h"
|
||||
#include "td/telegram/AnimationsManager.h"
|
||||
#include "td/telegram/Application.h"
|
||||
@ -4326,7 +4325,7 @@ void Td::on_request(uint64 id, td_api::checkAuthenticationBotToken &request) {
|
||||
void Td::on_request(uint64 id, td_api::confirmQrCodeAuthentication &request) {
|
||||
CLEAN_INPUT_STRING(request.link_);
|
||||
CREATE_REQUEST_PROMISE();
|
||||
confirm_qr_code_authentication(this, request.link_, std::move(promise));
|
||||
account_manager_->confirm_qr_code_authentication(request.link_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getCurrentState &request) {
|
||||
@ -4565,7 +4564,7 @@ void Td::on_request(uint64 id, const td_api::getDefaultMessageAutoDeleteTime &re
|
||||
promise.set_value(td_api::make_object<td_api::messageAutoDeleteTime>(result.ok()));
|
||||
}
|
||||
});
|
||||
get_default_message_ttl(this, std::move(query_promise));
|
||||
account_manager_->get_default_message_ttl(std::move(query_promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::setDefaultMessageAutoDeleteTime &request) {
|
||||
@ -4574,7 +4573,7 @@ void Td::on_request(uint64 id, const td_api::setDefaultMessageAutoDeleteTime &re
|
||||
return send_error_raw(id, 400, "New default message auto-delete time must be non-empty");
|
||||
}
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
set_default_message_ttl(this, request.message_auto_delete_time_->time_, std::move(promise));
|
||||
account_manager_->set_default_message_ttl(request.message_auto_delete_time_->time_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getAccountTtl &request) {
|
||||
@ -4587,7 +4586,7 @@ void Td::on_request(uint64 id, const td_api::getAccountTtl &request) {
|
||||
promise.set_value(td_api::make_object<td_api::accountTtl>(result.ok()));
|
||||
}
|
||||
});
|
||||
get_account_ttl(this, std::move(query_promise));
|
||||
account_manager_->get_account_ttl(std::move(query_promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::setAccountTtl &request) {
|
||||
@ -4596,7 +4595,7 @@ void Td::on_request(uint64 id, const td_api::setAccountTtl &request) {
|
||||
return send_error_raw(id, 400, "New account TTL must be non-empty");
|
||||
}
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
set_account_ttl(this, request.ttl_->days_, std::move(promise));
|
||||
account_manager_->set_account_ttl(request.ttl_->days_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::deleteAccount &request) {
|
||||
@ -4633,62 +4632,62 @@ void Td::on_request(uint64 id, td_api::searchUserByToken &request) {
|
||||
CHECK_IS_USER();
|
||||
CLEAN_INPUT_STRING(request.token_);
|
||||
CREATE_REQUEST_PROMISE();
|
||||
contacts_manager_->search_user_by_token(std::move(request.token_), std::move(promise));
|
||||
account_manager_->import_contact_token(std::move(request.token_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getActiveSessions &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_REQUEST_PROMISE();
|
||||
get_active_sessions(this, std::move(promise));
|
||||
account_manager_->get_active_sessions(std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::terminateSession &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
terminate_session(this, request.session_id_, std::move(promise));
|
||||
account_manager_->terminate_session(request.session_id_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::terminateAllOtherSessions &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
terminate_all_other_sessions(this, std::move(promise));
|
||||
account_manager_->terminate_all_other_sessions(std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::toggleSessionCanAcceptCalls &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
toggle_session_can_accept_calls(this, request.session_id_, request.can_accept_calls_, std::move(promise));
|
||||
account_manager_->toggle_session_can_accept_calls(request.session_id_, request.can_accept_calls_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::toggleSessionCanAcceptSecretChats &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
toggle_session_can_accept_secret_chats(this, request.session_id_, request.can_accept_secret_chats_,
|
||||
account_manager_->toggle_session_can_accept_secret_chats(request.session_id_, request.can_accept_secret_chats_,
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::setInactiveSessionTtl &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
set_inactive_session_ttl_days(this, request.inactive_session_ttl_days_, std::move(promise));
|
||||
account_manager_->set_inactive_session_ttl_days(request.inactive_session_ttl_days_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getConnectedWebsites &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_REQUEST_PROMISE();
|
||||
get_connected_websites(this, std::move(promise));
|
||||
account_manager_->get_connected_websites(std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::disconnectWebsite &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
disconnect_website(this, request.website_id_, std::move(promise));
|
||||
account_manager_->disconnect_website(request.website_id_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::disconnectAllWebsites &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
disconnect_all_websites(this, std::move(promise));
|
||||
account_manager_->disconnect_all_websites(std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getMe &request) {
|
||||
|
Loading…
Reference in New Issue
Block a user