sendActivate method

Future<int> sendActivate(
  1. Activate activateHit
)
override

Implementation

Future<int> sendActivate(Activate activateHit) async {
  // Add the current activate by default
  List<Hit> listOfActivate = [activateHit];
  bool needToClean = false;

  /// When yes, the cache and pool need to be cleaned
  // If we have a failed activate hits
  if (_activatePool.isNotEmpty()) {
    needToClean = true;
    Flagship.logger(Level.ALL,
        "Add previous activates in batch found in the pool activate");
    listOfActivate.addAll(
        _activatePool.extractHitsWithVisitorId(activateHit.visitorId));
  } else {
    // We dont have any failed activate in the pool
  }
  var statusCode = await sendActivateBatch(listOfActivate);
  switch (statusCode) {
    case 200:
    case 204:
      // Clear all the activate in the pool and clear them from cache
      if (needToClean) {
        _activatePool.flushAllTrackFromQueue();
        listOfActivate.remove(
            activateHit); // Remove the current hit before because is not already present in the cache.
        onSendActivateBatchWithSuccess(listOfActivate);
      }
      break;
    default:
      _activatePool.addNewTrackElement(activateHit);
      this.onCacheHit(activateHit);
  }
  return statusCode;
}