SessionKey.fromDb constructor

SessionKey.fromDb(
  1. StoredInboundGroupSession dbEntry,
  2. String key
)

Implementation

SessionKey.fromDb(StoredInboundGroupSession dbEntry, this.key)
    : content = Event.getMapFromPayload(dbEntry.content),
      indexes = Event.getMapFromPayload(dbEntry.indexes)
          .catchMap((k, v) => MapEntry<String, String>(k, v)),
      allowedAtIndex = Event.getMapFromPayload(dbEntry.allowedAtIndex)
          .catchMap((k, v) => MapEntry(k, Map<String, int>.from(v))),
      roomId = dbEntry.roomId,
      sessionId = dbEntry.sessionId,
      senderKey = dbEntry.senderKey,
      inboundGroupSession = olm.InboundGroupSession() {
  final parsedSenderClaimedKeys =
      Event.getMapFromPayload(dbEntry.senderClaimedKeys)
          .catchMap((k, v) => MapEntry<String, String>(k, v));
  // we need to try...catch as the map used to be <String, int> and that will throw an error.
  senderClaimedKeys = (parsedSenderClaimedKeys.isNotEmpty)
      ? parsedSenderClaimedKeys
      : (content
              .tryGetMap<String, dynamic>('sender_claimed_keys')
              ?.catchMap((k, v) => MapEntry<String, String>(k, v)) ??
          (content['sender_claimed_ed25519_key'] is String
              ? <String, String>{
                  'ed25519': content['sender_claimed_ed25519_key'],
                }
              : <String, String>{}));

  try {
    inboundGroupSession!.unpickle(key, dbEntry.pickle);
  } catch (e, s) {
    dispose();
    Logs().e('[LibOlm] Unable to unpickle inboundGroupSession', e, s);
  }
}