useDirectLink method
- DirectLinkSlug slug
override
Uses the specified DirectLink by the authenticated MyUser creating a new Chat-dialog or joining an existing Chat-group.
Implementation
@override
Future<ChatId> useDirectLink(DirectLinkSlug slug) async {
Log.debug('useDirectLink($slug)', '$runtimeType');
if (me.isLocal) {
final query = await _graphQlProvider.searchLink(slug);
final DtoUser? user = query.searchUsers.edges.firstOrNull?.node.toDto();
if (user == null) {
return support;
}
_userRepo.put(user);
// Store the transition only if [User] found by [slug] exists.
await _slugProvider.upsert(slug);
return ChatId.local(user.id);
}
final response = await Backoff.run(
() async => await _graphQlProvider.useDirectLink(slug),
retryIf: (e) => e.isNetworkRelated,
retries: 10,
);
_add(
DtoChat(
response.chat.toModel(),
response.chat.ver,
null,
null,
null,
null,
),
);
return response.chat.id;
}