diff --git a/Telegram/SourceFiles/boxes/sessions_box.cpp b/Telegram/SourceFiles/boxes/sessions_box.cpp index 0fe26ab685..3a459c6bfa 100644 --- a/Telegram/SourceFiles/boxes/sessions_box.cpp +++ b/Telegram/SourceFiles/boxes/sessions_box.cpp @@ -286,13 +286,28 @@ void SessionsBox::shortPollSessions() { update(); } -void SessionsBox::terminateOne(uint64 hash) { - if (_terminateBox) _terminateBox->deleteLater(); +void SessionsBox::terminate(Fn terminateRequest, QString message) { + if (_terminateBox) { + _terminateBox->deleteLater(); + } const auto callback = crl::guard(this, [=] { if (_terminateBox) { _terminateBox->closeBox(); _terminateBox = nullptr; } + terminateRequest(); + }); + _terminateBox = Ui::show( + Box( + message, + tr::lng_settings_reset_button(tr::now), + st::attentionBoxButton, + callback), + Ui::LayerOption::KeepOther); +} + +void SessionsBox::terminateOne(uint64 hash) { + auto callback = [=] { _api.request(MTPaccount_ResetAuthorization( MTP_long(hash) )).done([=](const MTPBool &result) { @@ -312,23 +327,12 @@ void SessionsBox::terminateOne(uint64 hash) { _inner->terminatingOne(hash, false); }).send(); _inner->terminatingOne(hash, true); - }); - _terminateBox = Ui::show( - Box( - tr::lng_settings_reset_one_sure(tr::now), - tr::lng_settings_reset_button(tr::now), - st::attentionBoxButton, - callback), - Ui::LayerOption::KeepOther); + }; + terminate(std::move(callback), tr::lng_settings_reset_one_sure(tr::now)); } void SessionsBox::terminateAll() { - if (_terminateBox) _terminateBox->deleteLater(); - const auto callback = crl::guard(this, [=] { - if (_terminateBox) { - _terminateBox->closeBox(); - _terminateBox = nullptr; - } + auto callback = [=] { _api.request(MTPauth_ResetAuthorizations( )).done([=](const MTPBool &result) { _api.request(base::take(_shortPollRequest)).cancel(); @@ -338,14 +342,8 @@ void SessionsBox::terminateAll() { shortPollSessions(); }).send(); _loading = true; - }); - _terminateBox = Ui::show( - Box( - tr::lng_settings_reset_sure(tr::now), - tr::lng_settings_reset_button(tr::now), - st::attentionBoxButton, - callback), - Ui::LayerOption::KeepOther); + }; + terminate(std::move(callback), tr::lng_settings_reset_sure(tr::now)); } SessionsBox::Inner::Inner(QWidget *parent) diff --git a/Telegram/SourceFiles/boxes/sessions_box.h b/Telegram/SourceFiles/boxes/sessions_box.h index c2f5979f57..32d25f72fb 100644 --- a/Telegram/SourceFiles/boxes/sessions_box.h +++ b/Telegram/SourceFiles/boxes/sessions_box.h @@ -55,6 +55,7 @@ private: void got(const MTPaccount_Authorizations &result); + void terminate(Fn terminateRequest, QString message); void terminateOne(uint64 hash); void terminateAll();