setCurrentAtSign method

Future<AtClientManager> setCurrentAtSign(
  1. String atSign,
  2. String? namespace,
  3. AtClientPreference preference, {
  4. AtServiceFactory? serviceFactory,
  5. AtChops? atChops,
  6. String? enrollmentId,
})
  • Can provide an AtServiceFactory to control what types of AtClients, NotificationServices and SyncServices get created by this method.
  • Can provide an AtChops instance if available; setCurrentAtSign will ensure that it is injected into objects that can use it

Implementation

Future<AtClientManager> setCurrentAtSign(
    String atSign, String? namespace, AtClientPreference preference,
    {AtServiceFactory? serviceFactory,
    AtChops? atChops,
    String? enrollmentId}) async {
  serviceFactory ??= DefaultAtServiceFactory();

  _logger.info("setCurrentAtSign called with atSign $atSign");
  AtUtils.fixAtSign(atSign);
  secondaryAddressFinder ??= CacheableSecondaryAddressFinder(
      preference.rootDomain, preference.rootPort);
  if (_currentAtClient != null &&
      _currentAtClient?.getCurrentAtSign() == atSign) {
    _logger.info(
        'previous currentAtSign ${_currentAtClient?.getCurrentAtSign()} is same as new atSign $atSign - doing nothing, returning');
    return this;
  }

  _logger.info(
      'Switching atSigns from ${_currentAtClient?.getCurrentAtSign()} to $atSign');
  _atSign = atSign;
  var previousAtClient = _currentAtClient;
  _currentAtClient = await serviceFactory
      .atClient(_atSign, namespace, preference, this, atChops: atChops);
  _currentAtClient?.enrollmentId = enrollmentId;
  final switchAtSignEvent =
      SwitchAtSignEvent(previousAtClient, _currentAtClient!);
  _notifyListeners(switchAtSignEvent);

  var notificationService =
      await serviceFactory.notificationService(_currentAtClient!, this);
  _currentAtClient!.notificationService = notificationService;

  var syncService = await serviceFactory.syncService(
      _currentAtClient!, this, notificationService);
  _currentAtClient!.syncService = syncService;

  _logger.info("setCurrentAtSign complete");

  return this;
}