mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-07-21 13:48:43 -04:00
clean up a bunch of exceptions
This commit is contained in:
parent
c077a0290f
commit
bf38c2c44d
21 changed files with 244 additions and 166 deletions
|
@ -6,6 +6,7 @@ import 'package:sorted_list/sorted_list.dart';
|
|||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import '../../../proto/proto.dart' as proto;
|
||||
import '../../../tools/tools.dart';
|
||||
import 'author_input_queue.dart';
|
||||
import 'author_input_source.dart';
|
||||
import 'output_position.dart';
|
||||
|
@ -62,17 +63,24 @@ class MessageReconciliation {
|
|||
Future<AuthorInputQueue?> _enqueueAuthorInput(
|
||||
{required TypedKey author,
|
||||
required AuthorInputSource inputSource}) async {
|
||||
// Get the position of our most recent reconciled message from this author
|
||||
final outputPosition = await _findLastOutputPosition(author: author);
|
||||
try {
|
||||
// Get the position of our most recent reconciled message from this author
|
||||
final outputPosition = await _findLastOutputPosition(author: author);
|
||||
|
||||
// Find oldest message we have not yet reconciled
|
||||
final inputQueue = await AuthorInputQueue.create(
|
||||
author: author,
|
||||
inputSource: inputSource,
|
||||
outputPosition: outputPosition,
|
||||
onError: _onError,
|
||||
);
|
||||
return inputQueue;
|
||||
// Find oldest message we have not yet reconciled
|
||||
final inputQueue = await AuthorInputQueue.create(
|
||||
author: author,
|
||||
inputSource: inputSource,
|
||||
outputPosition: outputPosition,
|
||||
onError: _onError,
|
||||
);
|
||||
return inputQueue;
|
||||
// Catch everything so we can avoid ParallelWaitError
|
||||
// ignore: avoid_catches_without_on_clauses
|
||||
} catch (e, st) {
|
||||
log.error('Exception enqueing author input: $e:\n$st\n');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the position of our most recent reconciled message from this author
|
||||
|
|
|
@ -100,8 +100,8 @@ class SingleContactMessagesCubit extends Cubit<SingleContactMessagesState> {
|
|||
key: _remoteConversationRecordKey.toString(),
|
||||
fromBuffer: proto.Message.fromBuffer,
|
||||
closure: _processUnsentMessages,
|
||||
onError: (e, sp) {
|
||||
log.error('Exception while processing unsent messages: $e\n$sp\n');
|
||||
onError: (e, st) {
|
||||
log.error('Exception while processing unsent messages: $e\n$st\n');
|
||||
});
|
||||
|
||||
// Make crypto
|
||||
|
@ -310,14 +310,11 @@ class SingleContactMessagesCubit extends Cubit<SingleContactMessagesState> {
|
|||
|
||||
Future<void> _processMessageToSend(
|
||||
proto.Message message, proto.Message? previousMessage) async {
|
||||
// Get the previous message if we don't have one
|
||||
previousMessage ??= await _sentMessagesCubit!.operate((r) async =>
|
||||
r.length == 0
|
||||
? null
|
||||
: await r.getProtobuf(proto.Message.fromBuffer, r.length - 1));
|
||||
|
||||
message.id =
|
||||
await _senderMessageIntegrity.generateMessageId(previousMessage);
|
||||
// It's possible we had a signature from a previous
|
||||
// operateAppendEventual attempt, so clear it and make a new message id too
|
||||
message
|
||||
..clearSignature()
|
||||
..id = await _senderMessageIntegrity.generateMessageId(previousMessage);
|
||||
|
||||
// Now sign it
|
||||
await _senderMessageIntegrity.signMessage(
|
||||
|
@ -326,26 +323,33 @@ class SingleContactMessagesCubit extends Cubit<SingleContactMessagesState> {
|
|||
|
||||
// Async process to send messages in the background
|
||||
Future<void> _processUnsentMessages(IList<proto.Message> messages) async {
|
||||
// Go through and assign ids to all the messages in order
|
||||
proto.Message? previousMessage;
|
||||
final processedMessages = messages.toList();
|
||||
for (final message in processedMessages) {
|
||||
try {
|
||||
await _processMessageToSend(message, previousMessage);
|
||||
previousMessage = message;
|
||||
} on Exception catch (e) {
|
||||
log.error('Exception processing unsent message: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// _sendingMessages = messages;
|
||||
|
||||
// _renderState();
|
||||
try {
|
||||
await _sentMessagesCubit!.operateAppendEventual((writer) =>
|
||||
writer.addAll(messages.map((m) => m.writeToBuffer()).toList()));
|
||||
} on Exception catch (e) {
|
||||
log.error('Exception appending unsent messages: $e');
|
||||
await _sentMessagesCubit!.operateAppendEventual((writer) async {
|
||||
// Get the previous message if we have one
|
||||
var previousMessage = writer.length == 0
|
||||
? null
|
||||
: await writer.getProtobuf(
|
||||
proto.Message.fromBuffer, writer.length - 1);
|
||||
|
||||
// Sign all messages
|
||||
final processedMessages = messages.toList();
|
||||
for (final message in processedMessages) {
|
||||
try {
|
||||
await _processMessageToSend(message, previousMessage);
|
||||
previousMessage = message;
|
||||
} on Exception catch (e, st) {
|
||||
log.error('Exception processing unsent message: $e:\n$st\n');
|
||||
}
|
||||
}
|
||||
final byteMessages = messages.map((m) => m.writeToBuffer()).toList();
|
||||
|
||||
return writer.addAll(byteMessages);
|
||||
});
|
||||
} on Exception catch (e, st) {
|
||||
log.error('Exception appending unsent messages: $e:\n$st\n');
|
||||
}
|
||||
|
||||
// _sendingMessages = const IList.empty();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue