From 79ea85bf4d2520a1c5246c3059e5c9d8113a30cd Mon Sep 17 00:00:00 2001 From: Sorunome Date: Tue, 14 Jul 2020 10:43:21 +0200 Subject: [PATCH 1/7] indexes are already created when creating a talbe --- lib/src/database/database.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/src/database/database.dart b/lib/src/database/database.dart index c329d0b..036d885 100644 --- a/lib/src/database/database.dart +++ b/lib/src/database/database.dart @@ -48,7 +48,6 @@ class Database extends _$Database { } if (from == 3) { await m.createTable(userCrossSigningKeys); - await m.createIndex(userCrossSigningKeysIndex); await m.createTable(ssssCache); // mark all keys as outdated so that the cross signing keys will be fetched await m.issueCustomQuery( From 8294231f78348eb20133cf9bc9c99a4654e8f6bc Mon Sep 17 00:00:00 2001 From: Sorunome Date: Tue, 14 Jul 2020 12:00:37 +0200 Subject: [PATCH 2/7] url in PusherData is optional --- lib/matrix_api/model/pusher.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/matrix_api/model/pusher.dart b/lib/matrix_api/model/pusher.dart index 18ef050..00bc280 100644 --- a/lib/matrix_api/model/pusher.dart +++ b/lib/matrix_api/model/pusher.dart @@ -74,7 +74,9 @@ class PusherData { }); PusherData.fromJson(Map json) { - url = Uri.parse(json['url']); + if (json.containsKey('url')) { + url = Uri.parse(json['url']); + } format = json['format']; } From fc1b78d712ec2710db4e4ad47f51c627c6889e82 Mon Sep 17 00:00:00 2001 From: Lukas Lihotzki Date: Tue, 14 Jul 2020 17:08:30 +0200 Subject: [PATCH 3/7] olm and matrix_file_e2ee from pub --- pubspec.lock | 18 ------------------ pubspec.yaml | 12 ++---------- 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index e532c62..7f80235 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -323,15 +323,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.12.6" - matrix_file_e2ee: - dependency: "direct main" - description: - path: "." - ref: "1.x.y" - resolved-ref: "32edeff765369a7a77a0822f4b19302ca24a017b" - url: "https://gitlab.com/famedly/libraries/matrix_file_e2ee.git" - source: git - version: "1.0.3" meta: dependency: transitive description: @@ -395,15 +386,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.4.8" - olm: - dependency: "direct main" - description: - path: "." - ref: "1.x.y" - resolved-ref: "8e4fcccff7a2d4d0bd5142964db092bf45061905" - url: "https://gitlab.com/famedly/libraries/dart-olm.git" - source: git - version: "1.2.0" package_config: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index c75844a..a82843e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,16 +19,8 @@ dependencies: crypto: ^2.1.4 base58check: ^1.0.1 password_hash: ^2.0.0 - - olm: - git: - url: https://gitlab.com/famedly/libraries/dart-olm.git - ref: 1.x.y - - matrix_file_e2ee: - git: - url: https://gitlab.com/famedly/libraries/matrix_file_e2ee.git - ref: 1.x.y + olm: ^1.2.1 + matrix_file_e2ee: ^1.0.4 dev_dependencies: test: ^1.0.0 From 864151ec838690452a38879019ca2170c64b24cc Mon Sep 17 00:00:00 2001 From: Sorunome Date: Fri, 17 Jul 2020 12:02:43 +0200 Subject: [PATCH 4/7] use prev_content to calculate displayname and avatar_url, if content unavailable --- lib/src/event.dart | 8 +++++++- lib/src/user.dart | 15 +++++++++++---- pubspec.lock | 37 +++++++++++++++---------------------- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/lib/src/event.dart b/lib/src/event.dart index d80b56c..50c3563 100644 --- a/lib/src/event.dart +++ b/lib/src/event.dart @@ -89,7 +89,13 @@ class Event extends MatrixEvent { this.roomId = roomId ?? room?.id; this.senderId = senderId; this.unsigned = unsigned; - this.prevContent = prevContent; + // synapse unfortunatley isn't following the spec and tosses the prev_content + // into the unsigned block + this.prevContent = prevContent != null && prevContent.isNotEmpty + ? prevContent + : (unsigned != null && unsigned['prev_content'] is Map + ? unsigned['prev_content'] + : null); this.stateKey = stateKey; this.originServerTs = originServerTs; } diff --git a/lib/src/user.dart b/lib/src/user.dart index c87ebbc..3efedf4 100644 --- a/lib/src/user.dart +++ b/lib/src/user.dart @@ -71,7 +71,10 @@ class User extends Event { String get id => stateKey; /// The displayname of the user if the user has set one. - String get displayName => content != null ? content['displayname'] : null; + String get displayName => + content != null && content.containsKey('displayname') + ? content['displayname'] + : (prevContent != null ? prevContent['displayname'] : null); /// Returns the power level of this user. int get powerLevel => room?.getPowerLevelByUserId(id); @@ -89,9 +92,13 @@ class User extends Event { }, orElse: () => Membership.join); /// The avatar if the user has one. - Uri get avatarUrl => content != null && content['avatar_url'] is String - ? Uri.parse(content['avatar_url']) - : null; + Uri get avatarUrl => content != null && content.containsKey('avatar_url') + ? (content['avatar_url'] is String + ? Uri.parse(content['avatar_url']) + : null) + : (prevContent != null && prevContent['avatar_url'] is String + ? Uri.parse(prevContent['avatar_url']) + : null); /// Returns the displayname or the local part of the Matrix ID if the user /// has no displayname. If [formatLocalpart] is true, then the localpart will diff --git a/pubspec.lock b/pubspec.lock index 7f80235..faec33f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -22,13 +22,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.2.2" - archive: - dependency: transitive - description: - name: archive - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.13" args: dependency: transitive description: @@ -323,6 +316,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.12.6" + matrix_file_e2ee: + dependency: "direct main" + description: + name: matrix_file_e2ee + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" meta: dependency: transitive description: @@ -331,7 +331,7 @@ packages: source: hosted version: "1.1.8" mime: - dependency: transitive + dependency: "direct main" description: name: mime url: "https://pub.dartlang.org" @@ -386,6 +386,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.4.8" + olm: + dependency: "direct main" + description: + name: olm + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" package_config: dependency: transitive description: @@ -414,13 +421,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.9.0" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.dartlang.org" - source: hosted - version: "3.0.2" pointycastle: dependency: transitive description: @@ -652,13 +652,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.5.4" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.dartlang.org" - source: hosted - version: "3.7.0" yaml: dependency: transitive description: From 175cb0fbd224928c72ceab43f131e81aac950836 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Fri, 17 Jul 2020 13:20:23 +0200 Subject: [PATCH 5/7] add Databse.connect to be able to run in isaltes --- build.yaml | 6 ++++++ lib/src/database/database.dart | 2 ++ lib/src/database/database.g.dart | 18 +----------------- 3 files changed, 9 insertions(+), 17 deletions(-) create mode 100644 build.yaml diff --git a/build.yaml b/build.yaml new file mode 100644 index 0000000..b07425b --- /dev/null +++ b/build.yaml @@ -0,0 +1,6 @@ +targets: + $default: + builders: + moor_generator: + options: + generate_connect_constructor: true diff --git a/lib/src/database/database.dart b/lib/src/database/database.dart index 036d885..805330f 100644 --- a/lib/src/database/database.dart +++ b/lib/src/database/database.dart @@ -15,6 +15,8 @@ part 'database.g.dart'; class Database extends _$Database { Database(QueryExecutor e) : super(e); + Database.connect(DatabaseConnection connection) : super.connect(connection); + @override int get schemaVersion => 5; diff --git a/lib/src/database/database.g.dart b/lib/src/database/database.g.dart index e17101d..453053e 100644 --- a/lib/src/database/database.g.dart +++ b/lib/src/database/database.g.dart @@ -5361,6 +5361,7 @@ class Files extends Table with TableInfo { abstract class _$Database extends GeneratedDatabase { _$Database(QueryExecutor e) : super(SqlTypeSystem.defaultInstance, e); + _$Database.connect(DatabaseConnection c) : super.connect(c); Clients _clients; Clients get clients => _clients ??= Clients(this); UserDeviceKeys _userDeviceKeys; @@ -6196,23 +6197,6 @@ abstract class _$Database extends GeneratedDatabase { }).map(_rowToDbRoomState); } - Selectable dbGetUsers( - int client_id, List mxids, String room_id) { - var $arrayStartIndex = 2; - final expandedmxids = $expandVar($arrayStartIndex, mxids.length); - $arrayStartIndex += mxids.length; - return customSelect( - 'SELECT * FROM room_states WHERE client_id = :client_id AND type = \'m.room.member\' AND state_key IN ($expandedmxids) AND room_id = :room_id', - variables: [ - Variable.withInt(client_id), - for (var $ in mxids) Variable.withString($), - Variable.withString(room_id) - ], - readsFrom: { - roomStates - }).map(_rowToDbRoomState); - } - DbEvent _rowToDbEvent(QueryRow row) { return DbEvent( clientId: row.readInt('client_id'), From 2214ac2d0a5bfdb66122b6c697e25f985b7b9665 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Mon, 20 Jul 2020 06:31:05 +0000 Subject: [PATCH 6/7] fixes a racing condition in key verification --- lib/encryption/utils/key_verification.dart | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/encryption/utils/key_verification.dart b/lib/encryption/utils/key_verification.dart index 90a2479..e4a43f3 100644 --- a/lib/encryption/utils/key_verification.dart +++ b/lib/encryption/utils/key_verification.dart @@ -194,8 +194,14 @@ class KeyVerification { } } + bool _handlePayloadLock = false; + Future handlePayload(String type, Map payload, [String eventId]) async { + while (_handlePayloadLock) { + await Future.delayed(Duration(milliseconds: 50)); + } + _handlePayloadLock = true; print('[Key Verification] Received type ${type}: ' + payload.toString()); try { var thisLastStep = lastStep; @@ -307,6 +313,8 @@ class KeyVerification { if (deviceId != null) { await cancel('m.invalid_message'); } + } finally { + _handlePayloadLock = false; } } @@ -529,8 +537,8 @@ class KeyVerification { Future send(String type, Map payload) async { makePayload(payload); print('[Key Verification] Sending type ${type}: ' + payload.toString()); - print('[Key Verification] Sending to ${userId} device ${deviceId}'); if (room != null) { + print('[Key Verification] Sending to ${userId} in room ${room.id}'); if (['m.key.verification.request'].contains(type)) { payload['msgtype'] = type; payload['to'] = userId; @@ -544,6 +552,7 @@ class KeyVerification { encryption.keyVerificationManager.addRequest(this); } } else { + print('[Key Verification] Sending to ${userId} device ${deviceId}'); await client.sendToDevice( [client.userDeviceKeys[userId].deviceKeys[deviceId]], type, payload); } From b8f80c7071b446691b8aeea439a52009f07b7b9f Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Mon, 20 Jul 2020 07:46:46 +0000 Subject: [PATCH 7/7] Fix room sorting --- lib/src/client.dart | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index 2b959cf..8815688 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -87,7 +87,8 @@ class Client { this.enableE2eeRecovery = false, this.verificationMethods, http.Client httpClient, - this.importantStateEvents}) { + this.importantStateEvents, + this.pinUnreadRooms = false}) { verificationMethods ??= {}; importantStateEvents ??= {}; importantStateEvents.addAll([ @@ -1101,13 +1102,16 @@ class Client { bool _sortLock = false; + /// If [true] then unread rooms are pinned at the top of the room list. + bool pinUnreadRooms; + /// The compare function how the rooms should be sorted internally. By default /// rooms are sorted by timestamp of the last m.room.message event or the last /// event if there is no known message. - RoomSorter sortRoomsBy = (a, b) => (a.membership != b.membership) - ? (a.membership == Membership.invite ? -1 : 1) - : (a.isFavourite != b.isFavourite) - ? (a.isFavourite ? -1 : 1) + RoomSorter get sortRoomsBy => (a, b) => (a.isFavourite != b.isFavourite) + ? (a.isFavourite ? -1 : 1) + : (pinUnreadRooms && a.notificationCount != b.notificationCount) + ? b.notificationCount.compareTo(a.notificationCount) : b.timeCreated.millisecondsSinceEpoch .compareTo(a.timeCreated.millisecondsSinceEpoch);