createUserDirectLink method

Future<MyUserEventsVersionedMixin?> createUserDirectLink(
  1. ChatDirectLinkSlug slug
)

Creates a new ChatDirectLink with the specified ChatDirectLinkSlug and deletes the current active ChatDirectLink of the authenticated MyUser (if any).

Deleted ChatDirectLinks can be re-created again by the original owner only (MyUser) and cannot leak to somebody else.

Authentication

Mandatory.

Result

Only the following MyUserEvent may be produced on success:

Idempotent

Succeeds as no-op (and returns no MyUserEvent) if the authenticated MyUser has an active ChatDirectLink with such ChatDirectLinkSlug already.

Implementation

Future<MyUserEventsVersionedMixin?> createUserDirectLink(
  ChatDirectLinkSlug slug,
) async {
  Log.debug('createUserDirectLink($slug)', '$runtimeType');

  final variables = CreateUserDirectLinkArguments(slug: slug);
  final QueryResult result = await client.mutate(
    MutationOptions(
      operationName: 'CreateUserDirectLink',
      document: CreateUserDirectLinkMutation(variables: variables).document,
      variables: variables.toJson(),
    ),
    onException:
        (data) => CreateChatDirectLinkException(
          (CreateUserDirectLink$Mutation.fromJson(data).createChatDirectLink
                  as CreateUserDirectLink$Mutation$CreateChatDirectLink$CreateChatDirectLinkError)
              .code,
        ),
  );
  return CreateUserDirectLink$Mutation.fromJson(
        result.data!,
      ).createChatDirectLink
      as MyUserEventsVersionedMixin?;
}