From 1da635a5dd3cba3f42a7c558ba1e9c29de165b96 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 12 Feb 2023 15:01:39 +0400 Subject: [PATCH] Fix crash in cloud lang manager destructor. --- .../countries/countries_manager.cpp | 23 ++++++++++--------- .../SourceFiles/lang/lang_cloud_manager.cpp | 22 +++++++++--------- Telegram/SourceFiles/main/main_domain.cpp | 2 -- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/Telegram/SourceFiles/countries/countries_manager.cpp b/Telegram/SourceFiles/countries/countries_manager.cpp index 2355208d6..5b8c30c99 100644 --- a/Telegram/SourceFiles/countries/countries_manager.cpp +++ b/Telegram/SourceFiles/countries/countries_manager.cpp @@ -148,18 +148,19 @@ auto ProcessAlternativeName(Info &&info) { Manager::Manager(not_null domain) : _path(cWorkingDir() + "tdata/countries") { read(); + + const auto mtpLifetime = _lifetime.make_state(); domain->activeValue( - ) | rpl::map([=](Main::Account *account) { - if (!account) { - _api.reset(); - } - return account - ? account->mtpMainSessionValue() - : rpl::never>(); - }) | rpl::flatten_latest( - ) | rpl::start_with_next([=](not_null instance) { - _api.emplace(instance); - request(); + ) | rpl::filter([=](Main::Account *account) { + return (account != nullptr); + }) | rpl::start_with_next_done([=](Main::Account *account) { + *mtpLifetime = account->mtpMainSessionValue( + ) | rpl::start_with_next([=](not_null instance) { + _api.emplace(instance); + request(); + }); + }, [=] { + _api.reset(); }, _lifetime); } diff --git a/Telegram/SourceFiles/lang/lang_cloud_manager.cpp b/Telegram/SourceFiles/lang/lang_cloud_manager.cpp index 1b4623db2..8c98b96d1 100644 --- a/Telegram/SourceFiles/lang/lang_cloud_manager.cpp +++ b/Telegram/SourceFiles/lang/lang_cloud_manager.cpp @@ -158,18 +158,18 @@ Language ParseLanguage(const MTPLangPackLanguage &data) { CloudManager::CloudManager(Instance &langpack) : _langpack(langpack) { + const auto mtpLifetime = _lifetime.make_state(); Core::App().domain().activeValue( - ) | rpl::map([=](Main::Account *account) { - if (!account) { - _api.reset(); - } - return account - ? account->mtpMainSessionValue() - : rpl::never>(); - }) | rpl::flatten_latest( - ) | rpl::start_with_next([=](not_null instance) { - _api.emplace(instance); - resendRequests(); + ) | rpl::filter([=](Main::Account *account) { + return (account != nullptr); + }) | rpl::start_with_next_done([=](Main::Account *account) { + *mtpLifetime = account->mtpMainSessionValue( + ) | rpl::start_with_next([=](not_null instance) { + _api.emplace(instance); + resendRequests(); + }); + }, [=] { + _api.reset(); }, _lifetime); } diff --git a/Telegram/SourceFiles/main/main_domain.cpp b/Telegram/SourceFiles/main/main_domain.cpp index 396aaeb6d..5cd02c907 100644 --- a/Telegram/SourceFiles/main/main_domain.cpp +++ b/Telegram/SourceFiles/main/main_domain.cpp @@ -202,8 +202,6 @@ Account &Domain::active() const { return *_active.current(); } - - rpl::producer> Domain::activeChanges() const { return _active.changes() | rpl::map([](Account *value) { return not_null{ value };