init method

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

Implementation

Future<void> init(
    {String? olmAccount,
    required String? deviceId,
    String? pickleKey}) async {
  ourDeviceId = deviceId;
  if (olmAccount == null) {
    try {
      await olm.init();
      _olmAccount = olm.Account();
      _olmAccount!.create();
      if (!await uploadKeys(
          uploadDeviceKeys: true,
          updateDatabase: false,
          // dehydrated devices don't have a device id when created, so skip upload in that case.
          skipAllUploads: deviceId == 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;
    }
  }
}