chore: Reformat with latest nightly

This commit is contained in:
Ginger committed 2026-09-01 12:55:05 -04:00
1 parent 03d669594e
commit 9fbabe2210
113 files changed
+981 -831

No files matched your search

+9 -7
View File
@@ -67,14 +67,16 @@ async fn load_timeline(
})?;
if last_timeline_count <= starting_count {
// no messages have been sent in this room since `starting_count`
// no messages have been sent in this room since
// `starting_count`
return Ok(TimelinePdus::default());
}
// for incremental sync, stream from the DB all PDUs which were sent after
// `starting_count` but before `ending_count`, including `ending_count` but
// not `starting_count`. this code is pretty similar to the initial sync
// branch, they're separate to allow for future optimization
// for incremental sync, stream from the DB all PDUs which were sent
// after `starting_count` but before `ending_count`, including
// `ending_count` but not `starting_count`. this code is pretty
// similar to the initial sync branch, they're separate to allow
// for future optimization
services
.rooms
.timeline
@@ -99,8 +101,8 @@ async fn load_timeline(
.boxed()
},
| None => {
// For initial sync, stream from the DB all PDUs before and including
// `ending_count` in reverse order
// For initial sync, stream from the DB all PDUs before and
// including `ending_count` in reverse order
services
.rooms
.timeline
+37 -32
View File
@@ -148,10 +148,11 @@ async fn build_ephemeral(
SyncContext { syncing_user, last_sync_end_count, .. }: SyncContext<'_>,
room_id: &RoomId,
) -> Result<Ephemeral> {
// note: some of the futures below are boxed. this is because, without the box,
// rustc produces over thirty inscrutable errors in `mod.rs` at the call-site
// of `load_joined_room`. I don't know why boxing them fixes this -- it seems
// to be related to the async closures and borrowing from the sync context.
// note: some of the futures below are boxed. this is because, without the
// box, rustc produces over thirty inscrutable errors in `mod.rs` at the
// call-site of `load_joined_room`. I don't know why boxing them fixes this
// -- it seems to be related to the async closures and borrowing from the
// sync context.
// collect updates to read receipts
let receipt_events = services
@@ -176,8 +177,8 @@ async fn build_ephemeral(
| Some(last_sync_end_count) => {
match services.rooms.typing.last_typing_update(room_id).await {
| Ok(last_typing_update) => {
// update the typing list if the users typing have changed since the last
// sync
// update the typing list if the users typing have
// changed since the last sync
last_typing_update > last_sync_end_count
},
| Err(err) => {
@@ -288,7 +289,8 @@ async fn build_sticky_events(
.flatten()
.map(PduCount::Normal);
// nothing older than this can still be sticky, so the walk back never goes far
// nothing older than this can still be sticky, so the walk back never goes
// far
let oldest_sticky_ts = now.saturating_sub(sticky::MAX_DURATION_MS);
let mut events = Vec::new();
@@ -393,14 +395,14 @@ async fn build_state_and_timeline(
// history
let prev_batch = timeline.pdus.front().map(at!(0));
// note: we always indicate a limited timeline if the syncing user just joined
// the room, to indicate to the client that it should request backfill (and to
// copy Synapse's behavior). for federated room joins, the `timeline` will
// usually only include the syncing user's join event.
// note: we always indicate a limited timeline if the syncing user just
// joined the room, to indicate to the client that it should request
// backfill (and to copy Synapse's behavior). for federated room joins, the
// `timeline` will usually only include the syncing user's join event.
let limited = timeline.limited || joined_since_last_sync;
// filter out ignored events from the timeline and convert the PDUs into Ruma's
// AnySyncTimelineEvent type
// filter out ignored events from the timeline and convert the PDUs into
// Ruma's AnySyncTimelineEvent type
let filtered_timeline = timeline
.pdus
.into_iter()
@@ -442,8 +444,8 @@ async fn fetch_shortstatehashes(
room_id: &RoomId,
) -> Result<ShortStateHashes> {
// the room state currently.
// TODO: this should be the room state as of `current_count`, but there's no way
// to get that right now.
// TODO: this should be the room state as of `current_count`, but there's no
// way to get that right now.
let current_shortstatehash = services
.rooms
.state
@@ -484,7 +486,8 @@ async fn fetch_shortstatehashes(
}
},
| None => {
// No events have been sent since the last sync, or we just joined this room
// No events have been sent since the last sync, or we just
// joined this room
None
},
}
@@ -561,12 +564,13 @@ async fn build_state_events(
} = shortstatehashes;
if timeline.pdus.is_empty() {
// If the timeline is empty there can't possibly be any changes to the state
// If the timeline is empty there can't possibly be any changes to the
// state
return Ok(vec![]);
}
// the user IDs of members whose membership needs to be sent to the client, if
// lazy-loading is enabled.
// the user IDs of members whose membership needs to be sent to the client,
// if lazy-loading is enabled.
let lazily_loaded_members =
prepare_lazily_loaded_members(services, sync_context, room_id, timeline.senders()).await;
@@ -619,14 +623,14 @@ async fn build_notification_counts(
) -> Result<Option<UnreadNotificationsCount>> {
// determine whether to actually update the notification counts
let should_send_notification_counts = async {
// if we're going to sync some timeline events, the notification count has
// definitely changed to include them
// if we're going to sync some timeline events, the notification count
// has definitely changed to include them
if !timeline.pdus.is_empty() {
return true;
}
// if this is an initial sync, we need to send notification counts because the
// client doesn't know what they are yet
// if this is an initial sync, we need to send notification counts
// because the client doesn't know what they are yet
let Some(last_sync_end_count) = last_sync_end_count else {
return true;
};
@@ -637,8 +641,8 @@ async fn build_notification_counts(
.last_notification_read(syncing_user, room_id)
.await;
// if the syncing user has read the events we sent during the last sync, we need
// to send a new notification count on this sync.
// if the syncing user has read the events we sent during the last sync,
// we need to send a new notification count on this sync.
if last_notification_read > last_sync_end_count {
return true;
}
@@ -683,8 +687,8 @@ async fn check_joined_since_last_sync(
SyncContext { syncing_user, .. }: SyncContext<'_>,
) -> Result<bool> {
let Some(last_sync_end_shortstatehash) = last_sync_end_shortstatehash else {
// For initial syncs always return false, since there's no "last sync" for the
// user to have joined since.
// For initial syncs always return false, since there's no "last sync"
// for the user to have joined since.
return Ok(false);
};
@@ -703,8 +707,8 @@ async fn check_joined_since_last_sync(
// TODO: If the requesting user got state-reset out of the room, this
// will be `true` when it shouldn't be. this function should never be called
// in that situation, but it may be if the membership cache didn't get updated.
// the root cause of this needs to be addressed
// in that situation, but it may be if the membership cache didn't get
// updated. the root cause of this needs to be addressed
let joined_since_last_sync =
membership_during_previous_sync.is_none_or(|content: RoomMemberEventContent| {
content.membership != MembershipState::Join
@@ -729,7 +733,8 @@ async fn build_room_summary(
state_events: &[PduEvent],
joined_since_last_sync: bool,
) -> Result<Option<RoomSummary>> {
// determine whether any events in the state or timeline are membership events.
// determine whether any events in the state or timeline are membership
// events.
let are_syncing_membership_events = timeline
.pdus
.iter()
@@ -863,8 +868,8 @@ async fn build_device_list_updates(
.state_get(current_shortstatehash, &StateEventType::RoomEncryption, "")
.is_ok();
// initial syncs don't include device updates, and rooms which aren't encrypted
// don't affect them, so return early in either of those cases
// initial syncs don't include device updates, and rooms which aren't
// encrypted don't affect them, so return early in either of those cases
if last_sync_end_count.is_none() || !(is_encrypted_room.await) {
return Ok(DeviceListUpdates::new());
}
+16 -14
View File
@@ -59,22 +59,23 @@ pub(super) async fn load_left_room(
.await
.ok()
else {
// if we get here, the membership cache is incorrect, likely due to a state
// reset
// if we get here, the membership cache is incorrect, likely due to a
// state reset
debug_warn!("attempting to sync left room but no left count exists");
return Ok(None);
};
// return early if we haven't gotten to this leave yet.
// this can happen if the user leaves while a sync response is being generated
// this can happen if the user leaves while a sync response is being
// generated
if current_count < left_count {
return Ok(None);
}
// return early if:
// - this is an initial sync and the room filter doesn't include leaves, or
// - this is an incremental sync, and we've already synced the leave, and the
// room filter doesn't include leaves
// - this is an incremental sync, and we've already synced the leave, and
// the room filter doesn't include leaves
if last_sync_end_count.is_none_or(|last_sync_end_count| last_sync_end_count >= left_count)
&& !filter.room.include_leave
{
@@ -110,8 +111,8 @@ pub(super) async fn load_left_room(
(TimelinePdus::default(), vec![leave_membership_event])
},
| Some(leave_membership_event) => {
// we have this room in our DB, and can fetch the state and timeline from when
// the user left.
// we have this room in our DB, and can fetch the state and timeline
// from when the user left.
let leave_state_key = syncing_user;
debug_assert_eq!(
@@ -120,9 +121,9 @@ pub(super) async fn load_left_room(
"leave PDU should be for the user requesting the sync"
);
// the shortstatehash of the state _immediately before_ the syncing user left
// this room. the state represented here _does not_ include
// `leave_membership_event`.
// the shortstatehash of the state _immediately before_ the syncing
// user left this room. the state represented here _does not_
// include `leave_membership_event`.
let leave_shortstatehash = services
.rooms
.state_accessor
@@ -246,9 +247,9 @@ async fn build_left_state_and_timeline(
)
.await?;
// the timeline index can lag behind the leave PDU, so `load_timeline` may omit
// it. we already hold the leave event, so ensure it's always synced to the
// client.
// the timeline index can lag behind the leave PDU, so `load_timeline` may
// omit it. we already hold the leave event, so ensure it's always synced
// to the client.
let leave_synced = timeline
.pdus
.iter()
@@ -294,7 +295,8 @@ async fn build_left_state_and_timeline(
[1]: https://github.com/matrix-org/matrix-js-sdk/issues/5071
*/
// `state` should only ever include one membership event for the syncing user
// `state` should only ever include one membership event for the syncing
// user
let membership_event_index = state.iter().position(|pdu| {
*pdu.event_type() == TimelineEventType::RoomMember
&& pdu.state_key() == Some(syncing_user.as_str())
+7 -6
View File
@@ -41,7 +41,8 @@ pub(super) async fn build_state_initial(
let event_ids_in_timeline: HashSet<_> =
timeline.pdus.iter().map(|pdu| &pdu.1.event_id).collect();
// load the keys and event IDs of the state events at the start of the timeline
// load the keys and event IDs of the state events at the start of the
// timeline
let (shortstatekeys, event_ids): (Vec<_>, Vec<_>) = services
.rooms
.state_accessor
@@ -167,11 +168,11 @@ pub(super) async fn build_state_incremental<'a>(
.await;
if !use_state_after {
// If state_after isn't enabled, filter out state events which also exist
// in the timeline. If splits exist in the DAG, this may not be exactly the same
// thing as the state diff ending at the start of the timeline, but Synapse
// also does this and it's technically more useful behavior anyway.
// See: https://github.com/element-hq/synapse/issues/16941
// If state_after isn't enabled, filter out state events which also
// exist in the timeline. If splits exist in the DAG, this may not be
// exactly the same thing as the state diff ending at the start of the
// timeline, but Synapse also does this and it's technically more
// useful behavior anyway. See: https://github.com/element-hq/synapse/issues/16941
for (_, pdu) in &timeline.pdus {
state_event_ids.remove(pdu.event_id());
+12 -10
View File
@@ -205,8 +205,8 @@ async fn collect_sync_response(
globalsince: u64,
known_rooms: &KnownRooms,
) -> Result<SyncCollection> {
// Bounds every read below and becomes the `pos` returned to the client. Zero
// would be echoed back as a request for an initial sync.
// Bounds every read below and becomes the `pos` returned to the client.
// Zero would be echoed back as a request for an initial sync.
let next_batch = services.globals.current_count()?.max(1);
let all_joined_rooms = services
@@ -1132,8 +1132,8 @@ async fn collect_sticky_events(
.iter()
.filter(|room_id| joined_room_ids.contains(*room_id))
{
// a room the client has not seen before needs its whole backlog, which a
// single stream position cannot express
// a room the client has not seen before needs its whole backlog, which
// a single stream position cannot express
let initial = todo_rooms
.get(room_id)
.is_some_and(|&(_, _, roomsince)| roomsince == 0);
@@ -1462,7 +1462,8 @@ where
.await
.is_ok();
// Skip the state diff only: `room_keys_changed` below must run for every room.
// Skip the state diff only: `room_keys_changed` below must run for
// every room.
if let Some(since_shortstatehash) =
since_shortstatehash.filter(|since| *since != current_shortstatehash)
{
@@ -1533,8 +1534,8 @@ where
}
},
| MembershipState::Leave => {
// Write down users that have left encrypted rooms we
// are in
// Write down users that have left
// encrypted rooms we are in
left_encrypted_users.insert(user_id.clone());
},
| _ => {},
@@ -1544,7 +1545,8 @@ where
}
}
if joined_since_last_sync || new_encrypted_room {
// If the user is in a new encrypted room, give them all joined users
// If the user is in a new encrypted room, give them all
// joined users
device_list_changes.extend(
services
.rooms
@@ -1580,8 +1582,8 @@ where
let dont_share_encrypted_room =
!share_encrypted_room(services, sender_user, &user_id, None).await;
// If the user doesn't share an encrypted room with the target anymore, we need
// to tell them
// If the user doesn't share an encrypted room with the target anymore,
// we need to tell them
if dont_share_encrypted_room {
device_list_left.insert(user_id);
}