acceptVerification method

Future<void> acceptVerification()

called when the user accepts an incoming verification

Implementation

Future<void> acceptVerification() async {
  if (!(await verifyLastStep([
    EventTypes.KeyVerificationRequest,
    EventTypes.KeyVerificationStart,
  ]))) {
    return;
  }
  setState(KeyVerificationState.waitingAccept);
  if (lastStep == EventTypes.KeyVerificationRequest) {
    final copyKnownVerificationMethods =
        List<String>.from(knownVerificationMethods);
    // qr code only works when atleast one side has verified master key
    if (userId == client.userID) {
      if (!(client.userDeviceKeys[client.userID]?.deviceKeys[deviceId]
                  ?.hasValidSignatureChain(verifiedByTheirMasterKey: true) ??
              false) &&
          !(client.userDeviceKeys[client.userID]?.masterKey?.verified ??
              false)) {
        copyKnownVerificationMethods
            .removeWhere((element) => element.startsWith('m.qr_code'));
        copyKnownVerificationMethods.remove(EventTypes.Reciprocate);

        // we are removing stuff only using the old possibleMethods should be ok here.
        final copyPossibleMethods = List<String>.from(possibleMethods);
        possibleMethods = _calculatePossibleMethods(
          copyKnownVerificationMethods,
          copyPossibleMethods,
        );
      }
    }
    // we need to send a ready event
    await send(EventTypes.KeyVerificationReady, {
      'methods': copyKnownVerificationMethods,
    });
    // setup QRData from incoming request (outgoing ready)
    qrCode = await generateQrCode();
    setState(KeyVerificationState.askChoice);
  } else {
    // we need to send an accept event
    await _method!
        .handlePayload(EventTypes.KeyVerificationStart, startPayload!);
  }
}