init method

Future<void> init({
  1. String? olmAccount,
  2. required String? deviceId,
  3. String? pickleKey,
  4. String? dehydratedDeviceAlgorithm,
})

Implementation

Future<void> init({
  String? olmAccount,
  required String? deviceId,
  String? pickleKey,
  String? dehydratedDeviceAlgorithm,
}) async {
  ourDeviceId = deviceId;
  if (olmAccount == null) {
    try {
      await olm.init();
      _olmAccount = olm.Account();
      _olmAccount!.create();
      if (!await uploadKeys(
        uploadDeviceKeys: true,
        updateDatabase: false,
        dehydratedDeviceAlgorithm: dehydratedDeviceAlgorithm,
        dehydratedDevicePickleKey:
            dehydratedDeviceAlgorithm != null ? pickleKey : null,
      )) {
        throw ('Upload key failed');
      }
    } catch (_) {
      _olmAccount?.free();
      _olmAccount = null;
      rethrow;
    }
  } else {
    try {
      await olm.init();
      _olmAccount = olm.Account();
      _olmAccount!.unpickle(pickleKey ?? client.userID!, olmAccount);
    } catch (_) {
      _olmAccount?.free();
      _olmAccount = null;
      rethrow;
    }
  }
}