preApproveSubscription method

Future<bool> preApproveSubscription(
  1. JID to
)

Similar to requestSubscription, but it also tells the server to automatically accept a subscription request from to, should it arrive. This requires a PresenceNegotiator to be registered as this feature is optional.

Returns true, when the stanza was sent. Returns false, when the stanza was not sent, for example because the server does not support subscription pre-approvals.

Implementation

Future<bool> preApproveSubscription(JID to) async {
  final negotiator = getAttributes()
      .getNegotiatorById<PresenceNegotiator>(presenceNegotiator);
  assert(negotiator != null, 'No PresenceNegotiator registered');

  if (!negotiator!.preApprovalSupported) {
    return false;
  }

  await getAttributes().sendStanza(
    StanzaDetails(
      Stanza.presence(
        type: 'subscribed',
        to: to.toString(),
      ),
      awaitable: false,
    ),
  );
  return true;
}