From c3c1759f3c487f83fc86a5b1653e28dd221c052e Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 17 Feb 2021 01:25:57 +0300 Subject: [PATCH] Fixed updating number of sessions after terminating any of them. --- Telegram/SourceFiles/api/api_authorizations.cpp | 16 +++++++++++++--- Telegram/SourceFiles/boxes/sessions_box.cpp | 8 ++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Telegram/SourceFiles/api/api_authorizations.cpp b/Telegram/SourceFiles/api/api_authorizations.cpp index ea8bef14a..b0a99e929 100644 --- a/Telegram/SourceFiles/api/api_authorizations.cpp +++ b/Telegram/SourceFiles/api/api_authorizations.cpp @@ -128,9 +128,19 @@ void Authorizations::requestTerminate( const auto send = [&](auto request) { _api.request( std::move(request) - ).done( - std::move(done) - ).fail( + ).done([=, done = std::move(done)](const MTPBool &result) { + done(result); + if (mtpIsTrue(result)) { + if (hash) { + _list.erase( + ranges::remove(_list, *hash, &Entry::hash), + end(_list)); + } else { + _list.clear(); + } + _listChanges.fire({}); + } + }).fail( std::move(fail) ).send(); }; diff --git a/Telegram/SourceFiles/boxes/sessions_box.cpp b/Telegram/SourceFiles/boxes/sessions_box.cpp index 9f447dcfa..198c0e587 100644 --- a/Telegram/SourceFiles/boxes/sessions_box.cpp +++ b/Telegram/SourceFiles/boxes/sessions_box.cpp @@ -262,13 +262,13 @@ void SessionsContent::terminateOne(uint64 hash) { const auto weak = Ui::MakeWeak(this); auto callback = [=] { auto done = crl::guard(weak, [=](const MTPBool &result) { + if (mtpIsFalse(result)) { + return; + } _inner->terminatingOne(hash, false); - const auto getHash = [](const Entry &entry) { - return entry.hash; - }; const auto removeByHash = [&](std::vector &list) { list.erase( - ranges::remove(list, hash, getHash), + ranges::remove(list, hash, &Entry::hash), end(list)); }; removeByHash(_data.incomplete);