From ee51d4357fdcf3700c028527c7fc6dae40ec2d18 Mon Sep 17 00:00:00 2001 From: Ginger Date: Wed, 5 Nov 2025 17:40:14 -0500 Subject: [PATCH] fix(sync/v3): Do not include the last membership event when syncing left rooms --- src/api/client/sync/mod.rs | 1 + src/api/client/sync/v3/left.rs | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/api/client/sync/mod.rs b/src/api/client/sync/mod.rs index 18041232..930a393d 100644 --- a/src/api/client/sync/mod.rs +++ b/src/api/client/sync/mod.rs @@ -39,6 +39,7 @@ impl TimelinePdus { } } +/// Load up to `limit` PDUs in the range (starting_count, ending_count]. async fn load_timeline( services: &Services, sender_user: &UserId, diff --git a/src/api/client/sync/v3/left.rs b/src/api/client/sync/v3/left.rs index 1a6590ad..7342a6ec 100644 --- a/src/api/client/sync/v3/left.rs +++ b/src/api/client/sync/v3/left.rs @@ -137,20 +137,21 @@ pub(super) async fn load_left_room( // if the user went from `join` to `leave`, they should be able to view the // timeline. - let timeline_start_count = if let Some(last_sync_end_count) = - last_sync_end_count - { - // for incremental syncs, start the timeline after `since` - PduCount::Normal(last_sync_end_count) - } else { - // for initial syncs, start the timeline at the previous membership event - services - .rooms - .timeline - .get_pdu_count(&prev_member_event.event_id) - .await? - .saturating_sub(1) - }; + let timeline_start_count = + if let Some(last_sync_end_count) = last_sync_end_count { + // for incremental syncs, start the timeline after `since` + PduCount::Normal(last_sync_end_count) + } else { + // for initial syncs, start the timeline after the previous membership + // event. we don't want to include the membership event itself + // because clients get confused when they see a `join` + // membership event in a `leave` room. + services + .rooms + .timeline + .get_pdu_count(&prev_member_event.event_id) + .await? + }; // end the timeline at the user's leave event let timeline_end_count = services