sendEventNotification method
dynamic
sendEventNotification()
Implementation
sendEventNotification() async {
try {
var eventNotification = eventNotificationModel!;
eventNotification.isUpdate = false;
eventNotification.isSharing = true;
eventNotification.key =
'createevent-${DateTime.now().microsecondsSinceEpoch}';
eventNotification.atsignCreator = atClientInstance!.currentAtSign;
var notification = EventNotificationModel.convertEventNotificationToJson(
EventService().eventNotificationModel!);
print('shared contact atsigns:$selectedContactsAtSigns');
var atKey = AtKey()
..metadata = Metadata()
..metadata!.ttr = -1
..metadata!.ccd = true
..key = eventNotification.key
..sharedBy = eventNotification.atsignCreator;
var putResult = await atClientInstance!.put(atKey, notification,
isDedicated:
true); // creating a key and saving it for creator without adding any receiver atsign
atKey.sharedWith = jsonEncode(
[...selectedContactsAtSigns]); //adding event members in atkey
await SyncSecondary().callSyncSecondary(
SyncOperation.notifyAll,
atKey: atKey,
notification: notification,
operation: OperationEnum.update,
isDedicated: MixedConstants.isDedicated,
);
/// Dont need to sync as notifyAll is called
await EventKeyStreamService().addDataToList(eventNotificationModel!);
eventNotificationModel = eventNotification;
if (onEventSaved != null) {
onEventSaved!(eventNotification);
}
return putResult;
} catch (e) {
print('error in SendEventNotification $e');
return e.toString();
}
}