enqueueMessage method
Message
enqueueMessage(
- Message msg, {
- ChatSilentNotification notification = const ChatSilentNotification(),
- VerifyToSendMessage? verifyToSend,
- OnDeniedToSendMessage? onDeniedToSend,
inherited
Enqueue a message for later send. Returns the message immediately (with status: sending) so the UI can display it optimistically.
Implementation
Message enqueueMessage(
Message msg, {
ChatSilentNotification notification = const ChatSilentNotification(),
VerifyToSendMessage? verifyToSend,
OnDeniedToSendMessage? onDeniedToSend,
}) {
if (!offlineQueueEnabled || msg.isEmpty) {
return msg.copyWith(status: MessageStatus.failed);
}
if (_queue.length >= maxOfflineQueueSize) {
final dropped = _queue.removeAt(0);
errorReporter.report(
StateError('Offline queue full — dropping oldest'),
source: 'OfflineQueueMixin.enqueueMessage',
context: {
'droppedMsgId': dropped.message.id,
'droppedRoomId': dropped.message.roomId,
},
);
}
_queue.add(
_QueuedMessage(
message: msg,
notification: notification,
verifyToSend: verifyToSend,
onDeniedToSend: onDeniedToSend,
),
);
_pendingCountNotifier.value = _queue.length;
return msg;
}