diff --git a/.github/workflows/app.yml b/.github/workflows/app.yml index 91e5529d..cdd83e2c 100644 --- a/.github/workflows/app.yml +++ b/.github/workflows/app.yml @@ -129,7 +129,7 @@ jobs: - name: Run tests run: | dart pub get - dart test test/box_test.dart --platform chrome + dart test test/box_test.dart --platform chrome --fail-fast pub-dev-dry-run: runs-on: ubuntu-latest diff --git a/.github/workflows/versions.env b/.github/workflows/versions.env index d946d570..5df62bca 100644 --- a/.github/workflows/versions.env +++ b/.github/workflows/versions.env @@ -1,2 +1,2 @@ -flutter_version=3.24.3 -dart_version=3.5.3 +flutter_version=3.27.1 +dart_version=3.6.0 diff --git a/lib/encryption/encryption.dart b/lib/encryption/encryption.dart index 5a4ec7e3..7d6c03ff 100644 --- a/lib/encryption/encryption.dart +++ b/lib/encryption/encryption.dart @@ -193,7 +193,7 @@ class Encryption { } } - Event decryptRoomEventSync(String roomId, Event event) { + Event decryptRoomEventSync(Event event) { if (event.type != EventTypes.Encrypted || event.redacted) { return event; } @@ -214,7 +214,7 @@ class Encryption { } final inboundGroupSession = - keyManager.getInboundGroupSession(roomId, sessionId); + keyManager.getInboundGroupSession(event.room.id, sessionId); if (!(inboundGroupSession?.isValid ?? false)) { canRequestSession = true; throw DecryptException(DecryptException.unknownSession); @@ -249,7 +249,7 @@ class Encryption { // ignore: discarded_futures ?.updateInboundGroupSessionIndexes( json.encode(inboundGroupSession.indexes), - roomId, + event.room.id, sessionId, ) // ignore: discarded_futures @@ -260,14 +260,16 @@ class Encryption { // alright, if this was actually by our own outbound group session, we might as well clear it if (exception.toString() != DecryptException.unknownSession && (keyManager - .getOutboundGroupSession(roomId) + .getOutboundGroupSession(event.room.id) ?.outboundGroupSession ?.session_id() ?? '') == content.sessionId) { runInRoot( - () async => - keyManager.clearOrUseOutboundGroupSession(roomId, wipe: true), + () async => keyManager.clearOrUseOutboundGroupSession( + event.room.id, + wipe: true, + ), ); } if (canRequestSession) { @@ -308,7 +310,6 @@ class Encryption { } Future decryptRoomEvent( - String roomId, Event event, { bool store = false, EventUpdateType updateType = EventUpdateType.timeline, @@ -323,22 +324,22 @@ class Encryption { sessionId != null && !(keyManager .getInboundGroupSession( - roomId, + event.room.id, sessionId, ) ?.isValid ?? false)) { await keyManager.loadInboundGroupSession( - roomId, + event.room.id, sessionId, ); } - event = decryptRoomEventSync(roomId, event); + event = decryptRoomEventSync(event); if (event.type == EventTypes.Encrypted && event.content['can_request_session'] == true && sessionId != null) { keyManager.maybeAutoRequest( - roomId, + event.room.id, sessionId, content.senderKey, ); @@ -350,7 +351,7 @@ class Encryption { await client.database?.storeEventUpdate( EventUpdate( content: event.toJson(), - roomID: roomId, + roomID: event.room.id, type: updateType, ), client, diff --git a/lib/encryption/key_manager.dart b/lib/encryption/key_manager.dart index fa9371c6..5c3df9c1 100644 --- a/lib/encryption/key_manager.dart +++ b/lib/encryption/key_manager.dart @@ -192,7 +192,7 @@ class KeyManager { if (event != null && event.type == EventTypes.Encrypted && event.content['session_id'] == sessionId) { - final decrypted = encryption.decryptRoomEventSync(roomId, event); + final decrypted = encryption.decryptRoomEventSync(event); if (decrypted.type != EventTypes.Encrypted) { // Update the last event in memory first room.lastEvent = decrypted; diff --git a/lib/encryption/utils/json_signature_check_extension.dart b/lib/encryption/utils/json_signature_check_extension.dart index f53cdad9..7c1f4f6c 100644 --- a/lib/encryption/utils/json_signature_check_extension.dart +++ b/lib/encryption/utils/json_signature_check_extension.dart @@ -27,7 +27,9 @@ extension JsonSignatureCheckExtension on Map { final signatures = this['signatures']; if (signatures == null || signatures is! Map || - !signatures.containsKey(userId)) return false; + !signatures.containsKey(userId)) { + return false; + } remove('unsigned'); remove('signatures'); if (!signatures[userId].containsKey('ed25519:$deviceId')) return false; diff --git a/lib/msc_extensions/msc_3814_dehydrated_devices/msc_3814_dehydrated_devices.dart b/lib/msc_extensions/msc_3814_dehydrated_devices/msc_3814_dehydrated_devices.dart index cc102b80..e53c1915 100644 --- a/lib/msc_extensions/msc_3814_dehydrated_devices/msc_3814_dehydrated_devices.dart +++ b/lib/msc_extensions/msc_3814_dehydrated_devices/msc_3814_dehydrated_devices.dart @@ -54,7 +54,9 @@ extension DehydratedDeviceHandler on Client { // Only handle devices we understand // In the future we might want to migrate to a newer format here if (device.deviceData?.tryGet('algorithm') != - _dehydratedDeviceAlgorithm) return; + _dehydratedDeviceAlgorithm) { + return; + } // Verify that the device is cross-signed final dehydratedDeviceIdentity = diff --git a/lib/src/client.dart b/lib/src/client.dart index ed52269c..01c57a72 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -1243,10 +1243,7 @@ class Client extends MatrixApi { if (archivedRoom.encrypted && archivedRoom.client.encryptionEnabled) { if (timeline.events[i].type == EventTypes.Encrypted) { await archivedRoom.client.encryption! - .decryptRoomEvent( - archivedRoom.id, - timeline.events[i], - ) + .decryptRoomEvent(timeline.events[i]) .then( (decrypted) => timeline.events[i] = decrypted, ); @@ -1880,11 +1877,11 @@ class Client extends MatrixApi { final encryption = this.encryption; if (event.type == EventTypes.Encrypted && encryption != null) { - var decrypted = await encryption.decryptRoomEvent(roomId, event); + var decrypted = await encryption.decryptRoomEvent(event); if (decrypted.messageType == MessageTypes.BadEncrypted && prevBatch != null) { await oneShotSync(); - decrypted = await encryption.decryptRoomEvent(roomId, event); + decrypted = await encryption.decryptRoomEvent(event); } event = decrypted; } @@ -2567,7 +2564,9 @@ class Client extends MatrixApi { if (event.event.roomID != roomId) continue; if (!sessionIds.contains( event.event.content['content']?['session_id'], - )) continue; + )) { + continue; + } final decryptedEvent = await event.event.decrypt(room); if (decryptedEvent.content.tryGet('type') != diff --git a/lib/src/models/receipts.dart b/lib/src/models/receipts.dart index 9bb3e3c6..d7027c43 100644 --- a/lib/src/models/receipts.dart +++ b/lib/src/models/receipts.dart @@ -115,7 +115,9 @@ class ReceiptEventContent { if (userId is! String || !userId.isValidMatrixId || - receiptContent is! Map) continue; + receiptContent is! Map) { + continue; + } final ts = receiptContent['ts']; final threadId = receiptContent['thread_id']; diff --git a/lib/src/room.dart b/lib/src/room.dart index 420dced0..9bcbd28a 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -518,7 +518,9 @@ class Room { // There is no known event or the last event is only a state fallback event, // we assume there is no new messages. if (lastEvent == null || - !client.roomPreviewLastEvents.contains(lastEvent.type)) return false; + !client.roomPreviewLastEvents.contains(lastEvent.type)) { + return false; + } // Read marker is on the last event so no new messages. if (lastEvent.receipts @@ -1458,10 +1460,7 @@ class Room { for (var i = 0; i < events.length; i++) { if (events[i].type == EventTypes.Encrypted && events[i].content['can_request_session'] == true) { - events[i] = await client.encryption!.decryptRoomEvent( - id, - events[i], - ); + events[i] = await client.encryption!.decryptRoomEvent(events[i]); } } } @@ -1527,10 +1526,7 @@ class Room { // Try to decrypt encrypted events but don't update the database. if (encrypted && client.encryptionEnabled) { if (events[i].type == EventTypes.Encrypted) { - events[i] = await client.encryption!.decryptRoomEvent( - id, - events[i], - ); + events[i] = await client.encryption!.decryptRoomEvent(events[i]); } } } @@ -1574,7 +1570,6 @@ class Room { // for the fragmented timeline, we don't cache the decrypted //message in the database chunk.events[i] = await client.encryption!.decryptRoomEvent( - id, chunk.events[i], ); } else if (client.database != null) { @@ -1583,7 +1578,6 @@ class Room { for (var i = 0; i < chunk.events.length; i++) { if (chunk.events[i].content['can_request_session'] == true) { chunk.events[i] = await client.encryption!.decryptRoomEvent( - id, chunk.events[i], store: !isArchived, updateType: EventUpdateType.history, @@ -1911,10 +1905,7 @@ class Room { final event = Event.fromMatrixEvent(matrixEvent, this); if (event.type == EventTypes.Encrypted && client.encryptionEnabled) { // attempt decryption - return await client.encryption?.decryptRoomEvent( - id, - event, - ); + return await client.encryption?.decryptRoomEvent(event); } return event; } on MatrixException catch (err) { diff --git a/lib/src/timeline.dart b/lib/src/timeline.dart index 801b743d..04d3679e 100644 --- a/lib/src/timeline.dart +++ b/lib/src/timeline.dart @@ -263,7 +263,9 @@ class Timeline { if (!allowNewEvent) { if (resp.start == resp.end || - (resp.end == null && direction == Direction.f)) allowNewEvent = true; + (resp.end == null && direction == Direction.f)) { + allowNewEvent = true; + } if (allowNewEvent) { Logs().d('We now allow sync update into the timeline.'); @@ -279,7 +281,6 @@ class Timeline { for (var i = 0; i < newEvents.length; i++) { if (newEvents[i].type == EventTypes.Encrypted) { newEvents[i] = await room.client.encryption!.decryptRoomEvent( - room.id, newEvents[i], ); } @@ -388,7 +389,6 @@ class Timeline { events[i].messageType == MessageTypes.BadEncrypted && events[i].content['session_id'] == sessionId) { events[i] = await encryption.decryptRoomEvent( - room.id, events[i], store: true, updateType: EventUpdateType.history, @@ -566,7 +566,9 @@ class Timeline { events.indexWhere( (e) => e.eventId == eventUpdate.content['event_id'], ) != - -1) return; + -1) { + return; + } var index = events.length; if (eventUpdate.type == EventUpdateType.history) { events.add(newEvent); @@ -703,7 +705,7 @@ class Timeline { for (final matrixEvent in resp.chunk) { var event = Event.fromMatrixEvent(matrixEvent, room); if (event.type == EventTypes.Encrypted && encryption != null) { - event = await encryption.decryptRoomEvent(room.id, event); + event = await encryption.decryptRoomEvent(event); if (event.type == EventTypes.Encrypted && event.messageType == MessageTypes.BadEncrypted && event.content['can_request_session'] == true) { diff --git a/lib/src/utils/event_localizations.dart b/lib/src/utils/event_localizations.dart index e03b9d0c..1ae3b98a 100644 --- a/lib/src/utils/event_localizations.dart +++ b/lib/src/utils/event_localizations.dart @@ -203,7 +203,6 @@ abstract class EventLocalizations { case RoomMemberChangeType.knock: return i18n.hasKnocked(targetName); case RoomMemberChangeType.other: - default: return userIsTarget ? i18n.youJoinedTheChat : i18n.joinedTheChat(targetName); diff --git a/lib/src/utils/event_update.dart b/lib/src/utils/event_update.dart index 8d5918f8..f083748f 100644 --- a/lib/src/utils/event_update.dart +++ b/lib/src/utils/event_update.dart @@ -68,7 +68,6 @@ class EventUpdate { } try { final decrpytedEvent = await encryption.decryptRoomEvent( - room.id, Event.fromJson(content, room), store: store, updateType: type, diff --git a/lib/src/utils/push_notification.dart b/lib/src/utils/push_notification.dart index 77c91300..7bd80cfc 100644 --- a/lib/src/utils/push_notification.dart +++ b/lib/src/utils/push_notification.dart @@ -29,7 +29,7 @@ class PushNotification { }); /// Generate a Push Notification object from JSON. It also supports a - /// map which usually comes from Firebase Cloud Messaging. + /// `map` which usually comes from Firebase Cloud Messaging. factory PushNotification.fromJson(Map json) => PushNotification( content: json['content'] is Map diff --git a/lib/src/utils/pushrule_evaluator.dart b/lib/src/utils/pushrule_evaluator.dart index f36f560c..9851d121 100644 --- a/lib/src/utils/pushrule_evaluator.dart +++ b/lib/src/utils/pushrule_evaluator.dart @@ -153,7 +153,6 @@ class _MemberCountCondition { case _CountComparisonOp.lt: return memberCount < count; case _CountComparisonOp.eq: - default: return memberCount == count; } } diff --git a/lib/src/utils/versions_comparator.dart b/lib/src/utils/versions_comparator.dart index 8e1928bd..d08ba33d 100644 --- a/lib/src/utils/versions_comparator.dart +++ b/lib/src/utils/versions_comparator.dart @@ -13,11 +13,10 @@ bool isVersionGreaterThanOrEqualTo(String version, String target) { } return true; - } catch (e, s) { - Logs().e( + } catch (e) { + Logs().w( '[_isVersionGreaterThanOrEqualTo] Failed to parse version $version', e, - s, ); return false; } diff --git a/lib/src/voip/backend/mesh_backend.dart b/lib/src/voip/backend/mesh_backend.dart index 0e0245b4..fd45a52d 100644 --- a/lib/src/voip/backend/mesh_backend.dart +++ b/lib/src/voip/backend/mesh_backend.dart @@ -650,7 +650,6 @@ class MeshBackend extends CallBackend { await call.setLocalVideoMuted(muted); } break; - default: } } diff --git a/lib/src/voip/call_session.dart b/lib/src/voip/call_session.dart index c11dbf30..a809de1f 100644 --- a/lib/src/voip/call_session.dart +++ b/lib/src/voip/call_session.dart @@ -1016,7 +1016,9 @@ class CallSession { // when a call crash and this call is already terminated the currentCId is null. // So don't return bc the hangup or reject will not proceed anymore. if (voip.currentCID != null && - voip.currentCID != VoipId(roomId: room.id, callId: callId)) return; + voip.currentCID != VoipId(roomId: room.id, callId: callId)) { + return; + } voip.currentCID = null; voip.incomingCallRoomId.removeWhere((key, value) => value == callId); } diff --git a/scripts/test.sh b/scripts/test.sh index 84207a80..3aa45815 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -6,7 +6,7 @@ if [ -n "$NO_OLM" ]; then tagFlag="-x olm" fi -dart test --concurrency=$thread_count --coverage=coverage_dir $tagFlag +dart test --concurrency=$thread_count --coverage=coverage_dir $tagFlag --fail-fast TEST_CODE=$? # lets you do more stuff like reporton diff --git a/test/client_test.dart b/test/client_test.dart index 162fb222..0cf30862 100644 --- a/test/client_test.dart +++ b/test/client_test.dart @@ -109,7 +109,7 @@ void main() { }); test('Login', () async { - matrix = Client( + final matrix = Client( 'testclient', httpClient: FakeMatrixApi(), databaseBuilder: getDatabase, diff --git a/test/encryption/encrypt_decrypt_room_message_test.dart b/test/encryption/encrypt_decrypt_room_message_test.dart index 357a4057..afa44c4e 100644 --- a/test/encryption/encrypt_decrypt_room_message_test.dart +++ b/test/encryption/encrypt_decrypt_room_message_test.dart @@ -61,7 +61,7 @@ void main() { senderId: client.userID!, ); final decryptedEvent = - await client.encryption!.decryptRoomEvent(roomId, encryptedEvent); + await client.encryption!.decryptRoomEvent(encryptedEvent); expect(decryptedEvent.type, 'm.room.message'); expect(decryptedEvent.content['msgtype'], 'm.text'); expect(decryptedEvent.content['text'], 'Hello foxies!'); @@ -80,7 +80,7 @@ void main() { senderId: client.userID!, ); final decryptedEvent = - await client.encryption!.decryptRoomEvent(roomId, encryptedEvent); + await client.encryption!.decryptRoomEvent(encryptedEvent); expect(decryptedEvent.type, 'm.room.message'); expect(decryptedEvent.content['msgtype'], 'm.text'); expect(decryptedEvent.content['text'], 'Hello foxies!'); @@ -98,12 +98,11 @@ void main() { senderId: '@alice:example.com', ); final decryptedEvent = - await client.encryption!.decryptRoomEvent(roomId, encryptedEvent); + await client.encryption!.decryptRoomEvent(encryptedEvent); expect(decryptedEvent.type, 'm.room.message'); expect(decryptedEvent.content['msgtype'], 'm.text'); expect(decryptedEvent.content['text'], 'Hello foxies!'); - await client.encryption! - .decryptRoomEvent(roomId, encryptedEvent, store: true); + await client.encryption!.decryptRoomEvent(encryptedEvent, store: true); }); test('dispose client', () async {