mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-07-24 07:00:47 -04:00
message length limit
This commit is contained in:
parent
9dfb8c3f71
commit
94988718e8
13 changed files with 792 additions and 132 deletions
|
@ -97,11 +97,13 @@ class SingleContactMessagesCubit extends Cubit<SingleContactMessagesState> {
|
|||
// Initialize everything
|
||||
Future<void> _init() async {
|
||||
_unsentMessagesQueue = PersistentQueue<proto.Message>(
|
||||
table: 'SingleContactUnsentMessages',
|
||||
key: _remoteConversationRecordKey.toString(),
|
||||
fromBuffer: proto.Message.fromBuffer,
|
||||
closure: _processUnsentMessages,
|
||||
);
|
||||
table: 'SingleContactUnsentMessages',
|
||||
key: _remoteConversationRecordKey.toString(),
|
||||
fromBuffer: proto.Message.fromBuffer,
|
||||
closure: _processUnsentMessages,
|
||||
onError: (e, sp) {
|
||||
log.error('Exception while processing unsent messages: $e\n$sp\n');
|
||||
});
|
||||
|
||||
// Make crypto
|
||||
await _initCrypto();
|
||||
|
@ -297,16 +299,23 @@ class SingleContactMessagesCubit extends Cubit<SingleContactMessagesState> {
|
|||
proto.Message? previousMessage;
|
||||
final processedMessages = messages.toList();
|
||||
for (final message in processedMessages) {
|
||||
await _processMessageToSend(message, previousMessage);
|
||||
previousMessage = message;
|
||||
try {
|
||||
await _processMessageToSend(message, previousMessage);
|
||||
previousMessage = message;
|
||||
} on Exception catch (e) {
|
||||
log.error('Exception processing unsent message: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// _sendingMessages = messages;
|
||||
|
||||
// _renderState();
|
||||
|
||||
await _sentMessagesCubit!.operateAppendEventual((writer) =>
|
||||
writer.addAll(messages.map((m) => m.writeToBuffer()).toList()));
|
||||
try {
|
||||
await _sentMessagesCubit!.operateAppendEventual((writer) =>
|
||||
writer.addAll(messages.map((m) => m.writeToBuffer()).toList()));
|
||||
} on Exception catch (e) {
|
||||
log.error('Exception appending unsent messages: $e');
|
||||
}
|
||||
|
||||
// _sendingMessages = const IList.empty();
|
||||
}
|
||||
|
@ -403,6 +412,10 @@ class SingleContactMessagesCubit extends Cubit<SingleContactMessagesState> {
|
|||
..author = _accountInfo.identityTypedPublicKey.toProto()
|
||||
..timestamp = Veilid.instance.now().toInt64();
|
||||
|
||||
if ((message.writeToBuffer().lengthInBytes + 256) > 4096) {
|
||||
throw const FormatException('message is too long');
|
||||
}
|
||||
|
||||
// Put in the queue
|
||||
_unsentMessagesQueue.addSync(message);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue