stopAutoSync method

void stopAutoSync({
  1. String? userId,
})

Stops automatic synchronization for one or all users.

Implementation

void stopAutoSync({String? userId}) {
  if (userId != null) {
    final timer = _autoSyncTimers.remove(userId);
    timer?.cancel();
    // If we are stopping a specific user's timer, also ensure it's not
    // marked for resumption if the manager is paused.
    if (_isSyncPaused) {
      _pausedAutoSyncUserIds.remove(userId);
    }

    // Update the global next sync time after stopping this timer
    _updateNextSyncTime();

    // Only log if a timer was actually stopped
    if (timer != null) {
      _logger.info('Auto-sync stopped for user: $userId');
    }
    return;
  }

  for (final timer in _autoSyncTimers.values) {
    timer.cancel();
  }
  _autoSyncTimers.clear();
  // If we are stopping all timers, clear the list of users to resume.
  if (_isSyncPaused) {
    _pausedAutoSyncUserIds.clear();
  }

  // Update the global next sync time after stopping all timers
  _updateNextSyncTime();
}