drainOfflineQueue method

Future<void> drainOfflineQueue()

Called when connectivity comes back. Drains the queue in order. Safe to call multiple times — concurrent drain is prevented.

Implementation

Future<void> drainOfflineQueue() async {
  if (_draining || _queue.isEmpty || !isConnected || me.isEmpty) return;
  _draining = true;

  try {
    while (_queue.isNotEmpty && isConnected) {
      final entry = _queue.removeAt(0);
      _pendingCountNotifier.value = _queue.length;
      try {
        await _sendQueued(entry);
      } catch (e, st) {
        errorReporter.report(
          e,
          stackTrace: st,
          source: 'OfflineQueueMixin.drainOfflineQueue',
          context: {
            'msgId': entry.message.id,
            'roomId': entry.message.roomId,
          },
        );
      }
    }
  } finally {
    _draining = false;
  }
}