Add td_api::confirmSession.

This commit is contained in:
levlam 2023-09-12 14:28:02 +03:00
parent 8b37e8101f
commit 2e4594a35a
6 changed files with 35 additions and 5 deletions

View File

@ -8342,6 +8342,9 @@ terminateSession session_id:int64 = Ok;
//@description Terminates all other sessions of the current user
terminateAllOtherSessions = Ok;
//@description Confirms an unconfirmed session of the current user from another device @session_id Session identifier
confirmSession session_id:int64 = Ok;
//@description Toggles whether a session can accept incoming calls @session_id Session identifier @can_accept_calls Pass true to allow accepting incoming calls by the session; pass false otherwise
toggleSessionCanAcceptCalls session_id:int64 can_accept_calls:Bool = Ok;

View File

@ -374,7 +374,7 @@ class ChangeAuthorizationSettingsQuery final : public Td::ResultHandler {
}
void send(int64 hash, bool set_encrypted_requests_disabled, bool encrypted_requests_disabled,
bool set_call_requests_disabled, bool call_requests_disabled) {
bool set_call_requests_disabled, bool call_requests_disabled, bool confirm) {
int32 flags = 0;
if (set_encrypted_requests_disabled) {
flags |= telegram_api::account_changeAuthorizationSettings::ENCRYPTED_REQUESTS_DISABLED_MASK;
@ -382,6 +382,9 @@ class ChangeAuthorizationSettingsQuery final : public Td::ResultHandler {
if (set_call_requests_disabled) {
flags |= telegram_api::account_changeAuthorizationSettings::CALL_REQUESTS_DISABLED_MASK;
}
if (confirm) {
flags |= telegram_api::account_changeAuthorizationSettings::CONFIRMED_MASK;
}
send_query(G()->net_query_creator().create(
telegram_api::account_changeAuthorizationSettings(flags, false /*ignored*/, hash, encrypted_requests_disabled,
call_requests_disabled),
@ -782,15 +785,23 @@ void AccountManager::terminate_all_other_sessions(Promise<Unit> &&promise) {
td_->create_handler<ResetAuthorizationsQuery>(std::move(promise))->send();
}
void AccountManager::confirm_session(int64 session_id, Promise<Unit> &&promise) {
if (!on_confirm_authorization(session_id)) {
return promise.set_value(Unit());
}
td_->create_handler<ChangeAuthorizationSettingsQuery>(std::move(promise))
->send(session_id, false, false, false, false, true);
}
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);
->send(session_id, false, false, true, !can_accept_calls, false);
}
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);
->send(session_id, true, !can_accept_secret_chats, false, false, false);
}
void AccountManager::set_inactive_session_ttl_days(int32 authorization_ttl_days, Promise<Unit> &&promise) {
@ -862,7 +873,7 @@ void AccountManager::on_new_unconfirmed_authorization(int64 hash, int32 date, st
}
}
void AccountManager::on_confirm_authorization(int64 hash) {
bool AccountManager::on_confirm_authorization(int64 hash) {
bool is_first_changed = false;
if (unconfirmed_authorizations_ != nullptr &&
unconfirmed_authorizations_->delete_authorization(hash, is_first_changed)) {
@ -873,7 +884,9 @@ void AccountManager::on_confirm_authorization(int64 hash) {
if (is_first_changed) {
send_update_unconfirmed_session();
}
return true;
}
return false;
}
string AccountManager::get_unconfirmed_authorizations_key() {

View File

@ -42,6 +42,8 @@ class AccountManager final : public Actor {
void terminate_all_other_sessions(Promise<Unit> &&promise);
void confirm_session(int64 session_id, 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);
@ -62,7 +64,7 @@ class AccountManager final : public Actor {
void on_new_unconfirmed_authorization(int64 hash, int32 date, string &&device, string &&location);
void on_confirm_authorization(int64 hash);
bool on_confirm_authorization(int64 hash);
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;

View File

@ -4653,6 +4653,12 @@ void Td::on_request(uint64 id, const td_api::terminateAllOtherSessions &request)
account_manager_->terminate_all_other_sessions(std::move(promise));
}
void Td::on_request(uint64 id, const td_api::confirmSession &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
account_manager_->confirm_session(request.session_id_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::toggleSessionCanAcceptCalls &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();

View File

@ -532,6 +532,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::terminateAllOtherSessions &request);
void on_request(uint64 id, const td_api::confirmSession &request);
void on_request(uint64 id, const td_api::toggleSessionCanAcceptCalls &request);
void on_request(uint64 id, const td_api::toggleSessionCanAcceptSecretChats &request);

View File

@ -2954,6 +2954,10 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::terminateSession>(session_id));
} else if (op == "TerminateAllOtherSessions") {
send_request(td_api::make_object<td_api::terminateAllOtherSessions>());
} else if (op == "cse") {
int64 session_id;
get_args(args, session_id);
send_request(td_api::make_object<td_api::confirmSession>(session_id));
} else if (op == "tscac") {
int64 session_id;
bool can_accept_calls;