notify abstract method

Future<NotificationResult> notify(
  1. NotificationParams notificationParams, {
  2. bool waitForFinalDeliveryStatus = true,
  3. bool checkForFinalDeliveryStatus = true,
  4. dynamic onSuccess(
    1. NotificationResult
    )?,
  5. dynamic onError(
    1. NotificationResult
    )?,
  6. dynamic onSentToSecondary(
    1. NotificationResult
    )?,
})

Sends notification to notificationParams.atKey.sharedWith atSign.

Returns NotificationResult when calling the method synchronously using await. Be aware that it could take many minutes before we get to a final delivery status when we run synchronously, so we advise against that. However there is something in between 'fire and forget' and 'wait a long time' available - if you call the method synchronously using await but you also set waitForFinalDeliveryStatus to false, then the future will complete once the notification has been successfully sent to our cloud secondary, which is thereafter responsible for forwarding to the recipient; the polling for delivery status will continue asynchronously and eventually your provided onSuccess or onError function will be called.

If you set the optional checkForFinalDeliveryStatus parameter to false, then you can prevent the polling for final delivery status to be done at all by this method, and instead if you need to, you can do the periodic checking for final delivery status elsewhere in your code.

When run asynchronously, register to onSentToSecondary, onSuccess and onError callbacks to get NotificationResult.

onSentToSecondary is called when the notification has been sent from our client to our cloud secondary

onSuccess is called when the notification has been delivered to the recipient's secondary successfully.

onError is called when the notification could not delivered. Note that this could be a very long time

Following exceptions are encapsulated in NotificationResult.atClientException

  • AtKeyException when invalid NotificationParams.atKey.key is formed or when invalid metadata is provided.
  • InvalidAtSignException on invalid NotificationParams.atKey.sharedWith or NotificationParams.atKey.sharedBy
  • AtClientException when keys to encrypt the data are not found.
  • AtClientException when notificationParams.notifier is null when notificationParams.strategy is set to latest.
  • AtClientException when fails to connect to cloud secondary server.

Usage

var currentAtSign = '@alice'
  1. To notify update of a key to @bob.
 var key = AtKey()
   ..key = 'phone'
   ..sharedWith = '@bob';

 var notificationService = AtClientManager.getInstance().notificationService;
 await notificationService.notify(NotificationParams.forUpdate(key));
  1. To notify and cache a key to @bob
 var metaData = Metadata()..ttr = '600000';
 var key = AtKey()
   ..key = 'phone'
   ..sharedWith = '@bob'
   ..metadata = metaData;

 var value = '+1 998 999 4940'

 var notificationService = AtClientManager.getInstance().notificationService;
 await notificationService.notify(NotificationParams.forUpdate(key, value: value));
  1. To notify deletion of a key to @bob.
 var key = AtKey()
    ..key = 'phone'
    ..sharedWith = '@bob';

  var notificationService = AtClientManager.getInstance().notificationService;
  await notificationService.notify(NotificationParams.forDelete(key));
  1. To notify a text message to @bob forText notifications are case sensitive await notificationService.notify(NotificationParams.forText(
  var notificationService = AtClientManager.getInstance().notificationService;
  await notificationService.notify(NotificationParams.forText('Hello','@bob'));

Implementation

Future<NotificationResult> notify(NotificationParams notificationParams,
    {bool waitForFinalDeliveryStatus =
        true, // this was the behaviour before introducing this parameter
    bool checkForFinalDeliveryStatus =
        true, // this was the behaviour before introducing this parameter
    Function(NotificationResult)? onSuccess,
    Function(NotificationResult)? onError,
    Function(NotificationResult)? onSentToSecondary});