Add toggleSessionCanAcceptSecretChats.

This commit is contained in:
levlam 2021-11-16 15:22:00 +03:00
parent b672a7de22
commit 526e7dc631
6 changed files with 56 additions and 2 deletions

View File

@ -5360,6 +5360,9 @@ terminateSession session_id:int64 = Ok;
//@description Terminates all other sessions of the current user
terminateAllOtherSessions = Ok;
//@description Toggles whether a session can accept incoming secret chats @session_id Session identifier @can_accept_secret_chats True, if incoming secret chats can be accepted by the session
toggleSessionCanAcceptSecretChats session_id:int64 can_accept_secret_chats:Bool = Ok;
//@description Returns all website where the current user used Telegram to log in
getConnectedWebsites = ConnectedWebsites;
@ -5377,7 +5380,7 @@ setSupergroupUsername supergroup_id:int53 username:string = Ok;
//@description Changes the sticker set of a supergroup; requires can_change_info administrator right @supergroup_id Identifier of the supergroup @sticker_set_id New value of the supergroup sticker set identifier. Use 0 to remove the supergroup sticker set
setSupergroupStickerSet supergroup_id:int53 sticker_set_id:int64 = Ok;
//@description Toggles sender signatures messages sent in a channel; requires can_change_info administrator right @supergroup_id Identifier of the channel @sign_messages New value of sign_messages
//@description Toggles whether sender signature is added to sent messages in a channel; requires can_change_info administrator right @supergroup_id Identifier of the channel @sign_messages New value of sign_messages
toggleSupergroupSignMessages supergroup_id:int53 sign_messages:Bool = Ok;
//@description Toggles whether the message history of a supergroup is available to new members; requires can_change_info administrator right @supergroup_id The identifier of the supergroup @is_all_history_available The new value of is_all_history_available

View File

@ -33,7 +33,7 @@ static td_api::object_ptr<td_api::session> convert_authorization_object(
CHECK(authorization != nullptr);
return td_api::make_object<td_api::session>(
authorization->hash_, authorization->current_, authorization->password_pending_,
authorization->encrypted_requests_disabled_, authorization->api_id_, authorization->app_name_,
!authorization->encrypted_requests_disabled_, 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_);
@ -222,6 +222,35 @@ class ResetAuthorizationsQuery final : public Td::ResultHandler {
}
};
class ChangeAuthorizationSettingsQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit ChangeAuthorizationSettingsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(int64 hash, bool encrypted_requests_disabled) {
int32 flags = telegram_api::account_changeAuthorizationSettings::ENCRYPTED_REQUESTS_DISABLED_MASK;
send_query(G()->net_query_creator().create(
telegram_api::account_changeAuthorizationSettings(flags, hash, encrypted_requests_disabled, false)));
}
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 authorization settings";
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_;
@ -357,6 +386,11 @@ void terminate_all_other_sessions(Td *td, Promise<Unit> &&promise) {
td->create_handler<ResetAuthorizationsQuery>(std::move(promise))->send();
}
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, !can_accept_secret_chats);
}
void get_connected_websites(Td *td, Promise<td_api::object_ptr<td_api::connectedWebsites>> &&promise) {
td->create_handler<GetWebAuthorizationsQuery>(std::move(promise))->send();
}

View File

@ -28,6 +28,9 @@ 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_secret_chats(Td *td, int64 session_id, bool can_accept_secret_chats,
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);

View File

@ -4789,6 +4789,13 @@ void Td::on_request(uint64 id, const td_api::terminateAllOtherSessions &request)
terminate_all_other_sessions(this, 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_,
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getConnectedWebsites &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();

View File

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

View File

@ -2248,6 +2248,11 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::terminateSession>(to_integer<int64>(args)));
} else if (op == "TerminateAllOtherSessions") {
send_request(td_api::make_object<td_api::terminateAllOtherSessions>());
} else if (op == "sscasc") {
int64 session_id;
bool can_accept_secret_chats;
get_args(args, session_id, can_accept_secret_chats);
send_request(td_api::make_object<td_api::toggleSessionCanAcceptSecretChats>(session_id, can_accept_secret_chats));
} else if (op == "gcw") {
send_request(td_api::make_object<td_api::getConnectedWebsites>());
} else if (op == "dw") {