busy handling

This commit is contained in:
Christien Rioux 2024-02-27 12:45:58 -05:00
parent 43b01c7555
commit c6f017b0d1
23 changed files with 307 additions and 179 deletions

View file

@ -1,6 +1,7 @@
import 'dart:async';
import 'package:async_tools/async_tools.dart';
import 'package:bloc_tools/bloc_tools.dart';
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:veilid_support/veilid_support.dart';
@ -61,9 +62,10 @@ class MessagesCubit extends Cubit<AsyncValue<IList<proto.Message>>> {
await super.close();
}
void updateLocalMessagesState(AsyncValue<IList<proto.Message>> avmessages) {
void updateLocalMessagesState(
BlocBusyState<AsyncValue<IList<proto.Message>>> avmessages) {
// Updated local messages from online just update the state immediately
emit(avmessages);
emit(avmessages.state);
}
Future<void> _updateRemoteMessagesStateAsync(_MessageQueueEntry entry) async {
@ -97,16 +99,17 @@ class MessagesCubit extends Cubit<AsyncValue<IList<proto.Message>>> {
// Insert at this position
if (!skip) {
// Insert into dht backing array
await _localMessagesCubit!.shortArray
.tryInsertItem(pos, newMessage.writeToBuffer());
await _localMessagesCubit!.operate((shortArray) =>
shortArray.tryInsertItem(pos, newMessage.writeToBuffer()));
// Insert into local copy as well for this operation
localMessages = localMessages.insert(pos, newMessage);
}
}
}
void updateRemoteMessagesState(AsyncValue<IList<proto.Message>> avmessages) {
final remoteMessages = avmessages.data?.value;
void updateRemoteMessagesState(
BlocBusyState<AsyncValue<IList<proto.Message>>> avmessages) {
final remoteMessages = avmessages.state.data?.value;
if (remoteMessages == null) {
return;
}
@ -171,7 +174,8 @@ class MessagesCubit extends Cubit<AsyncValue<IList<proto.Message>>> {
}
Future<void> addMessage({required proto.Message message}) async {
await _localMessagesCubit!.shortArray.tryAddItem(message.writeToBuffer());
await _localMessagesCubit!.operate(
(shortArray) => shortArray.tryAddItem(message.writeToBuffer()));
}
Future<DHTRecordCrypto> getMessagesCrypto() async {

View file

@ -48,7 +48,8 @@ class ChatComponent extends StatelessWidget {
if (accountRecordInfo == null) {
return debugPage('should always have an account record here');
}
final contactList = context.watch<ContactListCubit>().state.data?.value;
final contactList =
context.watch<ContactListCubit>().state.state.data?.value;
if (contactList == null) {
return debugPage('should always have a contact list here');
}