sendEventNotification method

dynamic sendEventNotification()

sends a new 'createevent' key

Implementation

// ignore: always_declare_return_types
sendEventNotification() async {
  try {
    var eventNotification = eventNotificationModel!;

    eventNotification.atsignCreator =
        atClientManager.atClient.getCurrentAtSign();

    var atKey = AtKey()
      ..metadata = Metadata()
      ..metadata.ttr = -1
      ..metadata.ccd = true
      ..key = 'createevent-${DateTime.now().microsecondsSinceEpoch}'
      ..sharedBy = eventNotification.atsignCreator;

    eventNotification.isUpdate = false;
    eventNotification.isSharing = true;
    eventNotification.key = atKey.key;

    var notification = EventNotificationModel.convertEventNotificationToJson(
        EventService().eventNotificationModel!);

    var putResult = await atClientManager.atClient.put(
      atKey,
      notification,
    ); // creating a key and saving it for creator without adding any receiver atsign

    /// throwing an error (doesnt start with @),
    /// might lead to functional bug (so, leaving it here)
    // atKey.sharedWith = jsonEncode(
    //     [...selectedContactsAtSigns]); //adding event members in atkey

    await notifyAll(
      atKey,
      notification,
      selectedContactsAtSigns,
    );

    /// Dont need to sync as notifyAll is called

    EventKeyStreamService().addDataToList(eventNotificationModel!);

    eventNotificationModel = eventNotification;
    if (onEventSaved != null) {
      onEventSaved!(eventNotification);
    }
    return putResult;
  } catch (e) {
    _logger.severe('error in SendEventNotification $e');
    return e.toString();
  }
}