diff --git a/changelog.d/+left-room-sync.bugfix.md b/changelog.d/+left-room-sync.bugfix.md new file mode 100644 index 000000000..909b39639 --- /dev/null +++ b/changelog.d/+left-room-sync.bugfix.md @@ -0,0 +1 @@ +Fixed left/banned rooms sometimes not coming down sync. diff --git a/src/api/client/sync/v3/left.rs b/src/api/client/sync/v3/left.rs index c0f22e48f..cabaa7762 100644 --- a/src/api/client/sync/v3/left.rs +++ b/src/api/client/sync/v3/left.rs @@ -215,12 +215,18 @@ async fn build_left_state_and_timeline( .get_pdu_count(&prev_membership_event.event_id) .await?; - // end the timeline at the user's leave event - let timeline_end_count = services + // end the timeline at the user's leave event. for federated events, the + // membership cache is updated before the PDU is appended to the timeline, + // so the leave event may not be in the timeline index yet. + let timeline_end_count = match services .rooms .timeline .get_pdu_count(leave_membership_event.event_id()) - .await?; + .await + { + | Ok(count) => count, + | Err(_) => services.rooms.timeline.last_timeline_count(room_id).await?, + }; // limit the timeline using the same logic as for joined rooms let timeline_limit = filter