open method

Future<void> open()

Implementation

Future<void> open() async {
  _collection = await collectionFactory(
    name,
    {
      _clientBoxName,
      _accountDataBoxName,
      _roomsBoxName,
      _toDeviceQueueBoxName,
      _roomStateBoxName,
      _roomMembersBoxName,
      _roomAccountDataBoxName,
      _inboundGroupSessionsBoxName,
      _outboundGroupSessionsBoxName,
      _olmSessionsBoxName,
      _userDeviceKeysBoxName,
      _userDeviceKeysOutdatedBoxName,
      _userCrossSigningKeysBoxName,
      _ssssCacheBoxName,
      _presencesBoxName,
      _timelineFragmentsBoxName,
      _eventsBoxName,
      _seenDeviceIdsBoxName,
      _seenDeviceKeysBoxName,
    },
    key: key,
    path: path,
  );
  _clientBox = await _collection.openBox(
    _clientBoxName,
    preload: true,
  );
  _accountDataBox = await _collection.openBox(
    _accountDataBoxName,
    preload: true,
  );
  _roomsBox = await _collection.openBox(
    _roomsBoxName,
    preload: true,
  );
  _roomStateBox = await _collection.openBox(
    _roomStateBoxName,
  );
  _roomMembersBox = await _collection.openBox(
    _roomMembersBoxName,
  );
  _toDeviceQueueBox = await _collection.openBox(
    _toDeviceQueueBoxName,
    preload: true,
  );
  _roomAccountDataBox = await _collection.openBox(
    _roomAccountDataBoxName,
    preload: true,
  );
  _inboundGroupSessionsBox = await _collection.openBox(
    _inboundGroupSessionsBoxName,
  );
  _outboundGroupSessionsBox = await _collection.openBox(
    _outboundGroupSessionsBoxName,
  );
  _olmSessionsBox = await _collection.openBox(
    _olmSessionsBoxName,
  );
  _userDeviceKeysBox = await _collection.openBox(
    _userDeviceKeysBoxName,
  );
  _userDeviceKeysOutdatedBox = await _collection.openBox(
    _userDeviceKeysOutdatedBoxName,
  );
  _userCrossSigningKeysBox = await _collection.openBox(
    _userCrossSigningKeysBoxName,
  );
  _ssssCacheBox = await _collection.openBox(
    _ssssCacheBoxName,
  );
  _presencesBox = await _collection.openBox(
    _presencesBoxName,
  );
  _timelineFragmentsBox = await _collection.openBox(
    _timelineFragmentsBoxName,
  );
  _eventsBox = await _collection.openBox(
    _eventsBoxName,
  );
  _seenDeviceIdsBox = await _collection.openBox(
    _seenDeviceIdsBoxName,
  );
  _seenDeviceKeysBox = await _collection.openBox(
    _seenDeviceKeysBoxName,
  );

  // Check version and check if we need a migration
  final currentVersion = int.tryParse(await _clientBox.get('version') ?? '');
  if (currentVersion == null) {
    await _clientBox.put('version', version.toString());
  } else if (currentVersion != version) {
    await _migrateFromVersion(currentVersion);
  }

  return;
}