mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-07-23 14:40:58 -04:00
deadlock cleanup
This commit is contained in:
parent
23867a1784
commit
2141dbff21
40 changed files with 254 additions and 253 deletions
|
@ -15,6 +15,9 @@ import '../../notifications/notifications.dart';
|
|||
import '../../proto/proto.dart' as proto;
|
||||
import '../account_manager.dart';
|
||||
|
||||
const _kAccountRecordSubscriptionListenKey =
|
||||
'accountRecordSubscriptionListenKey';
|
||||
|
||||
class PerAccountCollectionCubit extends Cubit<PerAccountCollectionState> {
|
||||
PerAccountCollectionCubit({
|
||||
required Locator locator,
|
||||
|
@ -32,6 +35,7 @@ class PerAccountCollectionCubit extends Cubit<PerAccountCollectionState> {
|
|||
await _processor.close();
|
||||
await accountInfoCubit.close();
|
||||
await _accountRecordSubscription?.cancel();
|
||||
await serialFutureClose((this, _kAccountRecordSubscriptionListenKey));
|
||||
await accountRecordCubit?.close();
|
||||
|
||||
await activeSingleContactChatBlocMapCubitUpdater.close();
|
||||
|
@ -83,7 +87,7 @@ class PerAccountCollectionCubit extends Cubit<PerAccountCollectionState> {
|
|||
accountRecordCubit = null;
|
||||
|
||||
// Update state to 'loading'
|
||||
nextState = _updateAccountRecordState(nextState, null);
|
||||
nextState = await _updateAccountRecordState(nextState, null);
|
||||
emit(nextState);
|
||||
} else {
|
||||
///////////////// Logged in ///////////////////
|
||||
|
@ -95,20 +99,22 @@ class PerAccountCollectionCubit extends Cubit<PerAccountCollectionState> {
|
|||
|
||||
// Update state to value
|
||||
nextState =
|
||||
_updateAccountRecordState(nextState, accountRecordCubit!.state);
|
||||
await _updateAccountRecordState(nextState, accountRecordCubit!.state);
|
||||
emit(nextState);
|
||||
|
||||
// Subscribe AccountRecordCubit
|
||||
_accountRecordSubscription ??=
|
||||
accountRecordCubit!.stream.listen((avAccountRecordState) {
|
||||
emit(_updateAccountRecordState(state, avAccountRecordState));
|
||||
serialFuture((this, _kAccountRecordSubscriptionListenKey), () async {
|
||||
emit(await _updateAccountRecordState(state, avAccountRecordState));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
PerAccountCollectionState _updateAccountRecordState(
|
||||
Future<PerAccountCollectionState> _updateAccountRecordState(
|
||||
PerAccountCollectionState prevState,
|
||||
AsyncValue<AccountRecordState>? avAccountRecordState) {
|
||||
AsyncValue<AccountRecordState>? avAccountRecordState) async {
|
||||
// Get next state
|
||||
final nextState =
|
||||
prevState.copyWith(avAccountRecordState: avAccountRecordState);
|
||||
|
@ -121,8 +127,8 @@ class PerAccountCollectionCubit extends Cubit<PerAccountCollectionState> {
|
|||
.avAccountRecordState?.asData?.value.contactInvitationRecords
|
||||
.toVeilid();
|
||||
|
||||
final contactInvitationListCubit = contactInvitationListCubitUpdater.update(
|
||||
accountInfo.userLogin == null ||
|
||||
final contactInvitationListCubit = await contactInvitationListCubitUpdater
|
||||
.update(accountInfo.userLogin == null ||
|
||||
contactInvitationListRecordPointer == null
|
||||
? null
|
||||
: (accountInfo, contactInvitationListRecordPointer));
|
||||
|
@ -131,34 +137,35 @@ class PerAccountCollectionCubit extends Cubit<PerAccountCollectionState> {
|
|||
final contactListRecordPointer =
|
||||
nextState.avAccountRecordState?.asData?.value.contactList.toVeilid();
|
||||
|
||||
final contactListCubit = contactListCubitUpdater.update(
|
||||
final contactListCubit = await contactListCubitUpdater.update(
|
||||
accountInfo.userLogin == null || contactListRecordPointer == null
|
||||
? null
|
||||
: (accountInfo, contactListRecordPointer));
|
||||
|
||||
// WaitingInvitationsBlocMapCubit
|
||||
final waitingInvitationsBlocMapCubit = waitingInvitationsBlocMapCubitUpdater
|
||||
.update(accountInfo.userLogin == null ||
|
||||
contactInvitationListCubit == null ||
|
||||
contactListCubit == null
|
||||
? null
|
||||
: (
|
||||
accountInfo,
|
||||
accountRecordCubit!,
|
||||
contactInvitationListCubit,
|
||||
contactListCubit,
|
||||
_locator<NotificationsCubit>(),
|
||||
));
|
||||
final waitingInvitationsBlocMapCubit =
|
||||
await waitingInvitationsBlocMapCubitUpdater.update(
|
||||
accountInfo.userLogin == null ||
|
||||
contactInvitationListCubit == null ||
|
||||
contactListCubit == null
|
||||
? null
|
||||
: (
|
||||
accountInfo,
|
||||
accountRecordCubit!,
|
||||
contactInvitationListCubit,
|
||||
contactListCubit,
|
||||
_locator<NotificationsCubit>(),
|
||||
));
|
||||
|
||||
// ActiveChatCubit
|
||||
final activeChatCubit = activeChatCubitUpdater
|
||||
final activeChatCubit = await activeChatCubitUpdater
|
||||
.update((accountInfo.userLogin == null) ? null : true);
|
||||
|
||||
// ChatListCubit
|
||||
final chatListRecordPointer =
|
||||
nextState.avAccountRecordState?.asData?.value.chatList.toVeilid();
|
||||
|
||||
final chatListCubit = chatListCubitUpdater.update(
|
||||
final chatListCubit = await chatListCubitUpdater.update(
|
||||
accountInfo.userLogin == null ||
|
||||
chatListRecordPointer == null ||
|
||||
activeChatCubit == null
|
||||
|
@ -167,7 +174,7 @@ class PerAccountCollectionCubit extends Cubit<PerAccountCollectionState> {
|
|||
|
||||
// ActiveConversationsBlocMapCubit
|
||||
final activeConversationsBlocMapCubit =
|
||||
activeConversationsBlocMapCubitUpdater.update(
|
||||
await activeConversationsBlocMapCubitUpdater.update(
|
||||
accountRecordCubit == null ||
|
||||
chatListCubit == null ||
|
||||
contactListCubit == null
|
||||
|
@ -181,7 +188,7 @@ class PerAccountCollectionCubit extends Cubit<PerAccountCollectionState> {
|
|||
|
||||
// ActiveSingleContactChatBlocMapCubit
|
||||
final activeSingleContactChatBlocMapCubit =
|
||||
activeSingleContactChatBlocMapCubitUpdater.update(
|
||||
await activeSingleContactChatBlocMapCubitUpdater.update(
|
||||
accountInfo.userLogin == null ||
|
||||
activeConversationsBlocMapCubit == null
|
||||
? null
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue