accept method

Future<void> accept(
  1. InvitationLink link,
  2. String code, {
  3. Map<String, dynamic> details = const {},
  4. SealedInvitationContent? outOfBandContent,
})

Accepts an invitation with the code its inviter sent separately, sending the inviter details of this atSign's choosing.

The inviter decides; processConnections reports the connection once they have. Throws a StateError when the invitation has expired or is already connected.

Implementation

Future<void> accept(
  InvitationLink link,
  String code, {
  Map<String, dynamic> details = const {},
  SealedInvitationContent? outOfBandContent,
}) async {
  final invitation = await preview(link, outOfBandContent: outOfBandContent);
  if (invitation.obj.status == ReceivedInvitationStatus.connected) {
    throw StateError('invitation ${link.id} is already connected');
  }
  if (DateTime.now().toUtc().isAfter(invitation.obj.expiresAt)) {
    throw StateError('invitation ${link.id} has expired');
  }
  await (await acceptances).create(
    obj: InvitationAcceptance(
        invitationId: link.id, code: code, details: details),
    sharedWith: {link.inviter},
    expiresAt: invitation.obj.expiresAt.add(_afterExpiry),
  );
  await (await receivedInvitations).update(
    _withObj(invitation,
        invitation.obj.withStatus(ReceivedInvitationStatus.accepted)),
  );
}