From cec6cbbd147927029f03661a2efb97bb74c8f2f2 Mon Sep 17 00:00:00 2001 From: HuyNguyen Date: Fri, 29 Dec 2023 13:39:42 +0700 Subject: [PATCH] TW-1193: Store/get/delete active account in persistent storage --- .../multiple_account_datasource.dart | 7 ++ .../multiple_account_datasource_impl.dart | 23 ++++++ .../multiple_account_cache_manager.dart | 20 +++++ .../multiple_account_repository_impl.dart | 23 ++++++ lib/di/global/get_it_initializer.dart | 23 ++++++ .../delete_persist_active_account_state.dart | 14 ++++ .../get_persist_active_account_state.dart | 18 +++++ .../store_persist_active_account_state.dart | 14 ++++ .../multiple_account_repository.dart | 7 ++ ...ete_persist_active_account_interactor.dart | 22 ++++++ ...get_persist_active_account_interactor.dart | 27 +++++++ ...ore_persist_active_account_interactor.dart | 22 ++++++ lib/pages/chat_list/chat_list.dart | 78 +++++++++++++++++-- lib/widgets/matrix.dart | 54 +++++++++---- 14 files changed, 332 insertions(+), 20 deletions(-) create mode 100644 lib/data/datasource/multiple_account/multiple_account_datasource.dart create mode 100644 lib/data/datasource_impl/multiple_account/multiple_account_datasource_impl.dart create mode 100644 lib/data/local/multiple_account/multiple_account_cache_manager.dart create mode 100644 lib/data/repository/multiple_account/multiple_account_repository_impl.dart create mode 100644 lib/domain/app_state/multiple_account/delete_persist_active_account_state.dart create mode 100644 lib/domain/app_state/multiple_account/get_persist_active_account_state.dart create mode 100644 lib/domain/app_state/multiple_account/store_persist_active_account_state.dart create mode 100644 lib/domain/repository/multiple_account/multiple_account_repository.dart create mode 100644 lib/domain/usecase/multiple_account/delete_persist_active_account_interactor.dart create mode 100644 lib/domain/usecase/multiple_account/get_persist_active_account_interactor.dart create mode 100644 lib/domain/usecase/multiple_account/store_persist_active_account_interactor.dart diff --git a/lib/data/datasource/multiple_account/multiple_account_datasource.dart b/lib/data/datasource/multiple_account/multiple_account_datasource.dart new file mode 100644 index 0000000000..890457120a --- /dev/null +++ b/lib/data/datasource/multiple_account/multiple_account_datasource.dart @@ -0,0 +1,7 @@ +abstract class MultipleAccountDatasource { + Future storePersistActiveAccount(String userId); + + Future getPersistActiveAccount(); + + Future deletePersistActiveAccount(); +} diff --git a/lib/data/datasource_impl/multiple_account/multiple_account_datasource_impl.dart b/lib/data/datasource_impl/multiple_account/multiple_account_datasource_impl.dart new file mode 100644 index 0000000000..2e67173c68 --- /dev/null +++ b/lib/data/datasource_impl/multiple_account/multiple_account_datasource_impl.dart @@ -0,0 +1,23 @@ +import 'package:fluffychat/data/datasource/multiple_account/multiple_account_datasource.dart'; +import 'package:fluffychat/data/local/multiple_account/multiple_account_cache_manager.dart'; +import 'package:fluffychat/di/global/get_it_initializer.dart'; + +class MultipleAccountDatasourceImpl implements MultipleAccountDatasource { + final MultipleAccountCacheManager _multipleAccountCacheManager = + getIt.get(); + + @override + Future getPersistActiveAccount() { + return _multipleAccountCacheManager.getPersistActiveAccount(); + } + + @override + Future storePersistActiveAccount(String userId) { + return _multipleAccountCacheManager.storePersistActiveAccount(userId); + } + + @override + Future deletePersistActiveAccount() { + return _multipleAccountCacheManager.deletePersistActiveAccount(); + } +} diff --git a/lib/data/local/multiple_account/multiple_account_cache_manager.dart b/lib/data/local/multiple_account/multiple_account_cache_manager.dart new file mode 100644 index 0000000000..2310b4d6be --- /dev/null +++ b/lib/data/local/multiple_account/multiple_account_cache_manager.dart @@ -0,0 +1,20 @@ +import 'package:fluffychat/di/global/get_it_initializer.dart'; +import 'package:fluffychat/utils/famedlysdk_store.dart'; + +class MultipleAccountCacheManager { + final pres = getIt.get(); + + static const String persistActiveAccountKey = 'persist_active_account_key'; + + Future storePersistActiveAccount(String userId) async { + await pres.setItem(persistActiveAccountKey, userId); + } + + Future getPersistActiveAccount() async { + return await pres.getItem(persistActiveAccountKey); + } + + Future deletePersistActiveAccount() async { + await pres.deleteItem(persistActiveAccountKey); + } +} diff --git a/lib/data/repository/multiple_account/multiple_account_repository_impl.dart b/lib/data/repository/multiple_account/multiple_account_repository_impl.dart new file mode 100644 index 0000000000..7bd1daffe2 --- /dev/null +++ b/lib/data/repository/multiple_account/multiple_account_repository_impl.dart @@ -0,0 +1,23 @@ +import 'package:fluffychat/data/datasource/multiple_account/multiple_account_datasource.dart'; +import 'package:fluffychat/di/global/get_it_initializer.dart'; +import 'package:fluffychat/domain/repository/multiple_account/multiple_account_repository.dart'; + +class MultipleAccountRepositoryImpl extends MultipleAccountRepository { + final MultipleAccountDatasource _multipleAccountDatasource = + getIt.get(); + + @override + Future getPersistActiveAccount() { + return _multipleAccountDatasource.getPersistActiveAccount(); + } + + @override + Future storePersistActiveAccount(String userId) { + return _multipleAccountDatasource.storePersistActiveAccount(userId); + } + + @override + Future deletePersistActiveAccount() { + return _multipleAccountDatasource.deletePersistActiveAccount(); + } +} diff --git a/lib/di/global/get_it_initializer.dart b/lib/di/global/get_it_initializer.dart index 8d3c54998c..d5e8ea7f11 100644 --- a/lib/di/global/get_it_initializer.dart +++ b/lib/di/global/get_it_initializer.dart @@ -3,6 +3,7 @@ import 'dart:collection'; import 'package:fluffychat/data/datasource/localizations/localizations_datasource.dart'; import 'package:fluffychat/data/datasource/lookup_datasource.dart'; import 'package:fluffychat/data/datasource/media/media_data_source.dart'; +import 'package:fluffychat/data/datasource/multiple_account/multiple_account_datasource.dart'; import 'package:fluffychat/data/datasource/phonebook_datasouce.dart'; import 'package:fluffychat/data/datasource/recovery_words_data_source.dart'; import 'package:fluffychat/data/datasource/server_search_datasource.dart'; @@ -13,10 +14,12 @@ import 'package:fluffychat/data/datasource_impl/contact/phonebook_contact_dataso import 'package:fluffychat/data/datasource_impl/contact/tom_contacts_datasource_impl.dart'; import 'package:fluffychat/data/datasource_impl/localizations/localizations_datasource_impl.dart'; import 'package:fluffychat/data/datasource_impl/media/media_data_source_impl.dart'; +import 'package:fluffychat/data/datasource_impl/multiple_account/multiple_account_datasource_impl.dart'; import 'package:fluffychat/data/datasource_impl/recovery_words_data_source_impl.dart'; import 'package:fluffychat/data/datasource_impl/server_search_datasource_impl.dart'; import 'package:fluffychat/data/datasource_impl/tom_configurations_datasource_impl.dart'; import 'package:fluffychat/data/local/localizations/language_cache_manager.dart'; +import 'package:fluffychat/data/local/multiple_account/multiple_account_cache_manager.dart'; import 'package:fluffychat/data/network/contact/lookup_api.dart'; import 'package:fluffychat/data/network/contact/tom_contact_api.dart'; import 'package:fluffychat/data/network/dio_cache_option.dart'; @@ -28,6 +31,7 @@ import 'package:fluffychat/data/repository/contact/phonebook_contact_repository_ import 'package:fluffychat/data/repository/contact/tom_contact_repository_impl.dart'; import 'package:fluffychat/data/repository/localizations/localizations_repository_impl.dart'; import 'package:fluffychat/data/repository/media/media_repository_impl.dart'; +import 'package:fluffychat/data/repository/multiple_account/multiple_account_repository_impl.dart'; import 'package:fluffychat/data/repository/recovery_words_repository_impl.dart'; import 'package:fluffychat/data/repository/server_search_repository_impl.dart'; import 'package:fluffychat/data/repository/tom_configurations_repository_impl.dart'; @@ -38,6 +42,7 @@ import 'package:fluffychat/domain/contact_manager/contacts_manager.dart'; import 'package:fluffychat/domain/repository/contact_repository.dart'; import 'package:fluffychat/domain/repository/localizations/localizations_repository.dart'; import 'package:fluffychat/domain/repository/lookup_repository.dart'; +import 'package:fluffychat/domain/repository/multiple_account/multiple_account_repository.dart'; import 'package:fluffychat/domain/repository/phonebook_contact_repository.dart'; import 'package:fluffychat/domain/repository/recovery_words_repository.dart'; import 'package:fluffychat/domain/repository/server_search_repository.dart'; @@ -48,6 +53,9 @@ import 'package:fluffychat/domain/usecase/download_file_for_preview_interactor.d import 'package:fluffychat/domain/usecase/forward/forward_message_interactor.dart'; import 'package:fluffychat/domain/usecase/contacts/get_tom_contacts_interactor.dart'; import 'package:fluffychat/domain/usecase/contacts/phonebook_contact_interactor.dart'; +import 'package:fluffychat/domain/usecase/multiple_account/delete_persist_active_account_interactor.dart'; +import 'package:fluffychat/domain/usecase/multiple_account/get_persist_active_account_interactor.dart'; +import 'package:fluffychat/domain/usecase/multiple_account/store_persist_active_account_interactor.dart'; import 'package:fluffychat/domain/usecase/preview_url/get_preview_url_interactor.dart'; import 'package:fluffychat/domain/usecase/recovery/delete_recovery_words_interactor.dart'; import 'package:fluffychat/domain/usecase/recovery/get_recovery_words_interactor.dart'; @@ -150,6 +158,9 @@ class GetItInitializer { getIt.registerFactory( () => ServerSearchDatasourceImpl(), ); + getIt.registerFactory( + () => MultipleAccountDatasourceImpl(), + ); } void bindingDatasourceImpl() { @@ -202,6 +213,9 @@ class GetItInitializer { getIt.registerFactory( () => ServerSearchRepositoryImpl(), ); + getIt.registerFactory( + () => MultipleAccountRepositoryImpl(), + ); } void bindingInteractor() { @@ -284,5 +298,14 @@ class GetItInitializer { getIt.registerFactory( () => SendFilesOnWebWithCaptionInteractor(), ); + getIt.registerFactory( + () => GetPersistActiveAccountInteractor(), + ); + getIt.registerFactory( + () => StorePersistActiveAccountInteractor(), + ); + getIt.registerFactory( + () => DeletePersistActiveAccountInteractor(), + ); } } diff --git a/lib/domain/app_state/multiple_account/delete_persist_active_account_state.dart b/lib/domain/app_state/multiple_account/delete_persist_active_account_state.dart new file mode 100644 index 0000000000..d8cead989b --- /dev/null +++ b/lib/domain/app_state/multiple_account/delete_persist_active_account_state.dart @@ -0,0 +1,14 @@ +import 'package:fluffychat/presentation/state/failure.dart'; +import 'package:fluffychat/presentation/state/success.dart'; + +class DeletePersistActiveAccountSuccess extends UIState { + DeletePersistActiveAccountSuccess(); + + @override + List get props => []; +} + +class DeletePersistActiveAccountFailure extends FeatureFailure { + const DeletePersistActiveAccountFailure(dynamic exception) + : super(exception: exception); +} diff --git a/lib/domain/app_state/multiple_account/get_persist_active_account_state.dart b/lib/domain/app_state/multiple_account/get_persist_active_account_state.dart new file mode 100644 index 0000000000..7fd80628f3 --- /dev/null +++ b/lib/domain/app_state/multiple_account/get_persist_active_account_state.dart @@ -0,0 +1,18 @@ +import 'package:fluffychat/presentation/state/failure.dart'; +import 'package:fluffychat/presentation/state/success.dart'; + +class GetPersistActiveAccountSuccess extends UIState { + final String userId; + + GetPersistActiveAccountSuccess(this.userId); + + @override + List get props => [userId]; +} + +class GetPersistActiveAccountFailure extends FeatureFailure { + const GetPersistActiveAccountFailure(dynamic exception) + : super(exception: exception); +} + +class PersistedActiveAccountIsEmpty extends FeatureFailure {} diff --git a/lib/domain/app_state/multiple_account/store_persist_active_account_state.dart b/lib/domain/app_state/multiple_account/store_persist_active_account_state.dart new file mode 100644 index 0000000000..7de2f887c0 --- /dev/null +++ b/lib/domain/app_state/multiple_account/store_persist_active_account_state.dart @@ -0,0 +1,14 @@ +import 'package:fluffychat/presentation/state/failure.dart'; +import 'package:fluffychat/presentation/state/success.dart'; + +class StorePersistActiveAccountSuccess extends UIState { + StorePersistActiveAccountSuccess(); + + @override + List get props => []; +} + +class StorePersistActiveAccountFailure extends FeatureFailure { + const StorePersistActiveAccountFailure(dynamic exception) + : super(exception: exception); +} diff --git a/lib/domain/repository/multiple_account/multiple_account_repository.dart b/lib/domain/repository/multiple_account/multiple_account_repository.dart new file mode 100644 index 0000000000..44b9acd5e4 --- /dev/null +++ b/lib/domain/repository/multiple_account/multiple_account_repository.dart @@ -0,0 +1,7 @@ +abstract class MultipleAccountRepository { + Future storePersistActiveAccount(String userId); + + Future getPersistActiveAccount(); + + Future deletePersistActiveAccount(); +} diff --git a/lib/domain/usecase/multiple_account/delete_persist_active_account_interactor.dart b/lib/domain/usecase/multiple_account/delete_persist_active_account_interactor.dart new file mode 100644 index 0000000000..b4a45249d9 --- /dev/null +++ b/lib/domain/usecase/multiple_account/delete_persist_active_account_interactor.dart @@ -0,0 +1,22 @@ +import 'package:dartz/dartz.dart'; +import 'package:fluffychat/app_state/failure.dart'; +import 'package:fluffychat/app_state/success.dart'; +import 'package:fluffychat/di/global/get_it_initializer.dart'; +import 'package:fluffychat/domain/app_state/multiple_account/delete_persist_active_account_state.dart'; +import 'package:fluffychat/domain/repository/multiple_account/multiple_account_repository.dart'; +import 'package:matrix/matrix.dart'; + +class DeletePersistActiveAccountInteractor { + final MultipleAccountRepository _multipleAccountRepository = + getIt.get(); + + Future> execute() async { + try { + await _multipleAccountRepository.deletePersistActiveAccount(); + return Right(DeletePersistActiveAccountSuccess()); + } catch (e) { + Logs().e('DeletePersistActiveAccountInteractor::execute(): Error $e'); + return Left(DeletePersistActiveAccountFailure(e)); + } + } +} diff --git a/lib/domain/usecase/multiple_account/get_persist_active_account_interactor.dart b/lib/domain/usecase/multiple_account/get_persist_active_account_interactor.dart new file mode 100644 index 0000000000..f68c1e0c57 --- /dev/null +++ b/lib/domain/usecase/multiple_account/get_persist_active_account_interactor.dart @@ -0,0 +1,27 @@ +import 'package:dartz/dartz.dart'; +import 'package:fluffychat/app_state/failure.dart'; +import 'package:fluffychat/app_state/success.dart'; +import 'package:fluffychat/di/global/get_it_initializer.dart'; +import 'package:fluffychat/domain/app_state/multiple_account/get_persist_active_account_state.dart'; +import 'package:fluffychat/domain/repository/multiple_account/multiple_account_repository.dart'; +import 'package:matrix/matrix.dart'; + +class GetPersistActiveAccountInteractor { + final MultipleAccountRepository _multipleAccountRepository = + getIt.get(); + + Future> execute() async { + try { + final persistActiveAccount = + await _multipleAccountRepository.getPersistActiveAccount(); + if (persistActiveAccount == null) { + return Left(PersistedActiveAccountIsEmpty()); + } else { + return Right(GetPersistActiveAccountSuccess(persistActiveAccount)); + } + } catch (e) { + Logs().e('GetPersistActiveAccountInteractor::execute(): Error $e'); + return Left(GetPersistActiveAccountFailure(e)); + } + } +} diff --git a/lib/domain/usecase/multiple_account/store_persist_active_account_interactor.dart b/lib/domain/usecase/multiple_account/store_persist_active_account_interactor.dart new file mode 100644 index 0000000000..1ca7924983 --- /dev/null +++ b/lib/domain/usecase/multiple_account/store_persist_active_account_interactor.dart @@ -0,0 +1,22 @@ +import 'package:dartz/dartz.dart'; +import 'package:fluffychat/app_state/failure.dart'; +import 'package:fluffychat/app_state/success.dart'; +import 'package:fluffychat/di/global/get_it_initializer.dart'; +import 'package:fluffychat/domain/app_state/multiple_account/store_persist_active_account_state.dart'; +import 'package:fluffychat/domain/repository/multiple_account/multiple_account_repository.dart'; +import 'package:matrix/matrix.dart'; + +class StorePersistActiveAccountInteractor { + final MultipleAccountRepository _multipleAccountRepository = + getIt.get(); + + Future> execute(String userId) async { + try { + await _multipleAccountRepository.storePersistActiveAccount(userId); + return Right(StorePersistActiveAccountSuccess()); + } catch (e) { + Logs().e('GetPersistActiveAccountInteractor::execute(): Error $e'); + return Left(StorePersistActiveAccountFailure(e)); + } + } +} diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index 38ecb50f62..397d98b710 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -5,7 +5,11 @@ import 'package:collection/collection.dart'; import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/config/first_column_inner_routes.dart'; import 'package:fluffychat/di/global/get_it_initializer.dart'; +import 'package:fluffychat/domain/app_state/multiple_account/get_persist_active_account_state.dart'; +import 'package:fluffychat/domain/app_state/multiple_account/store_persist_active_account_state.dart'; import 'package:fluffychat/domain/model/recovery_words/recovery_words.dart'; +import 'package:fluffychat/domain/usecase/multiple_account/get_persist_active_account_interactor.dart'; +import 'package:fluffychat/domain/usecase/multiple_account/store_persist_active_account_interactor.dart'; import 'package:fluffychat/domain/usecase/recovery/get_recovery_words_interactor.dart'; import 'package:fluffychat/pages/twake_id/twake_id.dart'; import 'package:fluffychat/presentation/mixins/comparable_presentation_contact_mixin.dart'; @@ -77,6 +81,12 @@ class ChatListController extends State GoToGroupChatMixin { final _getRecoveryWordsInteractor = getIt.get(); + final _getPersistActiveAccountInteractor = + getIt.get(); + + final _storePersistActiveAccountInteractor = + getIt.get(); + final responsive = getIt.get(); final ValueNotifier expandRoomsForAllNotifier = ValueNotifier(true); @@ -462,7 +472,6 @@ class ChatListController extends State } void setActiveClient(Client client) { - context.go('/rooms'); _getCurrentProfile(client); activeFilter = AppConfig.separateChatTypes ? ActiveFilter.messages @@ -471,6 +480,7 @@ class ChatListController extends State conversationSelectionNotifier.value.clear(); Matrix.of(context).setActiveClient(client); _clientStream.add(client); + setState(() {}); } void setActiveBundle(String bundle) { @@ -781,6 +791,7 @@ class ChatListController extends State ) ?.clientAccount; if (client == null) return; + _storePersistActiveAccount(client); setActiveClient(client); } @@ -797,14 +808,69 @@ class ChatListController extends State ); } - void initSetActiveClient() { + void _checkPersistedActiveAccountInitialization() { if (widget.newClient != null) { + _storePersistActiveAccount(widget.newClient!); setActiveClient(widget.newClient!); } else { - _getCurrentProfile(activeClient); + _retrievePersistedActiveAccount(); } } + void _retrievePersistedActiveAccount() async { + _getPersistActiveAccountInteractor.execute().then( + (either) => either.fold( + (failure) { + if (failure is PersistedActiveAccountIsEmpty) { + Logs().d( + 'ChatList::_retrievePersistedActiveAccount(): PersistedActiveAccountIsEmpty', + ); + _storePersistActiveAccount(activeClient); + _getCurrentProfile(activeClient); + } else { + Logs().e( + 'ChatList::_retrievePersistedActiveAccount(): $failure', + ); + } + }, + (success) { + if (success is GetPersistActiveAccountSuccess) { + Logs().d( + 'ChatList::_retrievePersistedActiveAccount(): $success', + ); + if (success.userId == activeClient.userID) { + _getCurrentProfile(activeClient); + } + final client = matrixState.getClientByUserId(success.userId); + if (client != null && success.userId != activeClient.userID) { + setActiveClient(client); + } + } + }, + ), + ); + } + + void _storePersistActiveAccount(Client newClient) { + if (newClient.userID == null) return; + _storePersistActiveAccountInteractor.execute(newClient.userID!).then( + (either) => either.fold( + (failure) { + Logs().e( + 'ChatList::_storePersistActiveAccount(): $failure', + ); + }, + (success) { + if (success is StorePersistActiveAccountSuccess) { + Logs().d( + 'ChatList::_storePersistActiveAccount(): $success', + ); + } + }, + ), + ); + } + @override void didUpdateWidget(covariant ChatList oldWidget) { Logs().d( @@ -813,8 +879,8 @@ class ChatListController extends State Logs().d( "ChatList::didUpdateWidget(): NewClient ${widget.newClient?.clientName}", ); - if (widget.newClient != activeClient) { - initSetActiveClient(); + if (widget.newClient?.userID != activeClient.userID) { + _checkPersistedActiveAccountInitialization(); } super.didUpdateWidget(oldWidget); } @@ -826,7 +892,7 @@ class ChatListController extends State } activeRoomIdNotifier.value = widget.activeRoomIdNotifier.value; scrollController.addListener(_onScroll); - initSetActiveClient(); + _checkPersistedActiveAccountInitialization(); _waitForFirstSync(); _hackyWebRTCFixForWeb(); CallKeepManager().initialize(); diff --git a/lib/widgets/matrix.dart b/lib/widgets/matrix.dart index 007dcb30b7..8ec8b848c3 100644 --- a/lib/widgets/matrix.dart +++ b/lib/widgets/matrix.dart @@ -9,10 +9,12 @@ import 'package:fluffychat/data/network/interceptor/authorization_interceptor.da import 'package:fluffychat/data/network/interceptor/dynamic_url_interceptor.dart'; import 'package:fluffychat/di/global/get_it_initializer.dart'; import 'package:fluffychat/di/global/network_di.dart'; +import 'package:fluffychat/domain/app_state/multiple_account/delete_persist_active_account_state.dart'; import 'package:fluffychat/domain/model/extensions/homeserver_summary_extensions.dart'; import 'package:fluffychat/domain/model/tom_configurations.dart'; import 'package:fluffychat/domain/model/tom_server_information.dart'; import 'package:fluffychat/domain/repository/tom_configurations_repository.dart'; +import 'package:fluffychat/domain/usecase/multiple_account/delete_persist_active_account_interactor.dart'; import 'package:fluffychat/pages/chat_list/receive_sharing_intent_mixin.dart'; import 'package:fluffychat/utils/client_manager.dart'; import 'package:fluffychat/utils/localized_exception_extension.dart'; @@ -71,6 +73,9 @@ class MatrixState extends State with WidgetsBindingObserver, ReceiveSharingIntentMixin { final tomConfigurationRepository = getIt.get(); + final _deletePersistActiveAccountInteractor = + getIt.get(); + int _activeClient = -1; String? activeBundle; Store store = Store(); @@ -205,6 +210,9 @@ class MatrixState extends State Client? getClientByName(String name) => widget.clients.firstWhereOrNull((c) => c.clientName == name); + Client? getClientByUserId(String userId) => + widget.clients.firstWhereOrNull((c) => c.userID == userId); + Map? get shareContent => _shareContent; set shareContent(Map? content) { @@ -362,19 +370,7 @@ class MatrixState extends State _cancelSubs(c.clientName); widget.clients.remove(c); ClientManager.removeClientNameFromStore(c.clientName); - TwakeSnackBar.show( - TwakeApp.routerKey.currentContext!, - L10n.of(context)!.oneClientLoggedOut, - ); - - if (state != LoginState.loggedIn) { - TwakeApp.router.go( - '/rooms', - extra: const AppAdaptiveScaffoldBodyArgs( - isLogoutMultipleAccount: true, - ), - ); - } + _handleLogoutWithMultipleAccount(state); } else { if (state == LoginState.loggedIn) { Logs().v('[MATRIX] Log in successful'); @@ -383,7 +379,7 @@ class MatrixState extends State } else { Logs().v('[MATRIX] Log out successful'); if (PlatformInfos.isMobile) { - TwakeApp.router.go('/twakeid'); + TwakeApp.router.go('/home/twakeid'); } else { TwakeApp.router.go('/home'); } @@ -407,6 +403,36 @@ class MatrixState extends State } } + void _handleLogoutWithMultipleAccount(LoginState state) { + _deletePersistActiveAccountInteractor.execute().then( + (either) => either.fold( + (failure) => Logs().e( + 'MatrixState::_handleLogoutWithMultipleAccount: Error - $failure', + ), + (success) { + if (success is DeletePersistActiveAccountSuccess) { + Logs().d( + 'MatrixState::_handleLogoutWithMultipleAccount: Delete persist active account success', + ); + TwakeSnackBar.show( + TwakeApp.routerKey.currentContext!, + L10n.of(context)!.oneClientLoggedOut, + ); + + if (state != LoginState.loggedIn) { + TwakeApp.router.go( + '/rooms', + extra: const AppAdaptiveScaffoldBodyArgs( + isLogoutMultipleAccount: true, + ), + ); + } + } + }, + ), + ); + } + void _cancelSubs(String name) { onRoomKeyRequestSub[name]?.cancel(); onRoomKeyRequestSub.remove(name);