Merge pull request #1896 from famedly/nico/fix-leave-invite-chain

fix: leave->invite in the same sync would hide the invite
This commit is contained in:
Nicolas Werner 2024-07-31 21:03:23 +02:00 committed by GitHub
commit 820a0c53dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 72 additions and 6 deletions

View File

@ -49,7 +49,6 @@ jobs:
path: coverage_dir/ path: coverage_dir/
retention-days: 1 retention-days: 1
coverage: coverage:
runs-on: arm-ubuntu-latest-16core runs-on: arm-ubuntu-latest-16core
steps: steps:
@ -61,6 +60,10 @@ jobs:
architecture: "arm64" architecture: "arm64"
- name: Run tests - name: Run tests
run: | 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 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 ./scripts/test.sh
- uses: actions/upload-artifact@v4 - uses: actions/upload-artifact@v4
@ -70,7 +73,6 @@ jobs:
path: coverage_dir/ path: coverage_dir/
retention-days: 1 retention-days: 1
merge_converage: merge_converage:
if: ${{ !cancelled() }} if: ${{ !cancelled() }}
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -2037,14 +2037,18 @@ class Client extends MatrixApi {
if (join != null) { if (join != null) {
await _handleRooms(join, direction: direction); await _handleRooms(join, direction: direction);
} }
final invite = sync.rooms?.invite; // We need to handle leave before invite. If you decline an invite and
if (invite != null) { // then get another invite to the same room, Synapse will include the
await _handleRooms(invite, direction: direction); // 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; final leave = sync.rooms?.leave;
if (leave != null) { if (leave != null) {
await _handleRooms(leave, direction: direction); await _handleRooms(leave, direction: direction);
} }
final invite = sync.rooms?.invite;
if (invite != null) {
await _handleRooms(invite, direction: direction);
}
} }
for (final newPresence in sync.presence ?? <Presence>[]) { for (final newPresence in sync.presence ?? <Presence>[]) {
final cachedPresence = CachedPresence.fromMatrixEvent(newPresence); final cachedPresence = CachedPresence.fromMatrixEvent(newPresence);

View File

@ -709,6 +709,66 @@ void main() {
await client.database?.clearCache(); await client.database?.clearCache();
await client.dispose(closeDatabase: true); 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 { test('ownProfile', () async {
final client = await getClient(); final client = await getClient();
await client.abortSync(); await client.abortSync();