import 'dart:convert'; import 'package:olm/olm.dart'; import '../database/database.dart' show DbInboundGroupSession; import '../event.dart'; class SessionKey { Map content; Map indexes; InboundGroupSession inboundGroupSession; final String key; List get forwardingCurve25519KeyChain => content['forwarding_curve25519_key_chain'] ?? []; String get senderClaimedEd25519Key => content['sender_claimed_ed25519_key'] ?? ''; SessionKey({this.content, this.inboundGroupSession, this.key, this.indexes}); SessionKey.fromDb(DbInboundGroupSession dbEntry, String key) : key = key { final parsedContent = Event.getMapFromPayload(dbEntry.content); final parsedIndexes = Event.getMapFromPayload(dbEntry.indexes); content = parsedContent != null ? Map.from(parsedContent) : null; indexes = parsedIndexes != null ? Map.from(parsedIndexes) : {}; var newInboundGroupSession = InboundGroupSession(); newInboundGroupSession.unpickle(key, dbEntry.pickle); inboundGroupSession = newInboundGroupSession; } SessionKey.fromJson(Map json, String key) : key = key { content = json['content'] != null ? Map.from(json['content']) : null; indexes = json['indexes'] != null ? Map.from(json['indexes']) : {}; var newInboundGroupSession = InboundGroupSession(); newInboundGroupSession.unpickle(key, json['inboundGroupSession']); inboundGroupSession = newInboundGroupSession; } Map toJson() { final data = {}; if (content != null) { data['content'] = content; } if (indexes != null) { data['indexes'] = indexes; } data['inboundGroupSession'] = inboundGroupSession.pickle(key); return data; } @override String toString() => json.encode(toJson()); }