From 3d92428b7e6f980c69b49d0134fa39490f6d05fb Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 31 Jul 2024 19:01:12 +0200 Subject: [PATCH 1/2] fix: leave->invite in the same sync would hide the invite Synapse includes the room in both sections if you have both an invite->leave and a leave->invite transition in one sync response. Transitions in the other order are only included once (in the leave section) it seems, so this should work correctly in all cases. Fixes https://github.com/famedly/product-management/issues/2283 --- lib/src/client.dart | 12 ++++++--- test/client_test.dart | 60 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index 41875642..960bd832 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -2037,14 +2037,18 @@ class Client extends MatrixApi { if (join != null) { await _handleRooms(join, direction: direction); } - final invite = sync.rooms?.invite; - if (invite != null) { - await _handleRooms(invite, direction: direction); - } + // We need to handle leave before invite. If you decline an invite and + // then get another invite to the same room, Synapse will include the + // room both in invite and leave. If you get an invite and then leave, it + // will only be included in leave. final leave = sync.rooms?.leave; if (leave != null) { await _handleRooms(leave, direction: direction); } + final invite = sync.rooms?.invite; + if (invite != null) { + await _handleRooms(invite, direction: direction); + } } for (final newPresence in sync.presence ?? []) { final cachedPresence = CachedPresence.fromMatrixEvent(newPresence); diff --git a/test/client_test.dart b/test/client_test.dart index 6324f1cc..3ec967fb 100644 --- a/test/client_test.dart +++ b/test/client_test.dart @@ -709,6 +709,66 @@ void main() { await client.database?.clearCache(); await client.dispose(closeDatabase: true); }); + test('leaveThenInvite should be invited', () async { + // Synapse includes a room in both invite and leave if you leave and get + // reinvited while you are offline. The other direction only contains the + // room in leave. Verify that we actually store the invite in the first + // case. See also + // https://github.com/famedly/product-management/issues/2283 + final client = await getClient(); + await client.abortSync(); + client.rooms.clear(); + await client.database?.clearCache(); + + final roomId = '!inviteLeaveRoom:example.com'; + await client.handleSync( + SyncUpdate( + nextBatch: 'ABCDEF', + rooms: RoomsUpdate( + invite: { + roomId: InvitedRoomUpdate( + inviteState: [ + StrippedStateEvent( + type: EventTypes.RoomMember, + senderId: '@bob:example.com', + stateKey: client.userID, + content: { + 'membership': 'invite', + }, + ), + ], + ), + }, + leave: { + roomId: LeftRoomUpdate( + state: [ + MatrixEvent( + type: EventTypes.RoomMember, + senderId: client.userID!, + stateKey: client.userID, + originServerTs: DateTime.now(), + eventId: + '\$abcdefwsjaskdfabsjfhabfsjgbahsjfkgbasjffsajfgsfd', + content: { + 'membership': 'leave', + }, + ), + ], + ), + }, + ), + ), + ); + + final room = client.getRoomById(roomId); + + expect(room?.membership, Membership.invite); + + await client.abortSync(); + client.rooms.clear(); + await client.database?.clearCache(); + await client.dispose(closeDatabase: true); + }); test('ownProfile', () async { final client = await getClient(); await client.abortSync(); From de5f4542185825c873f39046e9c22c4052277a59 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 31 Jul 2024 20:18:51 +0200 Subject: [PATCH 2/2] fix: don't restart github action service after apt install By default apt-get seems to restart services now, but that restarts the github actions runner and cancels our job... Add the github actions service to the exluded services. See also https://discourse.ubuntu.com/t/needrestart-changes-in-ubuntu-24-04-service-restarts/44671 --- .github/workflows/app.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/app.yml b/.github/workflows/app.yml index 360a8071..de872201 100644 --- a/.github/workflows/app.yml +++ b/.github/workflows/app.yml @@ -49,7 +49,6 @@ jobs: path: coverage_dir/ retention-days: 1 - coverage: runs-on: arm-ubuntu-latest-16core steps: @@ -61,6 +60,10 @@ jobs: architecture: "arm64" - name: Run tests run: | + # Prevent restarting the github actions service on package upgrades + # See https://discourse.ubuntu.com/t/needrestart-changes-in-ubuntu-24-04-service-restarts/44671 + echo '$nrconf{override_rc}{qr(^actions.runner.*.service$)} = 0;' | sudo tee /etc/needrestart/conf.d/githubactions.conf + sudo apt-get update && sudo apt-get install --no-install-recommends --no-install-suggests -y lcov libsqlite3-0 libsqlite3-dev libolm3 libssl3 ./scripts/test.sh - uses: actions/upload-artifact@v4 @@ -70,7 +73,6 @@ jobs: path: coverage_dir/ retention-days: 1 - merge_converage: if: ${{ !cancelled() }} runs-on: ubuntu-latest