notify method

  1. @override
Future<bool> notify(
  1. AtKey atKey,
  2. String value,
  3. OperationEnum operation, {
  4. MessageTypeEnum? messageType,
  5. PriorityEnum? priority,
  6. StrategyEnum? strategy,
  7. int? latestN,
  8. String? notifier = SYSTEM,
  9. bool isDedicated = false,
})
override

Notifies the AtKey with the sharedWith user of the atsign. Optionally, operation, value and metadata can be set along with key to notify. isDedicated need to be set to true to create a dedicated connection

e.g alice is the current atsign
notify:update:@bob:phone@alice:+1 999 9999
  var key = AtKey()..key='phone'
            ..sharedWith='@bob'
  var value='+1 999 9999'
  var operation=OperationEnum.update
  notify(key, value, operation);
notify:update:ttl:60000:ttb:30000:@bob:phone@alice:+1 999 9999
  var metaData = Metadata()..ttl='60000'
                 ..ttb='30000'
  var key = AtKey()..key='phone'
            ..sharedWith='@bob'
            ..metadata=metaData
  var value='+1 999 9999'
  var operation=OperationEnum.update
  notify(key, value, operation);

var atKey = AtKey()..key = 'phone@alice'
                   ..sharedWith = '@bob'
                   ..sharedBy = ‘@alice’
Sending Notification with Notification Strategy ‘ALL’ and priority low
await atClient.notify(atKey, ‘+1 987 986 2233’, OperationEnum.update,
                      priority: PriorityEnum.low,
                     strategy: StrategyEnum.all);

Sending Notification with Notification Strategy ‘Latest N’ and priority high
await atClient.notify(atKey, ‘+1 987 986 2233’, OperationEnum.update,
                      priority: PriorityEnum.high,
                      strategy: StrategyEnum.latest,
                      latestN:3,
                      Notifier: ‘wavi’);

Implementation

@override
Future<bool> notify(AtKey atKey, String value, OperationEnum operation,
    {MessageTypeEnum? messageType,
    PriorityEnum? priority,
    StrategyEnum? strategy,
    int? latestN,
    String? notifier = SYSTEM,
    bool isDedicated = false}) async {
  var notifyKey = atKey.key;
  var metadata = atKey.metadata;
  var sharedWith = atKey.sharedWith;
  if (metadata != null && metadata.namespaceAware) {
    notifyKey = _getKeyWithNamespace(atKey.key!);
  }
  sharedWith = AtUtils.formatAtSign(sharedWith);
  var builder = NotifyVerbBuilder()
    ..atKey = notifyKey
    ..sharedBy = currentAtSign
    ..sharedWith = sharedWith
    ..value = value
    ..operation = operation
    ..messageType = messageType
    ..priority = priority
    ..strategy = strategy
    ..latestN = latestN
    ..notifier = notifier!;
  if (sharedWith != null && sharedWith != currentAtSign) {
    try {
      builder.value =
          await _encryptionService!.encrypt(atKey.key, value, sharedWith);
    } on KeyNotFoundException catch (e) {
      var errorCode = AtClientExceptionUtil.getErrorCode(e);
      return Future.error(AtClientException(
          errorCode, AtClientExceptionUtil.getErrorDescription(errorCode)));
    }
  } else {
    builder.value =
        await _encryptionService!.encryptForSelf(atKey.key, value);
  }
  if (metadata != null) {
    builder.ttl = metadata.ttl;
    builder.ttb = metadata.ttb;
    builder.ttr = metadata.ttr;
    builder.ccd = metadata.ccd;
    builder.isPublic = metadata.isPublic!;
  }
  var isSyncRequired = true;
  if (notifyKey!.startsWith(AT_PKAM_PRIVATE_KEY) ||
      notifyKey.startsWith(AT_PKAM_PUBLIC_KEY)) {
    builder.sharedBy = null;
  }
  if (SyncUtil.shouldSkipSync(notifyKey)) {
    isSyncRequired = false;
  }
  var secondary = getSecondary(isDedicated: isDedicated);
  if (isDedicated) {
    isSyncRequired = false;
  }
  var notifyResult = await getRemoteSecondary()
      ?.executeVerb(builder, sync: (isDedicated ? false : isSyncRequired));
  if (isDedicated && (secondary is RemoteSecondary)) {
    await secondary.atLookUp.connection!.close();
  }
  return notifyResult != null;
}