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

+6 -6
View File
@@ -83,8 +83,8 @@ pub(crate) async fn change_password_route(
body: Ruma<change_password::v3::Request>,
) -> Result<change_password::v3::Response> {
let identity = if let Some(identity) = body.identity.as_ref() {
// A signed-in user is trying to change their password, prompt them for their
// existing one
// A signed-in user is trying to change their password, prompt them for
// their existing one
services
.uiaa
@@ -99,10 +99,10 @@ pub(crate) async fn change_password_route(
)
.await?
} else {
// A signed-out user is trying to reset their password, prompt them for email
// confirmation. Note that we do not _send_ an email here, their client should
// have already hit `/account/password/requestToken` to send the email. We
// just validate it.
// A signed-out user is trying to reset their password, prompt them for
// email confirmation. Note that we do not _send_ an email here, their
// client should have already hit `/account/password/requestToken` to
// send the email. We just validate it.
services
.uiaa
+5 -4
View File
@@ -41,8 +41,8 @@ pub(crate) async fn register_route(
return Err!(Request(GuestAccessForbidden("Guests may not register on this server.")));
}
// Allow registration if it's enabled in the config file or if this is the first
// run (so the first user account can be created)
// Allow registration if it's enabled in the config file or if this is the
// first run (so the first user account can be created)
let allow_registration =
services.config.allow_registration || services.firstrun.is_first_run();
@@ -108,8 +108,9 @@ pub(crate) async fn register_route(
};
let (token, device) = if !body.inhibit_login {
// If UIAA is disabled, we can't create a device. In that case only appservices
// can reach this point in the first place, so we return an error for them.
// If UIAA is disabled, we can't create a device. In that case only
// appservices can reach this point in the first place, so we return
// an error for them.
if !services.config.oauth.compatibility_mode().uiaa_available() {
return Err!(Request(AppserviceLoginUnsupported(
"User-interactive appservice registration is not available on this server."
+2 -2
View File
@@ -247,8 +247,8 @@ pub(crate) async fn add_backup_keys_for_session_route(
| Ordering::Less => true,
| Ordering::Greater => false,
| Ordering::Equal => {
// If both have same `first_message_index`, prefer the one with lower
// `forwarded_count`
// If both have same `first_message_index`, prefer the one
// with lower `forwarded_count`
let old_forwarded_count = old_key
.get_field::<UInt>("forwarded_count")?
.unwrap_or(UInt::MAX);
+5 -3
View File
@@ -111,8 +111,9 @@ pub(crate) async fn upload_keys_route(
.await
.and_then(|keys| keys.deserialize().map_err(Into::into))
{
// NOTE: also serves as a workaround for a nheko bug which omits cross-signing
// NOTE: signatures when re-uploading the same DeviceKeys.
// NOTE: also serves as a workaround for a nheko bug which omits
// cross-signing NOTE: signatures when re-uploading the same
// DeviceKeys.
if existing_keys.keys == deser_device_keys.keys {
debug!(
%sender_user,
@@ -273,7 +274,8 @@ async fn uiaa_needed_to_upload_keys(
);
if let Some(existing_master_signing_key) = existing_master_signing_key {
// If a master key exists, UIAA is required if any of the keys are different.
// If a master key exists, UIAA is required if any of the keys are
// different.
master_signing_key != Some(existing_master_signing_key)
|| user_signing_key != existing_user_signing_key
+5 -4
View File
@@ -77,8 +77,9 @@ pub(crate) async fn invite_user_route(
.await;
// ignored invites aren't handled here
// since the recipient's membership should still be changed to `invite`.
// they're filtered out in the individual /sync handlers.
// since the recipient's membership should still be changed to
// `invite`. they're filtered out in the individual /sync
// handlers.
if matches!(recipient_filter_level, FilterLevel::Block) {
return Err!(Request(InviteBlocked(
"{recipient_user} has blocked invites from you."
@@ -190,8 +191,8 @@ pub(crate) async fn invite_helper(
.send_federation_request(recipient_user.server_name(), request)
.await?;
// We do not add the event_id field to the pdu here because of signature and
// hashes checks
// We do not add the event_id field to the pdu here because of signature
// and hashes checks
let (event_id, value) = gen_event_id_canonical_json(
&response.event,
&room_version_id
+18 -17
View File
@@ -190,10 +190,10 @@ async fn knock_room_by_id_helper(
}
}
// For knock_restricted rooms, check if the user meets the restricted conditions
// If they do, attempt to join instead of knock
// This is not mentioned in the spec, but should be allowable (we're allowed to
// auto-join invites to knocked rooms)
// For knock_restricted rooms, check if the user meets the restricted
// conditions If they do, attempt to join instead of knock
// This is not mentioned in the spec, but should be allowable (we're allowed
// to auto-join invites to knocked rooms)
let join_rule = services.rooms.state_accessor.get_join_rules(room_id).await;
if let JoinRule::KnockRestricted(restricted) = &join_rule {
@@ -226,9 +226,9 @@ async fn knock_room_by_id_helper(
"{sender_user} meets the restricted criteria in knock_restricted room \
{room_id}, attempting to join instead of knock"
);
// For this case, we need to drop the state lock and get a new one in
// join_room_by_id_helper We need to release the lock here and let
// join_room_by_id_helper acquire it again
// For this case, we need to drop the state lock and get a new one
// in join_room_by_id_helper We need to release the lock here and
// let join_room_by_id_helper acquire it again
drop(state_lock);
match services
.rooms
@@ -401,8 +401,8 @@ async fn knock_room_helper_local(
to_canonical_value(content).expect("event is valid, we just created it"),
);
// In order to create a compatible ref hash (EventID) the `hashes` field needs
// to be present
// In order to create a compatible ref hash (EventID) the `hashes` field
// needs to be present
services
.server_keys
.hash_and_sign_event(&mut knock_event_stub, &room_version_rules)?;
@@ -446,10 +446,11 @@ async fn knock_room_helper_local(
.map_err(|e| err!(BadServerResponse("Invalid knock event PDU: {e:?}")))?;
info!("Updating membership locally to knock state with provided stripped state events");
// TODO: this call does not appear to do anything because `update_membership`
// doesn't call `mark_as_knock`. investigate further, ideally with the aim of
// removing this call entirely -- Ginger thinks `update_membership` should only
// be called from `force_state` and `append_pdu`.
// TODO: this call does not appear to do anything because
// `update_membership` doesn't call `mark_as_knock`. investigate further,
// ideally with the aim of removing this call entirely -- Ginger thinks
// `update_membership` should only be called from `force_state` and
// `append_pdu`.
services
.rooms
.state_cache
@@ -524,8 +525,8 @@ async fn knock_room_helper_remote(
to_canonical_value(knock_content).expect("event is valid, we just created it"),
);
// In order to create a compatible ref hash (EventID) the `hashes` field needs
// to be present
// In order to create a compatible ref hash (EventID) the `hashes` field
// needs to be present
services
.server_keys
.hash_and_sign_event(&mut knock_event_stub, &room_version_rules)?;
@@ -671,8 +672,8 @@ async fn knock_room_helper_remote(
.await?;
info!("Setting final room state for new room");
// We set the room state after inserting the pdu, so that we never have a moment
// in time where events in the current room state do not exist
// We set the room state after inserting the pdu, so that we never have a
// moment in time where events in the current room state do not exist
services
.rooms
.state
+19 -15
View File
@@ -110,16 +110,16 @@ pub async fn leave_room(
otherwise `build_and_append_pdu` will take care of updating the state cache for us.
*/
// `leave_pdu` is the outlier `m.room.member` event which will be synced to the
// user. if it's None the sync handler will create a dummy PDU.
// `leave_pdu` is the outlier `m.room.member` event which will be synced to
// the user. if it's None the sync handler will create a dummy PDU.
let leave_pdu = if is_banned.or(is_disabled).await {
// case 1: the room is banned/disabled. we don't want to federate with another
// server to leave, so we can't create an outlier PDU.
// case 1: the room is banned/disabled. we don't want to federate with
// another server to leave, so we can't create an outlier PDU.
None
} else if dont_have_room.and(not_knocked).await {
// case 2: ask a remote server to assist us with leaving
// we always mark the room as left locally, regardless of if the federated leave
// failed
// we always mark the room as left locally, regardless of if the
// federated leave failed
remote_leave_room(services, user_id, room_id, reason.clone(), HashSet::new())
.await
@@ -159,12 +159,14 @@ pub async fn leave_room(
)
.await?;
// `build_and_append_pdu` calls `mark_as_left` internally, so we return early.
// `build_and_append_pdu` calls `mark_as_left` internally, so we
// return early.
return Ok(());
},
| Err(_) => {
// an exception to case 3 is if the user isn't even in the room they're trying
// to leave. this can happen if the client's caching is wrong.
// an exception to case 3 is if the user isn't even in the room
// they're trying to leave. this can happen if the client's
// caching is wrong.
debug_warn!(
"Trying to leave a room you are not a member of, marking room as left \
locally."
@@ -177,11 +179,13 @@ pub async fn leave_room(
.left_state(user_id, room_id)
.await
.inspect_err(|err| {
// `left_state` may return an Err if the user _is_ in the room they're
// trying to leave, but the membership cache is incorrect and
// `left_state` may return an Err if the user _is_ in
// the room they're trying to leave, but the
// membership cache is incorrect and
// they're cached as being joined. In this situation
// we save a `None` to the `roomuserid_leftcount` table, which generates
// and sends a dummy leave to the client.
// we save a `None` to the `roomuserid_leftcount` table,
// which generates and sends a dummy leave to the
// client.
warn!(
?err,
"Trying to leave room not cached as leave, sending dummy leave \
@@ -370,8 +374,8 @@ pub async fn remote_leave_room<S: ::std::hash::BuildHasher>(
// room v3 and above removed the "event_id" field from remote PDU format
leave_event_stub.remove("event_id");
// In order to create a compatible ref hash (EventID) the `hashes` field needs
// to be present
// In order to create a compatible ref hash (EventID) the `hashes` field
// needs to be present
services
.server_keys
.hash_and_sign_event(&mut leave_event_stub, &room_version_rules)?;
+4 -4
View File
@@ -40,8 +40,8 @@ pub(crate) async fn get_pushrules_all_route(
.and_then(|event| event.get("content").cloned())
.filter(CanonicalJsonValue::is_object)
else {
// user somehow has non-existent push rule event. recreate it and return server
// default silently
// user somehow has non-existent push rule event. recreate it and return
// server default silently
return recreate_push_rules_and_return(&services, sender_user).await;
};
@@ -111,8 +111,8 @@ pub(crate) async fn get_pushrules_global_route(
.and_then(|event| event.get("content").cloned())
.filter(CanonicalJsonValue::is_object)
else {
// user somehow has non-existent push rule event. recreate it and return server
// default silently
// user somehow has non-existent push rule event. recreate it and return
// server default silently
let global_ruleset = Ruleset::server_default(sender_user);
let event = PushRulesEvent::new(PushRulesEventContent::new(global_ruleset.clone()));
+2 -2
View File
@@ -48,8 +48,8 @@ pub(crate) async fn report_room_route(
delay_response().await;
// We log this early in case the room ID does actually exist, in which case
// admins who scan their logs can see the report and choose to investigate at
// their discretion.
// admins who scan their logs can see the report and choose to investigate
// at their discretion.
info!(
"Received room report by user {sender_user} for room {} with reason: \"{}\"",
body.room_id, body.reason
+13 -13
View File
@@ -90,15 +90,15 @@ pub(crate) async fn create_room_route(
};
let room_version_rules = room_version.rules().unwrap();
// For custom room IDs, if the user is creating a room with a v1 room ID format,
// we can just use that ID directly. However, if it's a custom *v2* room ID, we
// need to make sure that we don't generate one, which would in turn trick us
// into generating invalid v2 room events.
// For custom room IDs, if the user is creating a room with a v1 room ID
// format, we can just use that ID directly. However, if it's a custom *v2*
// room ID, we need to make sure that we don't generate one, which would in
// turn trick us into generating invalid v2 room events.
//
// expect_room_id is the custom room ID that the user is expecting - for v2
// formatted rooms, we check that the m.room.create event's generated room ID
// exactly matches this, and abort if it doesn't. Otherwise, we use it as the
// room ID itself.
// formatted rooms, we check that the m.room.create event's generated room
// ID exactly matches this, and abort if it doesn't. Otherwise, we use it
// as the room ID itself.
let expect_room_id = {
let body_ref = body.json_body.as_ref().unwrap();
if let Some(CanonicalJsonValue::String(room_id)) = body_ref
@@ -165,10 +165,10 @@ pub(crate) async fn create_room_route(
continue;
}
// if the recipient of the invite is local and has the sender blocked, error
// out. if the recipient is remote we can't tell yet, and if they're local and
// have the sender _ignored_ their invite will be filtered out in
// the handlers for the individual /sync endpoints
// if the recipient of the invite is local and has the sender blocked,
// error out. if the recipient is remote we can't tell yet, and if
// they're local and have the sender _ignored_ their invite will be
// filtered out in the handlers for the individual /sync endpoints
if services.globals.user_is_local(recipient_user)
&& matches!(
services
@@ -652,8 +652,8 @@ fn default_power_levels_content(
power_levels_content["events"]["m.poll.response"] =
serde_json::to_value(0).expect("0 is valid Value");
// synapse does this too. clients do not expose these permissions. it prevents
// default users from calling public rooms, for obvious reasons.
// synapse does this too. clients do not expose these permissions. it
// prevents default users from calling public rooms, for obvious reasons.
if *visibility == room::Visibility::Public {
power_levels_content["events"]["m.call.invite"] =
serde_json::to_value(50).expect("50 is valid Value");
+33 -25
View File
@@ -77,8 +77,8 @@ async fn update_parents(
continue; // Skip updating rooms the sender isn't in.
}
let state_lock = services.rooms.state.mutex.lock(parent_id.as_str()).await;
// We're now fetching state from the *space* that has the old room as a *child*.
// Follow along. This will be on the test.
// We're now fetching state from the *space* that has the old room as a
// *child*. Follow along. This will be on the test.
let Ok(child) = services
.rooms
.state_accessor
@@ -98,13 +98,15 @@ async fn update_parents(
);
})
else {
// If the space does not have a child event for this room, we can skip it
// If the space does not have a child event for this room, we can
// skip it
continue;
};
// ...the upgrading server SHOULD send a new m.space.child event with state_key
// set to the new room's ID, copying the order and suggested fields from the
// content of the m.space.child with state_key of the previous room ID.
// ...the upgrading server SHOULD send a new m.space.child event with
// state_key set to the new room's ID, copying the order and suggested
// fields from the content of the m.space.child with state_key of the
// previous room ID.
services
.rooms
.timeline
@@ -199,7 +201,8 @@ async fn update_children(
);
})
else {
// If the child does not have a parent event for this room, we can skip it.
// If the child does not have a parent event for this room, we can
// skip it.
continue;
};
@@ -228,9 +231,10 @@ async fn update_children(
))
.ok();
// If the previous m.space.parent event has canonical set to true in content,
// homeservers SHOULD update the old state event to set canonical to false,
// while setting it to true in the newly-sent m.space.parent event.
// If the previous m.space.parent event has canonical set to true in
// content, homeservers SHOULD update the old state event to set
// canonical to false, while setting it to true in the newly-sent
// m.space.parent event.
if parent.canonical {
services
.rooms
@@ -301,11 +305,12 @@ pub(crate) async fn upgrade_room_route(
return Err!(Request(Forbidden("Upgrading the admin room this way is not allowed.")));
}
// 1. Check that the user has permission to send m.room.tombstone events in the
// room.
// 1. Check that the user has permission to send m.room.tombstone events in
// the room.
let old_room_state_lock = services.rooms.state.mutex.lock(body.room_id.as_str()).await;
// Check tombstone permission by attempting to create (but not send) the event.
// Check tombstone permission by attempting to create (but not send) the
// event.
services
.rooms
.timeline
@@ -389,9 +394,9 @@ pub(crate) async fn upgrade_room_route(
let new_room_state_lock = if let Some(new_room_id) = replacement_room_id.as_ref() {
services.rooms.state.mutex.lock(new_room_id.as_str()).await
} else {
// NOTE: Using a hardcoded room ID for the temporary mutex means only one room
// can be created at a time. This is actually beneficial, as it reduces the
// risk of concurrent in-flight collisions.
// NOTE: Using a hardcoded room ID for the temporary mutex means only
// one room can be created at a time. This is actually beneficial, as
// it reduces the risk of concurrent in-flight collisions.
services.rooms.state.mutex.lock("!new-room").await
};
debug!("Upgrading {} to room version {}", &body.room_id, &body.new_version);
@@ -408,9 +413,9 @@ pub(crate) async fn upgrade_room_route(
.await?;
drop(new_room_state_lock);
// re-acquire a new lock with the new room ID.
// We don't actually need a state lock for sending the m.room.create event, but
// we get one anyway because the function requires it and I can't be bothered
// refactoring it.
// We don't actually need a state lock for sending the m.room.create event,
// but we get one anyway because the function requires it and I can't be
// bothered refactoring it.
let (replacement_room_id, new_room_state_lock) =
if new_version_rules.room_id_format == RoomIdFormatVersion::V2 {
let parsed_room_id = RoomId::new_v2(
@@ -470,8 +475,9 @@ pub(crate) async fn upgrade_room_route(
| Ok(v) => v.content().to_owned(),
| Err(_) => continue, // Skipping missing events.
};
// If this is a power levels event, and the new room version has creators,
// we need to make sure they dont appear in the users block of power levels.
// If this is a power levels event, and the new room version has
// creators, we need to make sure they dont appear in the users
// block of power levels.
if *event_type == StateEventType::RoomPowerLevels {
let creators = body
.additional_creators
@@ -550,8 +556,8 @@ pub(crate) async fn upgrade_room_route(
)?;
}
// 5. Send a `m.room.tombstone` event to the old room to indicate that it is not
// intended to be used any further.
// 5. Send a `m.room.tombstone` event to the old room to indicate that it is
// not intended to be used any further.
debug!(target=?body.room_id, "Sending tombstone to old room");
services
.rooms
@@ -577,7 +583,8 @@ pub(crate) async fn upgrade_room_route(
.get_room_power_levels(&body.room_id)
.await;
// Setting events_default and invite to the greater of 50 and users_default + 1
// Setting events_default and invite to the greater of 50 and users_default
// + 1
let new_level = max(
int!(50),
power_levels
@@ -591,7 +598,8 @@ pub(crate) async fn upgrade_room_route(
power_levels.events_default = new_level;
power_levels.invite = new_level;
// 6. Modify the power levels in the old room to prevent sending of events and
// 6. Modify the power levels in the old room to prevent sending of events
// and
// inviting new users
// Spec dictates that this is allowed to fail.
debug!(target=?body.room_id, ?new_level, "Raising power level in old room to lock it");
+2 -1
View File
@@ -222,7 +222,8 @@ pub(crate) async fn login_route(
.await?
};
// send client well-known if specified so the client knows to reconfigure itself
// send client well-known if specified so the client knows to reconfigure
// itself
let client_discovery_info: Option<DiscoveryInfo> = services
.server
.config
+3 -3
View File
@@ -15,9 +15,9 @@ pub(crate) async fn get_hierarchy_route(
State(services): State<crate::State>,
body: Ruma<get_hierarchy::v1::Request>,
) -> Result<get_hierarchy::v1::Response> {
// We don't do pagination for this route (and therefore ignore `limit`), since
// there's no reasonable way to handle a space hierarchy changing during
// pagination.
// We don't do pagination for this route (and therefore ignore `limit`),
// since there's no reasonable way to handle a space hierarchy changing
// during pagination.
// Default to MAX_MAX_DEPTH when the client doesn't specify one, so an
// unbounded traversal can never happen.
+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);
}
+2 -2
View File
@@ -62,8 +62,8 @@ where
let body = {
let max_body_size = services.server.config.max_request_size;
// Check if the Content-Length header is present and valid, saves us streaming
// the response into memory
// Check if the Content-Length header is present and valid, saves us
// streaming the response into memory
if let Some(content_length) = parts.headers.get(http::header::CONTENT_LENGTH) {
if let Ok(content_length) = content_length
.to_str()
+2 -2
View File
@@ -85,8 +85,8 @@ pub(crate) async fn get_backfill_route(
pdu.remove_transaction_id().log_err().ok();
// Add age, as this is specified
pdu.add_age().log_err().ok();
// It's not clear if we should strip or add any more data, leave as is.
// In particular: Redaction?
// It's not clear if we should strip or add any more data, leave as
// is. In particular: Redaction?
Ok(pdu)
})
.try_filter_map(|pdu| async move {
+11 -11
View File
@@ -75,8 +75,8 @@ pub(crate) async fn create_invite_route(
.expect("must have create event in invite state by this point");
// We can now perform the banned remote server check with the create event.
// N.B. this checks the sender field, which is technically incorrect for rooms
// v10 and below. This usually isn't the case though so sue me
// N.B. this checks the sender field, which is technically incorrect for
// rooms v10 and below. This usually isn't the case though so sue me
let creator = create_event_json
.get("sender")
.and_then(|v| v.as_str())
@@ -122,8 +122,8 @@ pub(crate) async fn create_invite_route(
return Err!(Request(Forbidden("Invite rejected by antispam service.")));
}
// If we're already in the room, ensure that neither the origin nor ourselves
// are ACL'd.
// If we're already in the room, ensure that neither the origin nor
// ourselves are ACL'd.
let resident = services
.rooms
.state_cache
@@ -159,15 +159,15 @@ pub(crate) async fn create_invite_route(
// If we are active in the room, the remote server will notify us about the
// join/invite through /send. If we are not in the room, we need to manually
// record the invited state for client /sync through update_membership(), and
// send the invite PDU to the relevant appservices.
// record the invited state for client /sync through update_membership(),
// and send the invite PDU to the relevant appservices.
if !resident {
// We will start by recording the room's create event as an outlier.
// This will allow us to recognise it later in case the sender revokes the
// invite over federation later. We could store more state from the invite
// request, but we will get that during send_join anyway.
// This is safe to just add directly as an outlier as we already auth checked it
// during validation.
// This will allow us to recognise it later in case the sender revokes
// the invite over federation later. We could store more state from
// the invite request, but we will get that during send_join anyway.
// This is safe to just add directly as an outlier as we already auth
// checked it during validation.
services
.rooms
.outlier
+13 -11
View File
@@ -99,8 +99,8 @@ pub(crate) async fn create_join_event_template_route(
);
let join_authorized_via_users_server: Option<OwnedUserId> = {
if is_joined || is_invited {
// User is already joined or invited and consequently does not need an
// authorising user
// User is already joined or invited and consequently does not need
// an authorising user
None
} else if !room_version_rules.authorization.restricted_join_rule {
// room version does not support restricted join rules
@@ -223,8 +223,9 @@ pub(crate) async fn user_can_perform_restricted_join(
.server_in_room(services.globals.server_name(), &membership.room_id)
.await
{
// Since we can't check this room, mark could_satisfy as false
// so that we can return M_UNABLE_TO_AUTHORIZE_JOIN later.
// Since we can't check this room, mark could_satisfy as
// false so that we can return
// M_UNABLE_TO_AUTHORIZE_JOIN later.
could_satisfy = false;
continue;
}
@@ -252,7 +253,8 @@ pub(crate) async fn user_can_perform_restricted_join(
| Err(_) => Err!(Request(Forbidden("Antispam rejected join request."))),
},
| _ => {
// We don't recognise this join rule, so we cannot satisfy the request.
// We don't recognise this join rule, so we cannot satisfy the
// request.
could_satisfy = false;
debug_info!(
"Unsupported allow rule in restricted join for room {}: {:?}",
@@ -264,16 +266,16 @@ pub(crate) async fn user_can_perform_restricted_join(
}
if could_satisfy {
// We were able to check all the restrictions and can be certain that the
// prospective member is not permitted to join.
// We were able to check all the restrictions and can be certain that
// the prospective member is not permitted to join.
Err!(Request(Forbidden(
"You do not belong to any of the rooms or spaces required to join this room."
)))
} else {
// We were unable to check all the restrictions. This usually means we aren't in
// one of the rooms this one is restricted to, ergo can't check its state for
// the user's membership, and consequently the user *might* be able to join if
// they ask another server.
// We were unable to check all the restrictions. This usually means we
// aren't in one of the rooms this one is restricted to, ergo can't
// check its state for the user's membership, and consequently the
// user *might* be able to join if they ask another server.
Err!(Request(UnableToAuthorizeJoin(
"You do not belong to any of the recognised rooms or spaces required to join this \
room, but this server is unable to verify every requirement. You may be able to \
+6 -6
View File
@@ -173,9 +173,9 @@ async fn process_inbound_transaction(
debug!(pdus = body.pdus.len(), edus = body.edus.len(), "Processing transaction",);
// We have an additional panic catch here because if there's a panic in the
// handle, the sender will effectively become defederated until restart after
// never being removed from the tracking map. Ideally the handle function
// doesn't panic, but when has "ideally" ever worked for us.
// handle, the sender will effectively become defederated until restart
// after never being removed from the tracking map. Ideally the handle
// function doesn't panic, but when has "ideally" ever worked for us.
let handle_result =
std::panic::AssertUnwindSafe(handle(&services, &body.identity, pdus, edus))
.catch_unwind()
@@ -319,9 +319,9 @@ async fn handle_room(
.into_iter()
.map(|(_, event_id, value)| (event_id, value))
.collect();
// Try to sort PDUs by their dependencies, but fall back to arbitrary order on
// failure (e.g., cycles). This is best-effort; proper ordering is the sender's
// responsibility.
// Try to sort PDUs by their dependencies, but fall back to arbitrary order
// on failure (e.g., cycles). This is best-effort; proper ordering is the
// sender's responsibility.
let sorted_event_ids = build_local_dag(&pdu_map, DagBuilderTree::PrevEvents)
.await
.unwrap_or_else(|e| {
+2 -2
View File
@@ -58,8 +58,8 @@ async fn create_join_event(
.acl_check(origin, room_id)
.await?;
// We need to return the state prior to joining, let's keep a reference to that
// here
// We need to return the state prior to joining, let's keep a reference to
// that here
let shortstatehash = services
.rooms
.state