getNotifies method

Future<void> getNotifies({
  1. String? atsign,
  2. int days = 1,
})

Get Notify List From AtClient

Implementation

Future<void> getNotifies({String? atsign, int days = 1}) async {
  try {
    var currentDate = DateTime.now().subtract(Duration(days: days));
    var _fromDate = '${currentDate.year}';

    if (currentDate.month < 10) {
      _fromDate = '$_fromDate-0${currentDate.month}';
    } else {
      _fromDate = '$_fromDate-${currentDate.month}';
    }

    if (currentDate.day < 10) {
      _fromDate = '$_fromDate-0${currentDate.day}';
    } else {
      _fromDate = '$_fromDate-${currentDate.day}';
    }

    notifies = [];
    notifySink.add(notifies);

    var notificationsKey = await atClient.getAtKeys(regex: storageKey);

    if (notificationsKey.isEmpty) {
      return;
    }

    for (var atKey in notificationsKey) {
      var _notificationData = await atClient.get(atKey);
      var _newNotifyObj = Notify.fromJson(_notificationData.value);

      notifies.insert(0, _newNotifyObj);
      notifySink.add(notifies);
    }
  } catch (error) {
    print('Error in getNotifies -> $error');
  }
}