getAllEventNotifications method

void getAllEventNotifications()

adds all 'createevent' notifications to atNotificationsSink

Implementation

void getAllEventNotifications() async {
  AtClientManager.getInstance().atClient.syncService.sync();

  var response = await atClientManager.atClient.getKeys(
    regex: 'createevent-',
  );

  if (response.isEmpty) {
    SendLocationNotification().initEventData([]);
    notifyListeners();
    return;
  }

  await Future.forEach(response, (String key) async {
    var _atKey = getAtKey(key);
    AtValue? value = await getAtValue(_atKey);
    if (value != null) {
      try {
        if ((value.value != null) && (value.value != 'null')) {
          var eventNotificationModel =
              EventNotificationModel.fromJson(jsonDecode(value.value));

          // ignore: todo
          ///// TODO: Uncomment if any issues with keys
          // eventNotificationModel.key = key;

          allEventNotifications.insert(
              0,
              EventKeyLocationModel(
                  eventNotificationModel:
                      eventNotificationModel)); // last item to come in would be at the top of the list
        }
      } catch (e) {
        _logger.severe('convertJsonToLocationModel error :$e');
      }
    }
  });

  filterPastEventsFromList();
  await checkForPendingEvents();
  notifyListeners();
  calculateLocationSharingAllEvents(initLocationSharing: true);
}