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) {
    _olmAccount = vod.Account();
    if (!await uploadKeys(
      uploadDeviceKeys: true,
      updateDatabase: false,
      dehydratedDeviceAlgorithm: dehydratedDeviceAlgorithm,
      dehydratedDevicePickleKey:
          dehydratedDeviceAlgorithm != null ? pickleKey : null,
    )) {
      throw ('Upload key failed');
    }
  } else {
    try {
      _olmAccount = vod.Account.fromPickleEncrypted(
        pickle: olmAccount,
        pickleKey: (pickleKey ?? client.userID!).toPickleKey(),
      );
    } catch (e) {
      Logs().d(
        'Unable to unpickle account in vodozemac format. Trying Olm format...',
        e,
      );
      _olmAccount = vod.Account.fromOlmPickleEncrypted(
        pickle: olmAccount,
        pickleKey: utf8.encode(pickleKey ?? client.userID!),
      );
    }
  }
}