startVerification method

Future<KeyVerification> startVerification({
  1. bool? newDirectChatEnableEncryption,
  2. List<StateEvent>? newDirectChatInitialState,
})

Starts a verification with this device. This might need to create a new direct chat to send the verification request over this room. For this you can set parameters here.

Implementation

Future<KeyVerification> startVerification({
  bool? newDirectChatEnableEncryption,
  List<StateEvent>? newDirectChatInitialState,
}) async {
  final encryption = client.encryption;
  if (encryption == null) {
    throw Exception('Encryption not enabled');
  }
  if (userId != client.userID) {
    // in-room verification with someone else
    final roomId = await client.startDirectChat(
      userId,
      enableEncryption: newDirectChatEnableEncryption,
      initialState: newDirectChatInitialState,
      waitForSync: false,
    );

    final room =
        client.getRoomById(roomId) ?? Room(id: roomId, client: client);
    final request =
        KeyVerification(encryption: encryption, room: room, userId: userId);
    await request.start();
    // no need to add to the request client object. As we are doing a room
    // verification request that'll happen automatically once we know the transaction id
    return request;
  } else {
    // start verification with verified devices
    final request = KeyVerification(
        encryption: encryption, userId: userId, deviceId: '*');
    await request.start();
    encryption.keyVerificationManager.addRequest(request);
    return request;
  }
}