restoreOlmSession method

Future<void> restoreOlmSession(
  1. String userId,
  2. String senderKey
)

Implementation

Future<void> restoreOlmSession(String userId, String senderKey) async {
  if (!client.userDeviceKeys.containsKey(userId)) {
    return;
  }
  final device = client.userDeviceKeys[userId]!.deviceKeys.values
      .firstWhereOrNull((d) => d.curve25519Key == senderKey);
  if (device == null) {
    return;
  }
  // per device only one olm session per hour should be restored
  final mapKey = '$userId;$senderKey';
  if (_restoredOlmSessionsTime.containsKey(mapKey) &&
      DateTime.now()
          .subtract(Duration(hours: 1))
          .isBefore(_restoredOlmSessionsTime[mapKey]!)) {
    Logs().w(
        '[OlmManager] Skipping restore session, one was restored in the past hour');
    return;
  }
  _restoredOlmSessionsTime[mapKey] = DateTime.now();
  await startOutgoingOlmSessions([device]);
  await client.sendToDeviceEncrypted([device], EventTypes.Dummy, {});
}