diff --git a/lib/account_manager/cubits/per_account_collection_cubit.dart b/lib/account_manager/cubits/per_account_collection_cubit.dart index 0678f4b..8b8600b 100644 --- a/lib/account_manager/cubits/per_account_collection_cubit.dart +++ b/lib/account_manager/cubits/per_account_collection_cubit.dart @@ -26,6 +26,8 @@ class PerAccountCollectionCubit extends Cubit { @override Future close() async { + await _initWait(); + await _processor.close(); await accountInfoCubit.close(); await _accountRecordSubscription?.cancel(); @@ -43,8 +45,6 @@ class PerAccountCollectionCubit extends Cubit { } Future _init() async { - await _initWait(); - // subscribe to accountInfo changes _processor.follow(accountInfoCubit.stream, accountInfoCubit.state, _followAccountInfoState); @@ -66,11 +66,6 @@ class PerAccountCollectionCubit extends Cubit { activeSingleContactChatBlocMapCubit: null); Future _followAccountInfoState(AccountInfo accountInfo) async { - // If state hasn't changed just return - if (state.accountInfo == accountInfo) { - return; - } - // Get the next state var nextState = state.copyWith(accountInfo: accountInfo); @@ -83,8 +78,7 @@ class PerAccountCollectionCubit extends Cubit { _accountRecordSubscription = null; // Update state to 'loading' - nextState = - _updateAccountRecordState(nextState, const AsyncValue.loading()); + nextState = _updateAccountRecordState(nextState, null); emit(nextState); // Close AccountRecordCubit @@ -116,7 +110,7 @@ class PerAccountCollectionCubit extends Cubit { AsyncValue? avAccountRecordState) { // Get next state final nextState = - state.copyWith(avAccountRecordState: avAccountRecordState); + prevState.copyWith(avAccountRecordState: avAccountRecordState); // Get bloc parameters final accountInfo = nextState.accountInfo; @@ -127,7 +121,8 @@ class PerAccountCollectionCubit extends Cubit { .toVeilid(); final contactInvitationListCubit = contactInvitationListCubitUpdater.update( - contactInvitationListRecordPointer == null + accountInfo.userLogin == null || + contactInvitationListRecordPointer == null ? null : (accountInfo, contactInvitationListRecordPointer)); @@ -136,26 +131,33 @@ class PerAccountCollectionCubit extends Cubit { nextState.avAccountRecordState?.asData?.value.contactList.toVeilid(); final contactListCubit = contactListCubitUpdater.update( - contactListRecordPointer == null + accountInfo.userLogin == null || contactListRecordPointer == null ? null : (accountInfo, contactListRecordPointer)); // WaitingInvitationsBlocMapCubit - final waitingInvitationsBlocMapCubit = waitingInvitationsBlocMapCubitUpdater - .update(contactInvitationListCubit == null - ? null - : (accountInfo, accountRecordCubit!, contactInvitationListCubit)); + final waitingInvitationsBlocMapCubit = + waitingInvitationsBlocMapCubitUpdater.update( + accountInfo.userLogin == null || contactInvitationListCubit == null + ? null + : ( + accountInfo, + accountRecordCubit!, + contactInvitationListCubit + )); // ActiveChatCubit - final activeChatCubit = activeChatCubitUpdater.update( - (nextState.avAccountRecordState?.isData ?? false) ? true : null); + final activeChatCubit = activeChatCubitUpdater + .update((accountInfo.userLogin == null) ? null : true); // ChatListCubit final chatListRecordPointer = nextState.avAccountRecordState?.asData?.value.chatList.toVeilid(); final chatListCubit = chatListCubitUpdater.update( - chatListRecordPointer == null || activeChatCubit == null + accountInfo.userLogin == null || + chatListRecordPointer == null || + activeChatCubit == null ? null : (accountInfo, chatListRecordPointer, activeChatCubit)); @@ -176,7 +178,8 @@ class PerAccountCollectionCubit extends Cubit { // ActiveSingleContactChatBlocMapCubit final activeSingleContactChatBlocMapCubit = activeSingleContactChatBlocMapCubitUpdater.update( - activeConversationsBlocMapCubit == null || + accountInfo.userLogin == null || + activeConversationsBlocMapCubit == null || chatListCubit == null || contactListCubit == null ? null diff --git a/lib/layout/home/home_account_missing.dart b/lib/layout/home/home_account_missing.dart index d9c0aad..a2e4db4 100644 --- a/lib/layout/home/home_account_missing.dart +++ b/lib/layout/home/home_account_missing.dart @@ -21,13 +21,3 @@ class HomeAccountMissingState extends State { @override Widget build(BuildContext context) => const Text('Account missing'); } - -// xxx click to delete missing account or add to postframecallback - // Future.delayed(0.ms, () async { - // await showErrorModal(context, translate('home.missing_account_title'), - // translate('home.missing_account_text')); - // // Delete account - // await AccountRepository.instance.deleteLocalAccount(activeUserLogin); - // // Switch to no active user login - // await AccountRepository.instance.switchToAccount(null); - // }); \ No newline at end of file