directLinksEvents method

Stream<QueryResult<Object?>> directLinksEvents({
  1. ChatId? chatId,
  2. DirectLinkVersion? ver,
  3. FutureOr<DirectLinkVersion?> onVer()?,
})

Subscribes to DirectLinkEvents owned by the authenticated MyUser or the specified Chat-group.

Authentication

Mandatory.

Initialization

Once this subscription is initialized completely, it immediately emits SubscriptionInitialized.

If nothing has been emitted for a long period of time after establishing this subscription (while not being completed), it should be considered as an unexpected server error. This fact can be used on a client side to decide whether this subscription has been initialized successfully.

Result

If the ver argument is not specified (or is null) an initial state of the DirectLinksList will be emitted after SubscriptionInitialized and before any other DirectLinkEvents (and won't be emitted ever again until this subscription completes). This allows to skip calling the directLinks before establishing this subscription.

If the specified ver is not fresh (was queried quite a time ago), it may become stale, so this subscription will return a STALE_VERSION error on initialization. In such case:

  • either a fresh version should be obtained via directLinks;
  • or a re-subscription should be done without specifying the ver argument (so a fresh ver may be obtained in the emitted initial state of the DirectLinksList).

Completion

Finite.

Completes without re-subscription necessity when:

  • The Chat-group does not exist (emits nothing, completes immediately after being established).
  • The authenticated MyUser is not a member of the Chat-group at th moment of subscribing (emits nothing, completes immediately after being established).
  • The authenticated MyUser is no longer a member of the Chat-group (completes immediately after leaving the Chat-group).

Completes requiring a re-subscription when:

  • Authenticated Session expires (SESSION_EXPIRED error is emitted).
  • An error occurs on the server (error is emitted).
  • The server is shutting down or becoming unreachable (unexpectedly completes after initialization).

Idempotency

It's possible that in rare scenarios this subscription could emit an event which have already been applied to the state of some DirectLink, so a client side is expected to handle all the events idempotently considering the DtoDirectLink.ver.

Implementation

Stream<QueryResult> directLinksEvents({
  ChatId? chatId,
  DirectLinkVersion? ver,
  FutureOr<DirectLinkVersion?> Function()? onVer,
}) {
  Log.debug('directLinksEvents($chatId, $ver, onVer)', '$runtimeType');

  final variables = DirectLinksEventsArguments(chatId: chatId, ver: ver);
  return client.subscribe(
    SubscriptionOptions(
      operationName: 'DirectLinksEvents',
      document: DirectLinksEventsSubscription(variables: variables).document,
      variables: variables.toJson(),
    ),
    ver: onVer,
  );
}