This commit is contained in:
Christien Rioux 2024-06-19 13:44:22 -04:00
parent aea196deb3
commit 3f8b4d2a41
2 changed files with 23 additions and 30 deletions

View File

@ -26,6 +26,8 @@ class PerAccountCollectionCubit extends Cubit<PerAccountCollectionState> {
@override @override
Future<void> close() async { Future<void> close() async {
await _initWait();
await _processor.close(); await _processor.close();
await accountInfoCubit.close(); await accountInfoCubit.close();
await _accountRecordSubscription?.cancel(); await _accountRecordSubscription?.cancel();
@ -43,8 +45,6 @@ class PerAccountCollectionCubit extends Cubit<PerAccountCollectionState> {
} }
Future<void> _init() async { Future<void> _init() async {
await _initWait();
// subscribe to accountInfo changes // subscribe to accountInfo changes
_processor.follow(accountInfoCubit.stream, accountInfoCubit.state, _processor.follow(accountInfoCubit.stream, accountInfoCubit.state,
_followAccountInfoState); _followAccountInfoState);
@ -66,11 +66,6 @@ class PerAccountCollectionCubit extends Cubit<PerAccountCollectionState> {
activeSingleContactChatBlocMapCubit: null); activeSingleContactChatBlocMapCubit: null);
Future<void> _followAccountInfoState(AccountInfo accountInfo) async { Future<void> _followAccountInfoState(AccountInfo accountInfo) async {
// If state hasn't changed just return
if (state.accountInfo == accountInfo) {
return;
}
// Get the next state // Get the next state
var nextState = state.copyWith(accountInfo: accountInfo); var nextState = state.copyWith(accountInfo: accountInfo);
@ -83,8 +78,7 @@ class PerAccountCollectionCubit extends Cubit<PerAccountCollectionState> {
_accountRecordSubscription = null; _accountRecordSubscription = null;
// Update state to 'loading' // Update state to 'loading'
nextState = nextState = _updateAccountRecordState(nextState, null);
_updateAccountRecordState(nextState, const AsyncValue.loading());
emit(nextState); emit(nextState);
// Close AccountRecordCubit // Close AccountRecordCubit
@ -116,7 +110,7 @@ class PerAccountCollectionCubit extends Cubit<PerAccountCollectionState> {
AsyncValue<AccountRecordState>? avAccountRecordState) { AsyncValue<AccountRecordState>? avAccountRecordState) {
// Get next state // Get next state
final nextState = final nextState =
state.copyWith(avAccountRecordState: avAccountRecordState); prevState.copyWith(avAccountRecordState: avAccountRecordState);
// Get bloc parameters // Get bloc parameters
final accountInfo = nextState.accountInfo; final accountInfo = nextState.accountInfo;
@ -127,7 +121,8 @@ class PerAccountCollectionCubit extends Cubit<PerAccountCollectionState> {
.toVeilid(); .toVeilid();
final contactInvitationListCubit = contactInvitationListCubitUpdater.update( final contactInvitationListCubit = contactInvitationListCubitUpdater.update(
contactInvitationListRecordPointer == null accountInfo.userLogin == null ||
contactInvitationListRecordPointer == null
? null ? null
: (accountInfo, contactInvitationListRecordPointer)); : (accountInfo, contactInvitationListRecordPointer));
@ -136,26 +131,33 @@ class PerAccountCollectionCubit extends Cubit<PerAccountCollectionState> {
nextState.avAccountRecordState?.asData?.value.contactList.toVeilid(); nextState.avAccountRecordState?.asData?.value.contactList.toVeilid();
final contactListCubit = contactListCubitUpdater.update( final contactListCubit = contactListCubitUpdater.update(
contactListRecordPointer == null accountInfo.userLogin == null || contactListRecordPointer == null
? null ? null
: (accountInfo, contactListRecordPointer)); : (accountInfo, contactListRecordPointer));
// WaitingInvitationsBlocMapCubit // WaitingInvitationsBlocMapCubit
final waitingInvitationsBlocMapCubit = waitingInvitationsBlocMapCubitUpdater final waitingInvitationsBlocMapCubit =
.update(contactInvitationListCubit == null waitingInvitationsBlocMapCubitUpdater.update(
? null accountInfo.userLogin == null || contactInvitationListCubit == null
: (accountInfo, accountRecordCubit!, contactInvitationListCubit)); ? null
: (
accountInfo,
accountRecordCubit!,
contactInvitationListCubit
));
// ActiveChatCubit // ActiveChatCubit
final activeChatCubit = activeChatCubitUpdater.update( final activeChatCubit = activeChatCubitUpdater
(nextState.avAccountRecordState?.isData ?? false) ? true : null); .update((accountInfo.userLogin == null) ? null : true);
// ChatListCubit // ChatListCubit
final chatListRecordPointer = final chatListRecordPointer =
nextState.avAccountRecordState?.asData?.value.chatList.toVeilid(); nextState.avAccountRecordState?.asData?.value.chatList.toVeilid();
final chatListCubit = chatListCubitUpdater.update( final chatListCubit = chatListCubitUpdater.update(
chatListRecordPointer == null || activeChatCubit == null accountInfo.userLogin == null ||
chatListRecordPointer == null ||
activeChatCubit == null
? null ? null
: (accountInfo, chatListRecordPointer, activeChatCubit)); : (accountInfo, chatListRecordPointer, activeChatCubit));
@ -176,7 +178,8 @@ class PerAccountCollectionCubit extends Cubit<PerAccountCollectionState> {
// ActiveSingleContactChatBlocMapCubit // ActiveSingleContactChatBlocMapCubit
final activeSingleContactChatBlocMapCubit = final activeSingleContactChatBlocMapCubit =
activeSingleContactChatBlocMapCubitUpdater.update( activeSingleContactChatBlocMapCubitUpdater.update(
activeConversationsBlocMapCubit == null || accountInfo.userLogin == null ||
activeConversationsBlocMapCubit == null ||
chatListCubit == null || chatListCubit == null ||
contactListCubit == null contactListCubit == null
? null ? null

View File

@ -21,13 +21,3 @@ class HomeAccountMissingState extends State<HomeAccountMissing> {
@override @override
Widget build(BuildContext context) => const Text('Account missing'); 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);
// });