From ae79af6ea8cac137ec0f075321846e47eaa795f1 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Fri, 2 Oct 2020 11:25:31 +0200 Subject: [PATCH 1/2] fix: store timestamps in milliseconds to fix decrypt error --- lib/encryption/encryption.dart | 2 +- lib/encryption/key_manager.dart | 2 +- lib/encryption/olm_manager.dart | 8 +- lib/encryption/utils/olm_session.dart | 2 +- .../utils/outbound_group_session.dart | 2 +- lib/src/client.dart | 10 +- lib/src/database/database.dart | 34 +- lib/src/database/database.g.dart | 939 ++++++++++++------ lib/src/database/database.moor | 10 +- lib/src/event.dart | 8 +- pubspec.yaml | 4 + test/room_test.dart | 2 +- 12 files changed, 711 insertions(+), 312 deletions(-) diff --git a/lib/encryption/encryption.dart b/lib/encryption/encryption.dart index 1a3557a..9741460 100644 --- a/lib/encryption/encryption.dart +++ b/lib/encryption/encryption.dart @@ -362,10 +362,10 @@ class Encryption { } void dispose() { + _backgroundTasksRunning = false; keyManager.dispose(); olmManager.dispose(); keyVerificationManager.dispose(); - _backgroundTasksRunning = false; } } diff --git a/lib/encryption/key_manager.dart b/lib/encryption/key_manager.dart index 3c4ce5b..92e8a65 100644 --- a/lib/encryption/key_manager.dart +++ b/lib/encryption/key_manager.dart @@ -286,7 +286,7 @@ class KeyManager { roomId, sess.outboundGroupSession.pickle(client.userID), json.encode(sess.devices), - sess.creationTime, + sess.creationTime.millisecondsSinceEpoch, sess.sentMessages); } diff --git a/lib/encryption/olm_manager.dart b/lib/encryption/olm_manager.dart index 9635939..52ce2d6 100644 --- a/lib/encryption/olm_manager.dart +++ b/lib/encryption/olm_manager.dart @@ -238,8 +238,12 @@ class OlmManager { // update an existing session _olmSessions[session.identityKey][ix] = session; } - client.database.storeOlmSession(client.id, session.identityKey, - session.sessionId, session.pickledSession, session.lastReceived); + client.database.storeOlmSession( + client.id, + session.identityKey, + session.sessionId, + session.pickledSession, + session.lastReceived.millisecondsSinceEpoch); } ToDeviceEvent _decryptToDeviceEvent(ToDeviceEvent event) { diff --git a/lib/encryption/utils/olm_session.dart b/lib/encryption/utils/olm_session.dart index 2edf4cb..41f66a6 100644 --- a/lib/encryption/utils/olm_session.dart +++ b/lib/encryption/utils/olm_session.dart @@ -46,7 +46,7 @@ class OlmSession { identityKey = dbEntry.identityKey; sessionId = dbEntry.sessionId; lastReceived = - dbEntry.lastReceived ?? DateTime.fromMillisecondsSinceEpoch(0); + DateTime.fromMillisecondsSinceEpoch(dbEntry.lastReceived ?? 0); assert(sessionId == session.session_id()); } catch (e, s) { Logs.error('[LibOlm] Could not unpickle olm session: ' + e.toString(), s); diff --git a/lib/encryption/utils/outbound_group_session.dart b/lib/encryption/utils/outbound_group_session.dart index d3da8cb..e9e2414 100644 --- a/lib/encryption/utils/outbound_group_session.dart +++ b/lib/encryption/utils/outbound_group_session.dart @@ -44,7 +44,7 @@ class OutboundGroupSession { try { outboundGroupSession.unpickle(key, dbEntry.pickle); devices = List.from(json.decode(dbEntry.deviceIds)); - creationTime = dbEntry.creationTime; + creationTime = DateTime.fromMillisecondsSinceEpoch(dbEntry.creationTime); sentMessages = dbEntry.sentMessages; } catch (e, s) { dispose(); diff --git a/lib/src/client.dart b/lib/src/client.dart index ce3dc43..45025ac 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -1579,15 +1579,19 @@ sort order of ${prevState.sortOrder}. This should never happen...'''); /// you can safely make this Client instance null. Future dispose({bool closeDatabase = false}) async { _disposed = true; + encryption?.dispose(); + encryption = null; try { await _currentTransaction; } catch (_) { // No-OP } - if (closeDatabase) await database?.close(); + try { + if (closeDatabase) await database?.close(); + } catch (error, stacktrace) { + Logs.warning('Failed to close database: ' + error.toString(), stacktrace); + } database = null; - encryption?.dispose(); - encryption = null; return; } } diff --git a/lib/src/database/database.dart b/lib/src/database/database.dart index d1b3d2b..a61dfa3 100644 --- a/lib/src/database/database.dart +++ b/lib/src/database/database.dart @@ -55,7 +55,7 @@ class Database extends _$Database { Database.connect(DatabaseConnection connection) : super.connect(connection); @override - int get schemaVersion => 6; + int get schemaVersion => 7; int get maxFileSize => 1 * 1024 * 1024; @@ -117,6 +117,27 @@ class Database extends _$Database { inboundGroupSessions, inboundGroupSessions.senderClaimedKeys); from++; } + if (from == 6) { + // DATETIME was internally an int, so we should be able to re-use the + // olm_sessions table. + await m.deleteTable('outbound_group_sessions'); + await m.createTable(outboundGroupSessions); + await m.deleteTable('events'); + await m.createTable(events); + await m.deleteTable('room_states'); + await m.createTable(roomStates); + await m.deleteTable('files'); + await m.createTable(files); + // and now clear cache + await delete(presences).go(); + await delete(roomAccountData).go(); + await delete(accountData).go(); + await delete(roomStates).go(); + await delete(events).go(); + await delete(rooms).go(); + await delete(outboundGroupSessions).go(); + await customStatement('UPDATE clients SET prev_batch = null'); + } } catch (e, s) { Logs.error(e, s); onError.add(SdkError(exception: e, stackTrace: s)); @@ -484,10 +505,8 @@ class Database extends _$Database { eventContent['event_id'], chatId, oldEvent?.sortOrder ?? eventUpdate.sortOrder, - eventContent['origin_server_ts'] != null - ? DateTime.fromMillisecondsSinceEpoch( - eventContent['origin_server_ts']) - : DateTime.now(), + eventContent['origin_server_ts'] ?? + DateTime.now().millisecondsSinceEpoch, eventContent['sender'], eventContent['type'], json.encode(eventContent['unsigned'] ?? ''), @@ -520,10 +539,7 @@ class Database extends _$Database { eventContent['event_id'] ?? now.millisecondsSinceEpoch.toString(), chatId, eventUpdate.sortOrder ?? 0.0, - eventContent['origin_server_ts'] != null - ? DateTime.fromMillisecondsSinceEpoch( - eventContent['origin_server_ts']) - : now, + eventContent['origin_server_ts'] ?? now.millisecondsSinceEpoch, eventContent['sender'], eventContent['type'], json.encode(eventContent['unsigned'] ?? ''), diff --git a/lib/src/database/database.g.dart b/lib/src/database/database.g.dart index 103bd86..984288a 100644 --- a/lib/src/database/database.g.dart +++ b/lib/src/database/database.g.dart @@ -85,6 +85,34 @@ class DbClient extends DataClass implements Insertable { return map; } + ClientsCompanion toCompanion(bool nullToAbsent) { + return ClientsCompanion( + clientId: clientId == null && nullToAbsent + ? const Value.absent() + : Value(clientId), + name: name == null && nullToAbsent ? const Value.absent() : Value(name), + homeserverUrl: homeserverUrl == null && nullToAbsent + ? const Value.absent() + : Value(homeserverUrl), + token: + token == null && nullToAbsent ? const Value.absent() : Value(token), + userId: + userId == null && nullToAbsent ? const Value.absent() : Value(userId), + deviceId: deviceId == null && nullToAbsent + ? const Value.absent() + : Value(deviceId), + deviceName: deviceName == null && nullToAbsent + ? const Value.absent() + : Value(deviceName), + prevBatch: prevBatch == null && nullToAbsent + ? const Value.absent() + : Value(prevBatch), + olmAccount: olmAccount == null && nullToAbsent + ? const Value.absent() + : Value(olmAccount), + ); + } + factory DbClient.fromJson(Map json, {ValueSerializer serializer}) { serializer ??= moorRuntimeOptions.defaultSerializer; @@ -299,6 +327,22 @@ class ClientsCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('ClientsCompanion(') + ..write('clientId: $clientId, ') + ..write('name: $name, ') + ..write('homeserverUrl: $homeserverUrl, ') + ..write('token: $token, ') + ..write('userId: $userId, ') + ..write('deviceId: $deviceId, ') + ..write('deviceName: $deviceName, ') + ..write('prevBatch: $prevBatch, ') + ..write('olmAccount: $olmAccount') + ..write(')')) + .toString(); + } } class Clients extends Table with TableInfo { @@ -513,6 +557,19 @@ class DbUserDeviceKey extends DataClass implements Insertable { return map; } + UserDeviceKeysCompanion toCompanion(bool nullToAbsent) { + return UserDeviceKeysCompanion( + clientId: clientId == null && nullToAbsent + ? const Value.absent() + : Value(clientId), + userId: + userId == null && nullToAbsent ? const Value.absent() : Value(userId), + outdated: outdated == null && nullToAbsent + ? const Value.absent() + : Value(outdated), + ); + } + factory DbUserDeviceKey.fromJson(Map json, {ValueSerializer serializer}) { serializer ??= moorRuntimeOptions.defaultSerializer; @@ -610,6 +667,16 @@ class UserDeviceKeysCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('UserDeviceKeysCompanion(') + ..write('clientId: $clientId, ') + ..write('userId: $userId, ') + ..write('outdated: $outdated') + ..write(')')) + .toString(); + } } class UserDeviceKeys extends Table @@ -754,6 +821,28 @@ class DbUserDeviceKeysKey extends DataClass return map; } + UserDeviceKeysKeyCompanion toCompanion(bool nullToAbsent) { + return UserDeviceKeysKeyCompanion( + clientId: clientId == null && nullToAbsent + ? const Value.absent() + : Value(clientId), + userId: + userId == null && nullToAbsent ? const Value.absent() : Value(userId), + deviceId: deviceId == null && nullToAbsent + ? const Value.absent() + : Value(deviceId), + content: content == null && nullToAbsent + ? const Value.absent() + : Value(content), + verified: verified == null && nullToAbsent + ? const Value.absent() + : Value(verified), + blocked: blocked == null && nullToAbsent + ? const Value.absent() + : Value(blocked), + ); + } + factory DbUserDeviceKeysKey.fromJson(Map json, {ValueSerializer serializer}) { serializer ??= moorRuntimeOptions.defaultSerializer; @@ -912,6 +1001,19 @@ class UserDeviceKeysKeyCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('UserDeviceKeysKeyCompanion(') + ..write('clientId: $clientId, ') + ..write('userId: $userId, ') + ..write('deviceId: $deviceId, ') + ..write('content: $content, ') + ..write('verified: $verified, ') + ..write('blocked: $blocked') + ..write(')')) + .toString(); + } } class UserDeviceKeysKey extends Table @@ -1100,6 +1202,28 @@ class DbUserCrossSigningKey extends DataClass return map; } + UserCrossSigningKeysCompanion toCompanion(bool nullToAbsent) { + return UserCrossSigningKeysCompanion( + clientId: clientId == null && nullToAbsent + ? const Value.absent() + : Value(clientId), + userId: + userId == null && nullToAbsent ? const Value.absent() : Value(userId), + publicKey: publicKey == null && nullToAbsent + ? const Value.absent() + : Value(publicKey), + content: content == null && nullToAbsent + ? const Value.absent() + : Value(content), + verified: verified == null && nullToAbsent + ? const Value.absent() + : Value(verified), + blocked: blocked == null && nullToAbsent + ? const Value.absent() + : Value(blocked), + ); + } + factory DbUserCrossSigningKey.fromJson(Map json, {ValueSerializer serializer}) { serializer ??= moorRuntimeOptions.defaultSerializer; @@ -1259,6 +1383,19 @@ class UserCrossSigningKeysCompanion } return map; } + + @override + String toString() { + return (StringBuffer('UserCrossSigningKeysCompanion(') + ..write('clientId: $clientId, ') + ..write('userId: $userId, ') + ..write('publicKey: $publicKey, ') + ..write('content: $content, ') + ..write('verified: $verified, ') + ..write('blocked: $blocked') + ..write(')')) + .toString(); + } } class UserCrossSigningKeys extends Table @@ -1391,7 +1528,7 @@ class DbOlmSessions extends DataClass implements Insertable { final String identityKey; final String sessionId; final String pickle; - final DateTime lastReceived; + final int lastReceived; DbOlmSessions( {@required this.clientId, @required this.identityKey, @@ -1404,7 +1541,6 @@ class DbOlmSessions extends DataClass implements Insertable { final effectivePrefix = prefix ?? ''; final intType = db.typeSystem.forDartType(); final stringType = db.typeSystem.forDartType(); - final dateTimeType = db.typeSystem.forDartType(); return DbOlmSessions( clientId: intType.mapFromDatabaseResponse(data['${effectivePrefix}client_id']), @@ -1414,7 +1550,7 @@ class DbOlmSessions extends DataClass implements Insertable { .mapFromDatabaseResponse(data['${effectivePrefix}session_id']), pickle: stringType.mapFromDatabaseResponse(data['${effectivePrefix}pickle']), - lastReceived: dateTimeType + lastReceived: intType .mapFromDatabaseResponse(data['${effectivePrefix}last_received']), ); } @@ -1434,11 +1570,30 @@ class DbOlmSessions extends DataClass implements Insertable { map['pickle'] = Variable(pickle); } if (!nullToAbsent || lastReceived != null) { - map['last_received'] = Variable(lastReceived); + map['last_received'] = Variable(lastReceived); } return map; } + OlmSessionsCompanion toCompanion(bool nullToAbsent) { + return OlmSessionsCompanion( + clientId: clientId == null && nullToAbsent + ? const Value.absent() + : Value(clientId), + identityKey: identityKey == null && nullToAbsent + ? const Value.absent() + : Value(identityKey), + sessionId: sessionId == null && nullToAbsent + ? const Value.absent() + : Value(sessionId), + pickle: + pickle == null && nullToAbsent ? const Value.absent() : Value(pickle), + lastReceived: lastReceived == null && nullToAbsent + ? const Value.absent() + : Value(lastReceived), + ); + } + factory DbOlmSessions.fromJson(Map json, {ValueSerializer serializer}) { serializer ??= moorRuntimeOptions.defaultSerializer; @@ -1447,7 +1602,7 @@ class DbOlmSessions extends DataClass implements Insertable { identityKey: serializer.fromJson(json['identity_key']), sessionId: serializer.fromJson(json['session_id']), pickle: serializer.fromJson(json['pickle']), - lastReceived: serializer.fromJson(json['last_received']), + lastReceived: serializer.fromJson(json['last_received']), ); } @override @@ -1458,7 +1613,7 @@ class DbOlmSessions extends DataClass implements Insertable { 'identity_key': serializer.toJson(identityKey), 'session_id': serializer.toJson(sessionId), 'pickle': serializer.toJson(pickle), - 'last_received': serializer.toJson(lastReceived), + 'last_received': serializer.toJson(lastReceived), }; } @@ -1467,7 +1622,7 @@ class DbOlmSessions extends DataClass implements Insertable { String identityKey, String sessionId, String pickle, - DateTime lastReceived}) => + int lastReceived}) => DbOlmSessions( clientId: clientId ?? this.clientId, identityKey: identityKey ?? this.identityKey, @@ -1510,7 +1665,7 @@ class OlmSessionsCompanion extends UpdateCompanion { final Value identityKey; final Value sessionId; final Value pickle; - final Value lastReceived; + final Value lastReceived; const OlmSessionsCompanion({ this.clientId = const Value.absent(), this.identityKey = const Value.absent(), @@ -1533,7 +1688,7 @@ class OlmSessionsCompanion extends UpdateCompanion { Expression identityKey, Expression sessionId, Expression pickle, - Expression lastReceived, + Expression lastReceived, }) { return RawValuesInsertable({ if (clientId != null) 'client_id': clientId, @@ -1549,7 +1704,7 @@ class OlmSessionsCompanion extends UpdateCompanion { Value identityKey, Value sessionId, Value pickle, - Value lastReceived}) { + Value lastReceived}) { return OlmSessionsCompanion( clientId: clientId ?? this.clientId, identityKey: identityKey ?? this.identityKey, @@ -1575,10 +1730,22 @@ class OlmSessionsCompanion extends UpdateCompanion { map['pickle'] = Variable(pickle.value); } if (lastReceived.present) { - map['last_received'] = Variable(lastReceived.value); + map['last_received'] = Variable(lastReceived.value); } return map; } + + @override + String toString() { + return (StringBuffer('OlmSessionsCompanion(') + ..write('clientId: $clientId, ') + ..write('identityKey: $identityKey, ') + ..write('sessionId: $sessionId, ') + ..write('pickle: $pickle, ') + ..write('lastReceived: $lastReceived') + ..write(')')) + .toString(); + } } class OlmSessions extends Table with TableInfo { @@ -1621,11 +1788,11 @@ class OlmSessions extends Table with TableInfo { final VerificationMeta _lastReceivedMeta = const VerificationMeta('lastReceived'); - GeneratedDateTimeColumn _lastReceived; - GeneratedDateTimeColumn get lastReceived => + GeneratedIntColumn _lastReceived; + GeneratedIntColumn get lastReceived => _lastReceived ??= _constructLastReceived(); - GeneratedDateTimeColumn _constructLastReceived() { - return GeneratedDateTimeColumn('last_received', $tableName, true, + GeneratedIntColumn _constructLastReceived() { + return GeneratedIntColumn('last_received', $tableName, true, $customConstraints: ''); } @@ -1704,7 +1871,7 @@ class DbOutboundGroupSession extends DataClass final String roomId; final String pickle; final String deviceIds; - final DateTime creationTime; + final int creationTime; final int sentMessages; DbOutboundGroupSession( {@required this.clientId, @@ -1719,7 +1886,6 @@ class DbOutboundGroupSession extends DataClass final effectivePrefix = prefix ?? ''; final intType = db.typeSystem.forDartType(); final stringType = db.typeSystem.forDartType(); - final dateTimeType = db.typeSystem.forDartType(); return DbOutboundGroupSession( clientId: intType.mapFromDatabaseResponse(data['${effectivePrefix}client_id']), @@ -1729,7 +1895,7 @@ class DbOutboundGroupSession extends DataClass stringType.mapFromDatabaseResponse(data['${effectivePrefix}pickle']), deviceIds: stringType .mapFromDatabaseResponse(data['${effectivePrefix}device_ids']), - creationTime: dateTimeType + creationTime: intType .mapFromDatabaseResponse(data['${effectivePrefix}creation_time']), sentMessages: intType .mapFromDatabaseResponse(data['${effectivePrefix}sent_messages']), @@ -1751,7 +1917,7 @@ class DbOutboundGroupSession extends DataClass map['device_ids'] = Variable(deviceIds); } if (!nullToAbsent || creationTime != null) { - map['creation_time'] = Variable(creationTime); + map['creation_time'] = Variable(creationTime); } if (!nullToAbsent || sentMessages != null) { map['sent_messages'] = Variable(sentMessages); @@ -1759,6 +1925,27 @@ class DbOutboundGroupSession extends DataClass return map; } + OutboundGroupSessionsCompanion toCompanion(bool nullToAbsent) { + return OutboundGroupSessionsCompanion( + clientId: clientId == null && nullToAbsent + ? const Value.absent() + : Value(clientId), + roomId: + roomId == null && nullToAbsent ? const Value.absent() : Value(roomId), + pickle: + pickle == null && nullToAbsent ? const Value.absent() : Value(pickle), + deviceIds: deviceIds == null && nullToAbsent + ? const Value.absent() + : Value(deviceIds), + creationTime: creationTime == null && nullToAbsent + ? const Value.absent() + : Value(creationTime), + sentMessages: sentMessages == null && nullToAbsent + ? const Value.absent() + : Value(sentMessages), + ); + } + factory DbOutboundGroupSession.fromJson(Map json, {ValueSerializer serializer}) { serializer ??= moorRuntimeOptions.defaultSerializer; @@ -1767,7 +1954,7 @@ class DbOutboundGroupSession extends DataClass roomId: serializer.fromJson(json['room_id']), pickle: serializer.fromJson(json['pickle']), deviceIds: serializer.fromJson(json['device_ids']), - creationTime: serializer.fromJson(json['creation_time']), + creationTime: serializer.fromJson(json['creation_time']), sentMessages: serializer.fromJson(json['sent_messages']), ); } @@ -1779,7 +1966,7 @@ class DbOutboundGroupSession extends DataClass 'room_id': serializer.toJson(roomId), 'pickle': serializer.toJson(pickle), 'device_ids': serializer.toJson(deviceIds), - 'creation_time': serializer.toJson(creationTime), + 'creation_time': serializer.toJson(creationTime), 'sent_messages': serializer.toJson(sentMessages), }; } @@ -1789,7 +1976,7 @@ class DbOutboundGroupSession extends DataClass String roomId, String pickle, String deviceIds, - DateTime creationTime, + int creationTime, int sentMessages}) => DbOutboundGroupSession( clientId: clientId ?? this.clientId, @@ -1839,7 +2026,7 @@ class OutboundGroupSessionsCompanion final Value roomId; final Value pickle; final Value deviceIds; - final Value creationTime; + final Value creationTime; final Value sentMessages; const OutboundGroupSessionsCompanion({ this.clientId = const Value.absent(), @@ -1854,7 +2041,7 @@ class OutboundGroupSessionsCompanion @required String roomId, @required String pickle, @required String deviceIds, - @required DateTime creationTime, + @required int creationTime, this.sentMessages = const Value.absent(), }) : clientId = Value(clientId), roomId = Value(roomId), @@ -1866,7 +2053,7 @@ class OutboundGroupSessionsCompanion Expression roomId, Expression pickle, Expression deviceIds, - Expression creationTime, + Expression creationTime, Expression sentMessages, }) { return RawValuesInsertable({ @@ -1884,7 +2071,7 @@ class OutboundGroupSessionsCompanion Value roomId, Value pickle, Value deviceIds, - Value creationTime, + Value creationTime, Value sentMessages}) { return OutboundGroupSessionsCompanion( clientId: clientId ?? this.clientId, @@ -1912,13 +2099,26 @@ class OutboundGroupSessionsCompanion map['device_ids'] = Variable(deviceIds.value); } if (creationTime.present) { - map['creation_time'] = Variable(creationTime.value); + map['creation_time'] = Variable(creationTime.value); } if (sentMessages.present) { map['sent_messages'] = Variable(sentMessages.value); } return map; } + + @override + String toString() { + return (StringBuffer('OutboundGroupSessionsCompanion(') + ..write('clientId: $clientId, ') + ..write('roomId: $roomId, ') + ..write('pickle: $pickle, ') + ..write('deviceIds: $deviceIds, ') + ..write('creationTime: $creationTime, ') + ..write('sentMessages: $sentMessages') + ..write(')')) + .toString(); + } } class OutboundGroupSessions extends Table @@ -1960,11 +2160,11 @@ class OutboundGroupSessions extends Table final VerificationMeta _creationTimeMeta = const VerificationMeta('creationTime'); - GeneratedDateTimeColumn _creationTime; - GeneratedDateTimeColumn get creationTime => + GeneratedIntColumn _creationTime; + GeneratedIntColumn get creationTime => _creationTime ??= _constructCreationTime(); - GeneratedDateTimeColumn _constructCreationTime() { - return GeneratedDateTimeColumn('creation_time', $tableName, false, + GeneratedIntColumn _constructCreationTime() { + return GeneratedIntColumn('creation_time', $tableName, false, $customConstraints: 'NOT NULL'); } @@ -2136,6 +2336,36 @@ class DbInboundGroupSession extends DataClass return map; } + InboundGroupSessionsCompanion toCompanion(bool nullToAbsent) { + return InboundGroupSessionsCompanion( + clientId: clientId == null && nullToAbsent + ? const Value.absent() + : Value(clientId), + roomId: + roomId == null && nullToAbsent ? const Value.absent() : Value(roomId), + sessionId: sessionId == null && nullToAbsent + ? const Value.absent() + : Value(sessionId), + pickle: + pickle == null && nullToAbsent ? const Value.absent() : Value(pickle), + content: content == null && nullToAbsent + ? const Value.absent() + : Value(content), + indexes: indexes == null && nullToAbsent + ? const Value.absent() + : Value(indexes), + uploaded: uploaded == null && nullToAbsent + ? const Value.absent() + : Value(uploaded), + senderKey: senderKey == null && nullToAbsent + ? const Value.absent() + : Value(senderKey), + senderClaimedKeys: senderClaimedKeys == null && nullToAbsent + ? const Value.absent() + : Value(senderClaimedKeys), + ); + } + factory DbInboundGroupSession.fromJson(Map json, {ValueSerializer serializer}) { serializer ??= moorRuntimeOptions.defaultSerializer; @@ -2352,6 +2582,22 @@ class InboundGroupSessionsCompanion } return map; } + + @override + String toString() { + return (StringBuffer('InboundGroupSessionsCompanion(') + ..write('clientId: $clientId, ') + ..write('roomId: $roomId, ') + ..write('sessionId: $sessionId, ') + ..write('pickle: $pickle, ') + ..write('content: $content, ') + ..write('indexes: $indexes, ') + ..write('uploaded: $uploaded, ') + ..write('senderKey: $senderKey, ') + ..write('senderClaimedKeys: $senderClaimedKeys') + ..write(')')) + .toString(); + } } class InboundGroupSessions extends Table @@ -2621,6 +2867,42 @@ class DbRoom extends DataClass implements Insertable { return map; } + RoomsCompanion toCompanion(bool nullToAbsent) { + return RoomsCompanion( + clientId: clientId == null && nullToAbsent + ? const Value.absent() + : Value(clientId), + roomId: + roomId == null && nullToAbsent ? const Value.absent() : Value(roomId), + membership: membership == null && nullToAbsent + ? const Value.absent() + : Value(membership), + highlightCount: highlightCount == null && nullToAbsent + ? const Value.absent() + : Value(highlightCount), + notificationCount: notificationCount == null && nullToAbsent + ? const Value.absent() + : Value(notificationCount), + prevBatch: prevBatch == null && nullToAbsent + ? const Value.absent() + : Value(prevBatch), + joinedMemberCount: joinedMemberCount == null && nullToAbsent + ? const Value.absent() + : Value(joinedMemberCount), + invitedMemberCount: invitedMemberCount == null && nullToAbsent + ? const Value.absent() + : Value(invitedMemberCount), + newestSortOrder: newestSortOrder == null && nullToAbsent + ? const Value.absent() + : Value(newestSortOrder), + oldestSortOrder: oldestSortOrder == null && nullToAbsent + ? const Value.absent() + : Value(oldestSortOrder), + heroes: + heroes == null && nullToAbsent ? const Value.absent() : Value(heroes), + ); + } + factory DbRoom.fromJson(Map json, {ValueSerializer serializer}) { serializer ??= moorRuntimeOptions.defaultSerializer; @@ -2872,6 +3154,24 @@ class RoomsCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('RoomsCompanion(') + ..write('clientId: $clientId, ') + ..write('roomId: $roomId, ') + ..write('membership: $membership, ') + ..write('highlightCount: $highlightCount, ') + ..write('notificationCount: $notificationCount, ') + ..write('prevBatch: $prevBatch, ') + ..write('joinedMemberCount: $joinedMemberCount, ') + ..write('invitedMemberCount: $invitedMemberCount, ') + ..write('newestSortOrder: $newestSortOrder, ') + ..write('oldestSortOrder: $oldestSortOrder, ') + ..write('heroes: $heroes') + ..write(')')) + .toString(); + } } class Rooms extends Table with TableInfo { @@ -3102,7 +3402,7 @@ class DbEvent extends DataClass implements Insertable { final String eventId; final String roomId; final double sortOrder; - final DateTime originServerTs; + final int originServerTs; final String sender; final String type; final String unsigned; @@ -3129,7 +3429,6 @@ class DbEvent extends DataClass implements Insertable { final intType = db.typeSystem.forDartType(); final stringType = db.typeSystem.forDartType(); final doubleType = db.typeSystem.forDartType(); - final dateTimeType = db.typeSystem.forDartType(); return DbEvent( clientId: intType.mapFromDatabaseResponse(data['${effectivePrefix}client_id']), @@ -3139,7 +3438,7 @@ class DbEvent extends DataClass implements Insertable { stringType.mapFromDatabaseResponse(data['${effectivePrefix}room_id']), sortOrder: doubleType .mapFromDatabaseResponse(data['${effectivePrefix}sort_order']), - originServerTs: dateTimeType + originServerTs: intType .mapFromDatabaseResponse(data['${effectivePrefix}origin_server_ts']), sender: stringType.mapFromDatabaseResponse(data['${effectivePrefix}sender']), @@ -3171,7 +3470,7 @@ class DbEvent extends DataClass implements Insertable { map['sort_order'] = Variable(sortOrder); } if (!nullToAbsent || originServerTs != null) { - map['origin_server_ts'] = Variable(originServerTs); + map['origin_server_ts'] = Variable(originServerTs); } if (!nullToAbsent || sender != null) { map['sender'] = Variable(sender); @@ -3197,6 +3496,42 @@ class DbEvent extends DataClass implements Insertable { return map; } + EventsCompanion toCompanion(bool nullToAbsent) { + return EventsCompanion( + clientId: clientId == null && nullToAbsent + ? const Value.absent() + : Value(clientId), + eventId: eventId == null && nullToAbsent + ? const Value.absent() + : Value(eventId), + roomId: + roomId == null && nullToAbsent ? const Value.absent() : Value(roomId), + sortOrder: sortOrder == null && nullToAbsent + ? const Value.absent() + : Value(sortOrder), + originServerTs: originServerTs == null && nullToAbsent + ? const Value.absent() + : Value(originServerTs), + sender: + sender == null && nullToAbsent ? const Value.absent() : Value(sender), + type: type == null && nullToAbsent ? const Value.absent() : Value(type), + unsigned: unsigned == null && nullToAbsent + ? const Value.absent() + : Value(unsigned), + content: content == null && nullToAbsent + ? const Value.absent() + : Value(content), + prevContent: prevContent == null && nullToAbsent + ? const Value.absent() + : Value(prevContent), + stateKey: stateKey == null && nullToAbsent + ? const Value.absent() + : Value(stateKey), + status: + status == null && nullToAbsent ? const Value.absent() : Value(status), + ); + } + factory DbEvent.fromJson(Map json, {ValueSerializer serializer}) { serializer ??= moorRuntimeOptions.defaultSerializer; @@ -3205,7 +3540,7 @@ class DbEvent extends DataClass implements Insertable { eventId: serializer.fromJson(json['event_id']), roomId: serializer.fromJson(json['room_id']), sortOrder: serializer.fromJson(json['sort_order']), - originServerTs: serializer.fromJson(json['origin_server_ts']), + originServerTs: serializer.fromJson(json['origin_server_ts']), sender: serializer.fromJson(json['sender']), type: serializer.fromJson(json['type']), unsigned: serializer.fromJson(json['unsigned']), @@ -3223,7 +3558,7 @@ class DbEvent extends DataClass implements Insertable { 'event_id': serializer.toJson(eventId), 'room_id': serializer.toJson(roomId), 'sort_order': serializer.toJson(sortOrder), - 'origin_server_ts': serializer.toJson(originServerTs), + 'origin_server_ts': serializer.toJson(originServerTs), 'sender': serializer.toJson(sender), 'type': serializer.toJson(type), 'unsigned': serializer.toJson(unsigned), @@ -3239,7 +3574,7 @@ class DbEvent extends DataClass implements Insertable { String eventId, String roomId, double sortOrder, - DateTime originServerTs, + int originServerTs, String sender, String type, String unsigned, @@ -3326,7 +3661,7 @@ class EventsCompanion extends UpdateCompanion { final Value eventId; final Value roomId; final Value sortOrder; - final Value originServerTs; + final Value originServerTs; final Value sender; final Value type; final Value unsigned; @@ -3353,7 +3688,7 @@ class EventsCompanion extends UpdateCompanion { @required String eventId, @required String roomId, @required double sortOrder, - @required DateTime originServerTs, + @required int originServerTs, @required String sender, @required String type, this.unsigned = const Value.absent(), @@ -3373,7 +3708,7 @@ class EventsCompanion extends UpdateCompanion { Expression eventId, Expression roomId, Expression sortOrder, - Expression originServerTs, + Expression originServerTs, Expression sender, Expression type, Expression unsigned, @@ -3403,7 +3738,7 @@ class EventsCompanion extends UpdateCompanion { Value eventId, Value roomId, Value sortOrder, - Value originServerTs, + Value originServerTs, Value sender, Value type, Value unsigned, @@ -3443,7 +3778,7 @@ class EventsCompanion extends UpdateCompanion { map['sort_order'] = Variable(sortOrder.value); } if (originServerTs.present) { - map['origin_server_ts'] = Variable(originServerTs.value); + map['origin_server_ts'] = Variable(originServerTs.value); } if (sender.present) { map['sender'] = Variable(sender.value); @@ -3468,6 +3803,25 @@ class EventsCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('EventsCompanion(') + ..write('clientId: $clientId, ') + ..write('eventId: $eventId, ') + ..write('roomId: $roomId, ') + ..write('sortOrder: $sortOrder, ') + ..write('originServerTs: $originServerTs, ') + ..write('sender: $sender, ') + ..write('type: $type, ') + ..write('unsigned: $unsigned, ') + ..write('content: $content, ') + ..write('prevContent: $prevContent, ') + ..write('stateKey: $stateKey, ') + ..write('status: $status') + ..write(')')) + .toString(); + } } class Events extends Table with TableInfo { @@ -3508,11 +3862,11 @@ class Events extends Table with TableInfo { final VerificationMeta _originServerTsMeta = const VerificationMeta('originServerTs'); - GeneratedDateTimeColumn _originServerTs; - GeneratedDateTimeColumn get originServerTs => + GeneratedIntColumn _originServerTs; + GeneratedIntColumn get originServerTs => _originServerTs ??= _constructOriginServerTs(); - GeneratedDateTimeColumn _constructOriginServerTs() { - return GeneratedDateTimeColumn('origin_server_ts', $tableName, false, + GeneratedIntColumn _constructOriginServerTs() { + return GeneratedIntColumn('origin_server_ts', $tableName, false, $customConstraints: 'NOT NULL'); } @@ -3694,7 +4048,7 @@ class DbRoomState extends DataClass implements Insertable { final String eventId; final String roomId; final double sortOrder; - final DateTime originServerTs; + final int originServerTs; final String sender; final String type; final String unsigned; @@ -3719,7 +4073,6 @@ class DbRoomState extends DataClass implements Insertable { final intType = db.typeSystem.forDartType(); final stringType = db.typeSystem.forDartType(); final doubleType = db.typeSystem.forDartType(); - final dateTimeType = db.typeSystem.forDartType(); return DbRoomState( clientId: intType.mapFromDatabaseResponse(data['${effectivePrefix}client_id']), @@ -3729,7 +4082,7 @@ class DbRoomState extends DataClass implements Insertable { stringType.mapFromDatabaseResponse(data['${effectivePrefix}room_id']), sortOrder: doubleType .mapFromDatabaseResponse(data['${effectivePrefix}sort_order']), - originServerTs: dateTimeType + originServerTs: intType .mapFromDatabaseResponse(data['${effectivePrefix}origin_server_ts']), sender: stringType.mapFromDatabaseResponse(data['${effectivePrefix}sender']), @@ -3760,7 +4113,7 @@ class DbRoomState extends DataClass implements Insertable { map['sort_order'] = Variable(sortOrder); } if (!nullToAbsent || originServerTs != null) { - map['origin_server_ts'] = Variable(originServerTs); + map['origin_server_ts'] = Variable(originServerTs); } if (!nullToAbsent || sender != null) { map['sender'] = Variable(sender); @@ -3783,6 +4136,40 @@ class DbRoomState extends DataClass implements Insertable { return map; } + RoomStatesCompanion toCompanion(bool nullToAbsent) { + return RoomStatesCompanion( + clientId: clientId == null && nullToAbsent + ? const Value.absent() + : Value(clientId), + eventId: eventId == null && nullToAbsent + ? const Value.absent() + : Value(eventId), + roomId: + roomId == null && nullToAbsent ? const Value.absent() : Value(roomId), + sortOrder: sortOrder == null && nullToAbsent + ? const Value.absent() + : Value(sortOrder), + originServerTs: originServerTs == null && nullToAbsent + ? const Value.absent() + : Value(originServerTs), + sender: + sender == null && nullToAbsent ? const Value.absent() : Value(sender), + type: type == null && nullToAbsent ? const Value.absent() : Value(type), + unsigned: unsigned == null && nullToAbsent + ? const Value.absent() + : Value(unsigned), + content: content == null && nullToAbsent + ? const Value.absent() + : Value(content), + prevContent: prevContent == null && nullToAbsent + ? const Value.absent() + : Value(prevContent), + stateKey: stateKey == null && nullToAbsent + ? const Value.absent() + : Value(stateKey), + ); + } + factory DbRoomState.fromJson(Map json, {ValueSerializer serializer}) { serializer ??= moorRuntimeOptions.defaultSerializer; @@ -3791,7 +4178,7 @@ class DbRoomState extends DataClass implements Insertable { eventId: serializer.fromJson(json['event_id']), roomId: serializer.fromJson(json['room_id']), sortOrder: serializer.fromJson(json['sort_order']), - originServerTs: serializer.fromJson(json['origin_server_ts']), + originServerTs: serializer.fromJson(json['origin_server_ts']), sender: serializer.fromJson(json['sender']), type: serializer.fromJson(json['type']), unsigned: serializer.fromJson(json['unsigned']), @@ -3808,7 +4195,7 @@ class DbRoomState extends DataClass implements Insertable { 'event_id': serializer.toJson(eventId), 'room_id': serializer.toJson(roomId), 'sort_order': serializer.toJson(sortOrder), - 'origin_server_ts': serializer.toJson(originServerTs), + 'origin_server_ts': serializer.toJson(originServerTs), 'sender': serializer.toJson(sender), 'type': serializer.toJson(type), 'unsigned': serializer.toJson(unsigned), @@ -3823,7 +4210,7 @@ class DbRoomState extends DataClass implements Insertable { String eventId, String roomId, double sortOrder, - DateTime originServerTs, + int originServerTs, String sender, String type, String unsigned, @@ -3904,7 +4291,7 @@ class RoomStatesCompanion extends UpdateCompanion { final Value eventId; final Value roomId; final Value sortOrder; - final Value originServerTs; + final Value originServerTs; final Value sender; final Value type; final Value unsigned; @@ -3929,7 +4316,7 @@ class RoomStatesCompanion extends UpdateCompanion { @required String eventId, @required String roomId, @required double sortOrder, - @required DateTime originServerTs, + @required int originServerTs, @required String sender, @required String type, this.unsigned = const Value.absent(), @@ -3949,7 +4336,7 @@ class RoomStatesCompanion extends UpdateCompanion { Expression eventId, Expression roomId, Expression sortOrder, - Expression originServerTs, + Expression originServerTs, Expression sender, Expression type, Expression unsigned, @@ -3977,7 +4364,7 @@ class RoomStatesCompanion extends UpdateCompanion { Value eventId, Value roomId, Value sortOrder, - Value originServerTs, + Value originServerTs, Value sender, Value type, Value unsigned, @@ -4015,7 +4402,7 @@ class RoomStatesCompanion extends UpdateCompanion { map['sort_order'] = Variable(sortOrder.value); } if (originServerTs.present) { - map['origin_server_ts'] = Variable(originServerTs.value); + map['origin_server_ts'] = Variable(originServerTs.value); } if (sender.present) { map['sender'] = Variable(sender.value); @@ -4037,6 +4424,24 @@ class RoomStatesCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('RoomStatesCompanion(') + ..write('clientId: $clientId, ') + ..write('eventId: $eventId, ') + ..write('roomId: $roomId, ') + ..write('sortOrder: $sortOrder, ') + ..write('originServerTs: $originServerTs, ') + ..write('sender: $sender, ') + ..write('type: $type, ') + ..write('unsigned: $unsigned, ') + ..write('content: $content, ') + ..write('prevContent: $prevContent, ') + ..write('stateKey: $stateKey') + ..write(')')) + .toString(); + } } class RoomStates extends Table with TableInfo { @@ -4077,11 +4482,11 @@ class RoomStates extends Table with TableInfo { final VerificationMeta _originServerTsMeta = const VerificationMeta('originServerTs'); - GeneratedDateTimeColumn _originServerTs; - GeneratedDateTimeColumn get originServerTs => + GeneratedIntColumn _originServerTs; + GeneratedIntColumn get originServerTs => _originServerTs ??= _constructOriginServerTs(); - GeneratedDateTimeColumn _constructOriginServerTs() { - return GeneratedDateTimeColumn('origin_server_ts', $tableName, false, + GeneratedIntColumn _constructOriginServerTs() { + return GeneratedIntColumn('origin_server_ts', $tableName, false, $customConstraints: 'NOT NULL'); } @@ -4283,6 +4688,18 @@ class DbAccountData extends DataClass implements Insertable { return map; } + AccountDataCompanion toCompanion(bool nullToAbsent) { + return AccountDataCompanion( + clientId: clientId == null && nullToAbsent + ? const Value.absent() + : Value(clientId), + type: type == null && nullToAbsent ? const Value.absent() : Value(type), + content: content == null && nullToAbsent + ? const Value.absent() + : Value(content), + ); + } + factory DbAccountData.fromJson(Map json, {ValueSerializer serializer}) { serializer ??= moorRuntimeOptions.defaultSerializer; @@ -4380,6 +4797,16 @@ class AccountDataCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('AccountDataCompanion(') + ..write('clientId: $clientId, ') + ..write('type: $type, ') + ..write('content: $content') + ..write(')')) + .toString(); + } } class AccountData extends Table with TableInfo { @@ -4506,6 +4933,20 @@ class DbRoomAccountData extends DataClass return map; } + RoomAccountDataCompanion toCompanion(bool nullToAbsent) { + return RoomAccountDataCompanion( + clientId: clientId == null && nullToAbsent + ? const Value.absent() + : Value(clientId), + type: type == null && nullToAbsent ? const Value.absent() : Value(type), + roomId: + roomId == null && nullToAbsent ? const Value.absent() : Value(roomId), + content: content == null && nullToAbsent + ? const Value.absent() + : Value(content), + ); + } + factory DbRoomAccountData.fromJson(Map json, {ValueSerializer serializer}) { serializer ??= moorRuntimeOptions.defaultSerializer; @@ -4622,6 +5063,17 @@ class RoomAccountDataCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('RoomAccountDataCompanion(') + ..write('clientId: $clientId, ') + ..write('type: $type, ') + ..write('roomId: $roomId, ') + ..write('content: $content') + ..write(')')) + .toString(); + } } class RoomAccountData extends Table @@ -4762,6 +5214,20 @@ class DbPresence extends DataClass implements Insertable { return map; } + PresencesCompanion toCompanion(bool nullToAbsent) { + return PresencesCompanion( + clientId: clientId == null && nullToAbsent + ? const Value.absent() + : Value(clientId), + type: type == null && nullToAbsent ? const Value.absent() : Value(type), + sender: + sender == null && nullToAbsent ? const Value.absent() : Value(sender), + content: content == null && nullToAbsent + ? const Value.absent() + : Value(content), + ); + } + factory DbPresence.fromJson(Map json, {ValueSerializer serializer}) { serializer ??= moorRuntimeOptions.defaultSerializer; @@ -4878,6 +5344,17 @@ class PresencesCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('PresencesCompanion(') + ..write('clientId: $clientId, ') + ..write('type: $type, ') + ..write('sender: $sender, ') + ..write('content: $content') + ..write(')')) + .toString(); + } } class Presences extends Table with TableInfo { @@ -5024,6 +5501,23 @@ class DbSSSSCache extends DataClass implements Insertable { return map; } + SsssCacheCompanion toCompanion(bool nullToAbsent) { + return SsssCacheCompanion( + clientId: clientId == null && nullToAbsent + ? const Value.absent() + : Value(clientId), + type: type == null && nullToAbsent ? const Value.absent() : Value(type), + keyId: + keyId == null && nullToAbsent ? const Value.absent() : Value(keyId), + ciphertext: ciphertext == null && nullToAbsent + ? const Value.absent() + : Value(ciphertext), + content: content == null && nullToAbsent + ? const Value.absent() + : Value(content), + ); + } + factory DbSSSSCache.fromJson(Map json, {ValueSerializer serializer}) { serializer ??= moorRuntimeOptions.defaultSerializer; @@ -5165,6 +5659,18 @@ class SsssCacheCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('SsssCacheCompanion(') + ..write('clientId: $clientId, ') + ..write('type: $type, ') + ..write('keyId: $keyId, ') + ..write('ciphertext: $ciphertext, ') + ..write('content: $content') + ..write(')')) + .toString(); + } } class SsssCache extends Table with TableInfo { @@ -5282,21 +5788,21 @@ class SsssCache extends Table with TableInfo { class DbFile extends DataClass implements Insertable { final String mxcUri; final Uint8List bytes; - final DateTime savedAt; + final int savedAt; DbFile({@required this.mxcUri, this.bytes, this.savedAt}); factory DbFile.fromData(Map data, GeneratedDatabase db, {String prefix}) { final effectivePrefix = prefix ?? ''; final stringType = db.typeSystem.forDartType(); final uint8ListType = db.typeSystem.forDartType(); - final dateTimeType = db.typeSystem.forDartType(); + final intType = db.typeSystem.forDartType(); return DbFile( mxcUri: stringType.mapFromDatabaseResponse(data['${effectivePrefix}mxc_uri']), bytes: uint8ListType .mapFromDatabaseResponse(data['${effectivePrefix}bytes']), - savedAt: dateTimeType - .mapFromDatabaseResponse(data['${effectivePrefix}saved_at']), + savedAt: + intType.mapFromDatabaseResponse(data['${effectivePrefix}saved_at']), ); } @override @@ -5309,18 +5815,30 @@ class DbFile extends DataClass implements Insertable { map['bytes'] = Variable(bytes); } if (!nullToAbsent || savedAt != null) { - map['saved_at'] = Variable(savedAt); + map['saved_at'] = Variable(savedAt); } return map; } + FilesCompanion toCompanion(bool nullToAbsent) { + return FilesCompanion( + mxcUri: + mxcUri == null && nullToAbsent ? const Value.absent() : Value(mxcUri), + bytes: + bytes == null && nullToAbsent ? const Value.absent() : Value(bytes), + savedAt: savedAt == null && nullToAbsent + ? const Value.absent() + : Value(savedAt), + ); + } + factory DbFile.fromJson(Map json, {ValueSerializer serializer}) { serializer ??= moorRuntimeOptions.defaultSerializer; return DbFile( mxcUri: serializer.fromJson(json['mxc_uri']), bytes: serializer.fromJson(json['bytes']), - savedAt: serializer.fromJson(json['saved_at']), + savedAt: serializer.fromJson(json['saved_at']), ); } @override @@ -5329,11 +5847,11 @@ class DbFile extends DataClass implements Insertable { return { 'mxc_uri': serializer.toJson(mxcUri), 'bytes': serializer.toJson(bytes), - 'saved_at': serializer.toJson(savedAt), + 'saved_at': serializer.toJson(savedAt), }; } - DbFile copyWith({String mxcUri, Uint8List bytes, DateTime savedAt}) => DbFile( + DbFile copyWith({String mxcUri, Uint8List bytes, int savedAt}) => DbFile( mxcUri: mxcUri ?? this.mxcUri, bytes: bytes ?? this.bytes, savedAt: savedAt ?? this.savedAt, @@ -5363,7 +5881,7 @@ class DbFile extends DataClass implements Insertable { class FilesCompanion extends UpdateCompanion { final Value mxcUri; final Value bytes; - final Value savedAt; + final Value savedAt; const FilesCompanion({ this.mxcUri = const Value.absent(), this.bytes = const Value.absent(), @@ -5377,7 +5895,7 @@ class FilesCompanion extends UpdateCompanion { static Insertable custom({ Expression mxcUri, Expression bytes, - Expression savedAt, + Expression savedAt, }) { return RawValuesInsertable({ if (mxcUri != null) 'mxc_uri': mxcUri, @@ -5387,7 +5905,7 @@ class FilesCompanion extends UpdateCompanion { } FilesCompanion copyWith( - {Value mxcUri, Value bytes, Value savedAt}) { + {Value mxcUri, Value bytes, Value savedAt}) { return FilesCompanion( mxcUri: mxcUri ?? this.mxcUri, bytes: bytes ?? this.bytes, @@ -5405,10 +5923,20 @@ class FilesCompanion extends UpdateCompanion { map['bytes'] = Variable(bytes.value); } if (savedAt.present) { - map['saved_at'] = Variable(savedAt.value); + map['saved_at'] = Variable(savedAt.value); } return map; } + + @override + String toString() { + return (StringBuffer('FilesCompanion(') + ..write('mxcUri: $mxcUri, ') + ..write('bytes: $bytes, ') + ..write('savedAt: $savedAt') + ..write(')')) + .toString(); + } } class Files extends Table with TableInfo { @@ -5432,10 +5960,10 @@ class Files extends Table with TableInfo { } final VerificationMeta _savedAtMeta = const VerificationMeta('savedAt'); - GeneratedDateTimeColumn _savedAt; - GeneratedDateTimeColumn get savedAt => _savedAt ??= _constructSavedAt(); - GeneratedDateTimeColumn _constructSavedAt() { - return GeneratedDateTimeColumn('saved_at', $tableName, true, + GeneratedIntColumn _savedAt; + GeneratedIntColumn get savedAt => _savedAt ??= _constructSavedAt(); + GeneratedIntColumn _constructSavedAt() { + return GeneratedIntColumn('saved_at', $tableName, true, $customConstraints: ''); } @@ -5570,24 +6098,10 @@ abstract class _$Database extends GeneratedDatabase { SsssCache get ssssCache => _ssssCache ??= SsssCache(this); Files _files; Files get files => _files ??= Files(this); - DbClient _rowToDbClient(QueryRow row) { - return DbClient( - clientId: row.readInt('client_id'), - name: row.readString('name'), - homeserverUrl: row.readString('homeserver_url'), - token: row.readString('token'), - userId: row.readString('user_id'), - deviceId: row.readString('device_id'), - deviceName: row.readString('device_name'), - prevBatch: row.readString('prev_batch'), - olmAccount: row.readString('olm_account'), - ); - } - Selectable dbGetClient(String name) { return customSelect('SELECT * FROM clients WHERE name = :name', variables: [Variable.withString(name)], - readsFrom: {clients}).map(_rowToDbClient); + readsFrom: {clients}).map(clients.mapFromRow); } Future updateClient( @@ -5637,72 +6151,32 @@ abstract class _$Database extends GeneratedDatabase { ); } - DbUserDeviceKey _rowToDbUserDeviceKey(QueryRow row) { - return DbUserDeviceKey( - clientId: row.readInt('client_id'), - userId: row.readString('user_id'), - outdated: row.readBool('outdated'), - ); - } - Selectable getAllUserDeviceKeys(int client_id) { return customSelect( 'SELECT * FROM user_device_keys WHERE client_id = :client_id', variables: [Variable.withInt(client_id)], - readsFrom: {userDeviceKeys}).map(_rowToDbUserDeviceKey); - } - - DbUserDeviceKeysKey _rowToDbUserDeviceKeysKey(QueryRow row) { - return DbUserDeviceKeysKey( - clientId: row.readInt('client_id'), - userId: row.readString('user_id'), - deviceId: row.readString('device_id'), - content: row.readString('content'), - verified: row.readBool('verified'), - blocked: row.readBool('blocked'), - ); + readsFrom: {userDeviceKeys}).map(userDeviceKeys.mapFromRow); } Selectable getAllUserDeviceKeysKeys(int client_id) { return customSelect( 'SELECT * FROM user_device_keys_key WHERE client_id = :client_id', variables: [Variable.withInt(client_id)], - readsFrom: {userDeviceKeysKey}).map(_rowToDbUserDeviceKeysKey); - } - - DbUserCrossSigningKey _rowToDbUserCrossSigningKey(QueryRow row) { - return DbUserCrossSigningKey( - clientId: row.readInt('client_id'), - userId: row.readString('user_id'), - publicKey: row.readString('public_key'), - content: row.readString('content'), - verified: row.readBool('verified'), - blocked: row.readBool('blocked'), - ); + readsFrom: {userDeviceKeysKey}).map(userDeviceKeysKey.mapFromRow); } Selectable getAllUserCrossSigningKeys(int client_id) { return customSelect( 'SELECT * FROM user_cross_signing_keys WHERE client_id = :client_id', variables: [Variable.withInt(client_id)], - readsFrom: {userCrossSigningKeys}).map(_rowToDbUserCrossSigningKey); - } - - DbOlmSessions _rowToDbOlmSessions(QueryRow row) { - return DbOlmSessions( - clientId: row.readInt('client_id'), - identityKey: row.readString('identity_key'), - sessionId: row.readString('session_id'), - pickle: row.readString('pickle'), - lastReceived: row.readDateTime('last_received'), - ); + readsFrom: {userCrossSigningKeys}).map(userCrossSigningKeys.mapFromRow); } Selectable getAllOlmSessions(int client_id) { return customSelect( 'SELECT * FROM olm_sessions WHERE client_id = :client_id', variables: [Variable.withInt(client_id)], - readsFrom: {olmSessions}).map(_rowToDbOlmSessions); + readsFrom: {olmSessions}).map(olmSessions.mapFromRow); } Selectable dbGetOlmSessions( @@ -5715,11 +6189,11 @@ abstract class _$Database extends GeneratedDatabase { ], readsFrom: { olmSessions - }).map(_rowToDbOlmSessions); + }).map(olmSessions.mapFromRow); } Future storeOlmSession(int client_id, String identitiy_key, - String session_id, String pickle, DateTime last_received) { + String session_id, String pickle, int last_received) { return customInsert( 'INSERT OR REPLACE INTO olm_sessions (client_id, identity_key, session_id, pickle, last_received) VALUES (:client_id, :identitiy_key, :session_id, :pickle, :last_received)', variables: [ @@ -5727,46 +6201,39 @@ abstract class _$Database extends GeneratedDatabase { Variable.withString(identitiy_key), Variable.withString(session_id), Variable.withString(pickle), - Variable.withDateTime(last_received) + Variable.withInt(last_received) ], updates: {olmSessions}, ); } - DbOutboundGroupSession _rowToDbOutboundGroupSession(QueryRow row) { - return DbOutboundGroupSession( - clientId: row.readInt('client_id'), - roomId: row.readString('room_id'), - pickle: row.readString('pickle'), - deviceIds: row.readString('device_ids'), - creationTime: row.readDateTime('creation_time'), - sentMessages: row.readInt('sent_messages'), - ); - } - Selectable getAllOutboundGroupSessions( int client_id) { return customSelect( 'SELECT * FROM outbound_group_sessions WHERE client_id = :client_id', - variables: [Variable.withInt(client_id)], - readsFrom: {outboundGroupSessions}).map(_rowToDbOutboundGroupSession); + variables: [ + Variable.withInt(client_id) + ], + readsFrom: { + outboundGroupSessions + }).map(outboundGroupSessions.mapFromRow); } Selectable dbGetOutboundGroupSession( int client_id, String room_id) { return customSelect( 'SELECT * FROM outbound_group_sessions WHERE client_id = :client_id AND room_id = :room_id', - variables: [Variable.withInt(client_id), Variable.withString(room_id)], - readsFrom: {outboundGroupSessions}).map(_rowToDbOutboundGroupSession); + variables: [ + Variable.withInt(client_id), + Variable.withString(room_id) + ], + readsFrom: { + outboundGroupSessions + }).map(outboundGroupSessions.mapFromRow); } - Future storeOutboundGroupSession( - int client_id, - String room_id, - String pickle, - String device_ids, - DateTime creation_time, - int sent_messages) { + Future storeOutboundGroupSession(int client_id, String room_id, + String pickle, String device_ids, int creation_time, int sent_messages) { return customInsert( 'INSERT OR REPLACE INTO outbound_group_sessions (client_id, room_id, pickle, device_ids, creation_time, sent_messages) VALUES (:client_id, :room_id, :pickle, :device_ids, :creation_time, :sent_messages)', variables: [ @@ -5774,7 +6241,7 @@ abstract class _$Database extends GeneratedDatabase { Variable.withString(room_id), Variable.withString(pickle), Variable.withString(device_ids), - Variable.withDateTime(creation_time), + Variable.withInt(creation_time), Variable.withInt(sent_messages) ], updates: {outboundGroupSessions}, @@ -5790,20 +6257,6 @@ abstract class _$Database extends GeneratedDatabase { ); } - DbInboundGroupSession _rowToDbInboundGroupSession(QueryRow row) { - return DbInboundGroupSession( - clientId: row.readInt('client_id'), - roomId: row.readString('room_id'), - sessionId: row.readString('session_id'), - pickle: row.readString('pickle'), - content: row.readString('content'), - indexes: row.readString('indexes'), - uploaded: row.readBool('uploaded'), - senderKey: row.readString('sender_key'), - senderClaimedKeys: row.readString('sender_claimed_keys'), - ); - } - Selectable dbGetInboundGroupSessionKey( int client_id, String room_id, String session_id) { return customSelect( @@ -5815,7 +6268,7 @@ abstract class _$Database extends GeneratedDatabase { ], readsFrom: { inboundGroupSessions - }).map(_rowToDbInboundGroupSession); + }).map(inboundGroupSessions.mapFromRow); } Selectable dbGetInboundGroupSessionKeys( @@ -5823,14 +6276,14 @@ abstract class _$Database extends GeneratedDatabase { return customSelect( 'SELECT * FROM inbound_group_sessions WHERE client_id = :client_id AND room_id = :room_id', variables: [Variable.withInt(client_id), Variable.withString(room_id)], - readsFrom: {inboundGroupSessions}).map(_rowToDbInboundGroupSession); + readsFrom: {inboundGroupSessions}).map(inboundGroupSessions.mapFromRow); } Selectable getAllInboundGroupSessions(int client_id) { return customSelect( 'SELECT * FROM inbound_group_sessions WHERE client_id = :client_id', variables: [Variable.withInt(client_id)], - readsFrom: {inboundGroupSessions}).map(_rowToDbInboundGroupSession); + readsFrom: {inboundGroupSessions}).map(inboundGroupSessions.mapFromRow); } Future storeInboundGroupSession( @@ -5877,7 +6330,7 @@ abstract class _$Database extends GeneratedDatabase { return customSelect( 'SELECT * FROM inbound_group_sessions WHERE uploaded = false LIMIT 500', variables: [], - readsFrom: {inboundGroupSessions}).map(_rowToDbInboundGroupSession); + readsFrom: {inboundGroupSessions}).map(inboundGroupSessions.mapFromRow); } Future markInboundGroupSessionAsUploaded( @@ -6042,21 +6495,11 @@ abstract class _$Database extends GeneratedDatabase { ); } - DbSSSSCache _rowToDbSSSSCache(QueryRow row) { - return DbSSSSCache( - clientId: row.readInt('client_id'), - type: row.readString('type'), - keyId: row.readString('key_id'), - ciphertext: row.readString('ciphertext'), - content: row.readString('content'), - ); - } - Selectable dbGetSSSSCache(int client_id, String type) { return customSelect( 'SELECT * FROM ssss_cache WHERE client_id = :client_id AND type = :type', variables: [Variable.withInt(client_id), Variable.withString(type)], - readsFrom: {ssssCache}).map(_rowToDbSSSSCache); + readsFrom: {ssssCache}).map(ssssCache.mapFromRow); } Future clearSSSSCache(int client_id) { @@ -6135,19 +6578,11 @@ abstract class _$Database extends GeneratedDatabase { ); } - DbAccountData _rowToDbAccountData(QueryRow row) { - return DbAccountData( - clientId: row.readInt('client_id'), - type: row.readString('type'), - content: row.readString('content'), - ); - } - Selectable getAllAccountData(int client_id) { return customSelect( 'SELECT * FROM account_data WHERE client_id = :client_id', variables: [Variable.withInt(client_id)], - readsFrom: {accountData}).map(_rowToDbAccountData); + readsFrom: {accountData}).map(accountData.mapFromRow); } Future storeAccountData(int client_id, String type, String content) { @@ -6210,22 +6645,6 @@ abstract class _$Database extends GeneratedDatabase { ); } - DbRoomState _rowToDbRoomState(QueryRow row) { - return DbRoomState( - clientId: row.readInt('client_id'), - eventId: row.readString('event_id'), - roomId: row.readString('room_id'), - sortOrder: row.readDouble('sort_order'), - originServerTs: row.readDateTime('origin_server_ts'), - sender: row.readString('sender'), - type: row.readString('type'), - unsigned: row.readString('unsigned'), - content: row.readString('content'), - prevContent: row.readString('prev_content'), - stateKey: row.readString('state_key'), - ); - } - Selectable getImportantRoomStates( int client_id, List events) { var $arrayStartIndex = 2; @@ -6239,14 +6658,14 @@ abstract class _$Database extends GeneratedDatabase { ], readsFrom: { roomStates - }).map(_rowToDbRoomState); + }).map(roomStates.mapFromRow); } Selectable getAllRoomStates(int client_id) { return customSelect( 'SELECT * FROM room_states WHERE client_id = :client_id', variables: [Variable.withInt(client_id)], - readsFrom: {roomStates}).map(_rowToDbRoomState); + readsFrom: {roomStates}).map(roomStates.mapFromRow); } Selectable getUnimportantRoomStatesForRoom( @@ -6263,7 +6682,7 @@ abstract class _$Database extends GeneratedDatabase { ], readsFrom: { roomStates - }).map(_rowToDbRoomState); + }).map(roomStates.mapFromRow); } Future storeEvent( @@ -6271,7 +6690,7 @@ abstract class _$Database extends GeneratedDatabase { String event_id, String room_id, double sort_order, - DateTime origin_server_ts, + int origin_server_ts, String sender, String type, String unsigned, @@ -6286,7 +6705,7 @@ abstract class _$Database extends GeneratedDatabase { Variable.withString(event_id), Variable.withString(room_id), Variable.withReal(sort_order), - Variable.withDateTime(origin_server_ts), + Variable.withInt(origin_server_ts), Variable.withString(sender), Variable.withString(type), Variable.withString(unsigned), @@ -6304,7 +6723,7 @@ abstract class _$Database extends GeneratedDatabase { String event_id, String room_id, double sort_order, - DateTime origin_server_ts, + int origin_server_ts, String sender, String type, String unsigned, @@ -6318,7 +6737,7 @@ abstract class _$Database extends GeneratedDatabase { Variable.withString(event_id), Variable.withString(room_id), Variable.withReal(sort_order), - Variable.withDateTime(origin_server_ts), + Variable.withInt(origin_server_ts), Variable.withString(sender), Variable.withString(type), Variable.withString(unsigned), @@ -6330,20 +6749,11 @@ abstract class _$Database extends GeneratedDatabase { ); } - DbRoomAccountData _rowToDbRoomAccountData(QueryRow row) { - return DbRoomAccountData( - clientId: row.readInt('client_id'), - type: row.readString('type'), - roomId: row.readString('room_id'), - content: row.readString('content'), - ); - } - Selectable getAllRoomAccountData(int client_id) { return customSelect( 'SELECT * FROM room_account_data WHERE client_id = :client_id', variables: [Variable.withInt(client_id)], - readsFrom: {roomAccountData}).map(_rowToDbRoomAccountData); + readsFrom: {roomAccountData}).map(roomAccountData.mapFromRow); } Future storeRoomAccountData( @@ -6371,45 +6781,28 @@ abstract class _$Database extends GeneratedDatabase { ], readsFrom: { roomStates - }).map(_rowToDbRoomState); + }).map(roomStates.mapFromRow); } Selectable dbGetUsers(int client_id, String room_id) { return customSelect( 'SELECT * FROM room_states WHERE client_id = :client_id AND type = \'m.room.member\' AND room_id = :room_id', variables: [Variable.withInt(client_id), Variable.withString(room_id)], - readsFrom: {roomStates}).map(_rowToDbRoomState); - } - - DbEvent _rowToDbEvent(QueryRow row) { - return DbEvent( - clientId: row.readInt('client_id'), - eventId: row.readString('event_id'), - roomId: row.readString('room_id'), - sortOrder: row.readDouble('sort_order'), - originServerTs: row.readDateTime('origin_server_ts'), - sender: row.readString('sender'), - type: row.readString('type'), - unsigned: row.readString('unsigned'), - content: row.readString('content'), - prevContent: row.readString('prev_content'), - stateKey: row.readString('state_key'), - status: row.readInt('status'), - ); + readsFrom: {roomStates}).map(roomStates.mapFromRow); } Selectable dbGetEventList(int client_id, String room_id) { return customSelect( 'SELECT * FROM events WHERE client_id = :client_id AND room_id = :room_id GROUP BY event_id ORDER BY sort_order DESC', variables: [Variable.withInt(client_id), Variable.withString(room_id)], - readsFrom: {events}).map(_rowToDbEvent); + readsFrom: {events}).map(events.mapFromRow); } Selectable getStates(int client_id, String room_id) { return customSelect( 'SELECT * FROM room_states WHERE client_id = :client_id AND room_id = :room_id', variables: [Variable.withInt(client_id), Variable.withString(room_id)], - readsFrom: {roomStates}).map(_rowToDbRoomState); + readsFrom: {roomStates}).map(roomStates.mapFromRow); } Future resetNotificationCount(int client_id, String room_id) { @@ -6421,27 +6814,11 @@ abstract class _$Database extends GeneratedDatabase { ); } - DbRoom _rowToDbRoom(QueryRow row) { - return DbRoom( - clientId: row.readInt('client_id'), - roomId: row.readString('room_id'), - membership: row.readString('membership'), - highlightCount: row.readInt('highlight_count'), - notificationCount: row.readInt('notification_count'), - prevBatch: row.readString('prev_batch'), - joinedMemberCount: row.readInt('joined_member_count'), - invitedMemberCount: row.readInt('invited_member_count'), - newestSortOrder: row.readDouble('newest_sort_order'), - oldestSortOrder: row.readDouble('oldest_sort_order'), - heroes: row.readString('heroes'), - ); - } - Selectable getRoom(int client_id, String room_id) { return customSelect( 'SELECT * FROM rooms WHERE client_id = :client_id AND room_id = :room_id', variables: [Variable.withInt(client_id), Variable.withString(room_id)], - readsFrom: {rooms}).map(_rowToDbRoom); + readsFrom: {rooms}).map(rooms.mapFromRow); } Selectable getEvent(int client_id, String event_id, String room_id) { @@ -6454,7 +6831,7 @@ abstract class _$Database extends GeneratedDatabase { ], readsFrom: { events - }).map(_rowToDbEvent); + }).map(events.mapFromRow); } Future removeEvent(int client_id, String event_id, String room_id) { @@ -6488,30 +6865,22 @@ abstract class _$Database extends GeneratedDatabase { ); } - Future storeFile(String mxc_uri, Uint8List bytes, DateTime time) { + Future storeFile(String mxc_uri, Uint8List bytes, int time) { return customInsert( 'INSERT OR REPLACE INTO files (mxc_uri, bytes, saved_at) VALUES (:mxc_uri, :bytes, :time)', variables: [ Variable.withString(mxc_uri), Variable.withBlob(bytes), - Variable.withDateTime(time) + Variable.withInt(time) ], updates: {files}, ); } - DbFile _rowToDbFile(QueryRow row) { - return DbFile( - mxcUri: row.readString('mxc_uri'), - bytes: row.readBlob('bytes'), - savedAt: row.readDateTime('saved_at'), - ); - } - Selectable dbGetFile(String mxc_uri) { return customSelect('SELECT * FROM files WHERE mxc_uri = :mxc_uri', variables: [Variable.withString(mxc_uri)], - readsFrom: {files}).map(_rowToDbFile); + readsFrom: {files}).map(files.mapFromRow); } Future markPendingEventsAsError(int client_id) { diff --git a/lib/src/database/database.moor b/lib/src/database/database.moor index 17221d4..7624359 100644 --- a/lib/src/database/database.moor +++ b/lib/src/database/database.moor @@ -48,7 +48,7 @@ CREATE TABLE olm_sessions ( identity_key TEXT NOT NULL, session_id TEXT NOT NULL, pickle TEXT NOT NULL, - last_received DATETIME, + last_received BIGINT, UNIQUE(client_id, identity_key, session_id) ) AS DbOlmSessions; CREATE INDEX olm_sessions_index ON olm_sessions(client_id); @@ -58,7 +58,7 @@ CREATE TABLE outbound_group_sessions ( room_id TEXT NOT NULL, pickle TEXT NOT NULL, device_ids TEXT NOT NULL, - creation_time DATETIME NOT NULL, + creation_time BIGINT NOT NULL, sent_messages INTEGER NOT NULL DEFAULT '0', UNIQUE(client_id, room_id) ) AS DbOutboundGroupSession; @@ -108,7 +108,7 @@ CREATE TABLE events ( event_id TEXT NOT NULL, room_id TEXT NOT NULL, sort_order DOUBLE NOT NULL, - origin_server_ts DATETIME NOT NULL, + origin_server_ts BIGINT NOT NULL, sender TEXT NOT NULL, type TEXT NOT NULL, unsigned TEXT, @@ -125,7 +125,7 @@ CREATE TABLE room_states ( event_id TEXT NOT NULL, room_id TEXT NOT NULL, sort_order DOUBLE NOT NULL, - origin_server_ts DATETIME NOT NULL, + origin_server_ts BIGINT NOT NULL, sender TEXT NOT NULL, type TEXT NOT NULL, unsigned TEXT, @@ -166,7 +166,7 @@ CREATE INDEX presences_index ON presences(client_id); CREATE TABLE files ( mxc_uri TEXT NOT NULL PRIMARY KEY, bytes BLOB, - saved_at DATETIME, + saved_at BIGINT, UNIQUE(mxc_uri) ) AS DbFile; diff --git a/lib/src/event.dart b/lib/src/event.dart index bb6c428..af7bc54 100644 --- a/lib/src/event.dart +++ b/lib/src/event.dart @@ -192,7 +192,9 @@ class Event extends MatrixEvent { eventId: dbEntry.eventId, roomId: dbEntry.roomId, senderId: dbEntry.sender, - originServerTs: dbEntry.originServerTs ?? DateTime.now(), + originServerTs: dbEntry.originServerTs != null + ? DateTime.fromMillisecondsSinceEpoch(dbEntry.originServerTs) + : DateTime.now(), unsigned: unsigned, room: room, sortOrder: dbEntry.sortOrder ?? 0.0, @@ -425,8 +427,8 @@ class Event extends MatrixEvent { storeable = storeable && uint8list.lengthInBytes < room.client.database.maxFileSize; if (storeable) { - await room.client.database - .storeFile(mxContent.toString(), uint8list, DateTime.now()); + await room.client.database.storeFile(mxContent.toString(), uint8list, + DateTime.now().millisecondsSinceEpoch); } } diff --git a/pubspec.yaml b/pubspec.yaml index 8880a3c..2c283e1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -31,3 +31,7 @@ dev_dependencies: build_runner: ^1.5.2 pedantic: ^1.9.0 moor_ffi: ^0.5.0 + +dependency_overrides: + # See https://github.com/flutter/flutter/issues/62240 + analyzer: '0.39.14' diff --git a/test/room_test.dart b/test/room_test.dart index 214bd9c..53cc2d7 100644 --- a/test/room_test.dart +++ b/test/room_test.dart @@ -73,7 +73,7 @@ void main() { eventId: '143273582443PhrSn:example.org', roomId: id, sortOrder: 0.0, - originServerTs: DateTime.fromMillisecondsSinceEpoch(1432735824653), + originServerTs: 1432735824653, sender: '@example:example.org', type: 'm.room.join_rules', unsigned: '{"age": 1234}', From 74bd1d331b77f45ab0793af7c9e607795b8c16f0 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Sun, 4 Oct 2020 12:16:01 +0200 Subject: [PATCH 2/2] fix: Messages being encrypted for too many devices --- lib/src/client.dart | 4 ++-- lib/src/room.dart | 3 ++- test/user_test.dart | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index 45025ac..a3cec5d 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -1579,13 +1579,13 @@ sort order of ${prevState.sortOrder}. This should never happen...'''); /// you can safely make this Client instance null. Future dispose({bool closeDatabase = false}) async { _disposed = true; - encryption?.dispose(); - encryption = null; try { await _currentTransaction; } catch (_) { // No-OP } + encryption?.dispose(); + encryption = null; try { if (closeDatabase) await database?.close(); } catch (error, stacktrace) { diff --git a/lib/src/room.dart b/lib/src/room.dart index 7b46b88..aba01d2 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -1620,7 +1620,8 @@ class Room { var deviceKeys = []; var users = await requestParticipants(); for (final user in users) { - if (client.userDeviceKeys.containsKey(user.id)) { + if ([Membership.invite, Membership.join].contains(user.membership) && + client.userDeviceKeys.containsKey(user.id)) { for (var deviceKeyEntry in client.userDeviceKeys[user.id].deviceKeys.values) { deviceKeys.add(deviceKeyEntry); diff --git a/test/user_test.dart b/test/user_test.dart index ea2d7fe..fdb8c0b 100644 --- a/test/user_test.dart +++ b/test/user_test.dart @@ -133,7 +133,7 @@ void main() { expect(user1.canChangePowerLevel, false); }); test('dispose client', () async { - await client.dispose(); + await client.dispose(closeDatabase: true); }); }); }