mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2024-10-01 06:55:46 -04:00
exception handling work
This commit is contained in:
parent
1b7ac31085
commit
cbac96de99
@ -56,7 +56,7 @@ class AccountRecordCubit extends DefaultDHTRecordCubit<AccountRecordState> {
|
||||
Future<void> _updateAccountAsync(
|
||||
AccountSpec accountSpec, Future<void> Function() onSuccess) async {
|
||||
var changed = false;
|
||||
await record.eventualUpdateProtobuf(proto.Account.fromBuffer, (old) async {
|
||||
await record?.eventualUpdateProtobuf(proto.Account.fromBuffer, (old) async {
|
||||
changed = false;
|
||||
if (old == null) {
|
||||
return null;
|
||||
|
@ -41,7 +41,7 @@ class WaitingInvitationsBlocMapCubit extends BlocMapCubit<TypedKey,
|
||||
|
||||
@override
|
||||
Future<void> close() async {
|
||||
await _singleInvitationStatusProcessor.unfollow();
|
||||
await _singleInvitationStatusProcessor.close();
|
||||
await super.close();
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,7 @@ class ConversationCubit extends Cubit<AsyncValue<ConversationState>> {
|
||||
return;
|
||||
}
|
||||
serialFuture((this, _sfUpdateAccountChange), () async {
|
||||
await cubit.record.eventualUpdateProtobuf(proto.Conversation.fromBuffer,
|
||||
await cubit.record?.eventualUpdateProtobuf(proto.Conversation.fromBuffer,
|
||||
(old) async {
|
||||
if (old == null || old.profile == account.profile) {
|
||||
return null;
|
||||
|
@ -80,7 +80,7 @@ class MenuItemWidget extends StatelessWidget {
|
||||
),
|
||||
onPressed: footerCallback),
|
||||
],
|
||||
),
|
||||
).paddingAll(2),
|
||||
);
|
||||
|
||||
@override
|
||||
|
@ -39,7 +39,7 @@ class AvatarWidget extends StatelessWidget {
|
||||
width: _size,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: _scaleConfig.preferBorders
|
||||
border: _scaleConfig.useVisualIndicators
|
||||
? Border.all(
|
||||
color: _borderColor,
|
||||
width: 1 * (_size ~/ 32 + 1),
|
||||
|
@ -116,7 +116,7 @@ Widget buildProgressIndicator() => Builder(builder: (context) {
|
||||
return FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: SpinKitFoldingCube(
|
||||
color: scale.tertiaryScale.primary,
|
||||
color: scale.tertiaryScale.border,
|
||||
size: 80,
|
||||
));
|
||||
});
|
||||
|
@ -52,8 +52,11 @@ class DefaultDHTRecordCubit<T> extends DHTRecordCubit<T> {
|
||||
|
||||
Future<void> refreshDefault() async {
|
||||
await initWait();
|
||||
|
||||
final defaultSubkey = record.subkeyOrDefault(-1);
|
||||
await refresh([ValueSubkeyRange(low: defaultSubkey, high: defaultSubkey)]);
|
||||
final rec = record;
|
||||
if (rec != null) {
|
||||
final defaultSubkey = rec.subkeyOrDefault(-1);
|
||||
await refresh(
|
||||
[ValueSubkeyRange(low: defaultSubkey, high: defaultSubkey)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ abstract class DHTRecordCubit<T> extends Cubit<AsyncValue<T>> {
|
||||
// Do record open/create
|
||||
while (!cancel.isCompleted) {
|
||||
try {
|
||||
_record = await open();
|
||||
record = await open();
|
||||
_wantsCloseRecord = true;
|
||||
break;
|
||||
} on DHTExceptionNotAvailable {
|
||||
@ -49,7 +49,7 @@ abstract class DHTRecordCubit<T> extends Cubit<AsyncValue<T>> {
|
||||
) async {
|
||||
// Make initial state update
|
||||
try {
|
||||
final initialState = await initialStateFunction(_record);
|
||||
final initialState = await initialStateFunction(record!);
|
||||
if (initialState != null) {
|
||||
emit(AsyncValue.data(initialState));
|
||||
}
|
||||
@ -57,7 +57,7 @@ abstract class DHTRecordCubit<T> extends Cubit<AsyncValue<T>> {
|
||||
emit(AsyncValue.error(e));
|
||||
}
|
||||
|
||||
_subscription = await _record.listen((record, data, subkeys) async {
|
||||
_subscription = await record!.listen((record, data, subkeys) async {
|
||||
try {
|
||||
final newState = await stateFunction(record, subkeys, data);
|
||||
if (newState != null) {
|
||||
@ -68,17 +68,17 @@ abstract class DHTRecordCubit<T> extends Cubit<AsyncValue<T>> {
|
||||
}
|
||||
});
|
||||
|
||||
await watchFunction(_record);
|
||||
await watchFunction(record!);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() async {
|
||||
await initWait(cancelValue: true);
|
||||
await _record.cancelWatch();
|
||||
await record?.cancelWatch();
|
||||
await _subscription?.cancel();
|
||||
_subscription = null;
|
||||
if (_wantsCloseRecord) {
|
||||
await _record.close();
|
||||
await record?.close();
|
||||
_wantsCloseRecord = false;
|
||||
}
|
||||
await super.close();
|
||||
@ -91,10 +91,10 @@ abstract class DHTRecordCubit<T> extends Cubit<AsyncValue<T>> {
|
||||
|
||||
for (final skr in subkeys) {
|
||||
for (var sk = skr.low; sk <= skr.high; sk++) {
|
||||
final data = await _record.get(
|
||||
subkey: sk, refreshMode: DHTRecordRefreshMode.update);
|
||||
final data = await record!
|
||||
.get(subkey: sk, refreshMode: DHTRecordRefreshMode.update);
|
||||
if (data != null) {
|
||||
final newState = await _stateFunction(_record, updateSubkeys, data);
|
||||
final newState = await _stateFunction(record!, updateSubkeys, data);
|
||||
if (newState != null) {
|
||||
// Emit the new state
|
||||
emit(AsyncValue.data(newState));
|
||||
@ -108,13 +108,13 @@ abstract class DHTRecordCubit<T> extends Cubit<AsyncValue<T>> {
|
||||
}
|
||||
}
|
||||
|
||||
DHTRecord get record => _record;
|
||||
// DHTRecord get record => _record;
|
||||
|
||||
@protected
|
||||
final WaitSet<void, bool> initWait = WaitSet();
|
||||
|
||||
StreamSubscription<DHTRecordWatchChange>? _subscription;
|
||||
late DHTRecord _record;
|
||||
DHTRecord? record;
|
||||
bool _wantsCloseRecord;
|
||||
final StateFunction<T> _stateFunction;
|
||||
}
|
||||
|
@ -849,7 +849,7 @@ class DHTRecordPool with TableDBBackedJson<DHTRecordPoolAllocations> {
|
||||
openedRecordInfo.shared.needsWatchStateUpdate = false;
|
||||
}
|
||||
} on VeilidAPIException catch (e) {
|
||||
// Failed to cancel DHT watch, try again next tick
|
||||
// Failed to update DHT watch, try again next tick
|
||||
log('Exception in watch update: $e');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user