stop putting comments in the middle of call chains

`rustfmt` doesn't handle this very well.
This commit is contained in:
Charles Hall 2024-05-16 01:08:08 -07:00
parent 1911ad34d9
commit 05be778fbb
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
10 changed files with 35 additions and 38 deletions

View file

@ -266,7 +266,6 @@ pub(crate) async fn get_public_rooms_filtered_helper(
}) })
}) })
.transpose()? .transpose()?
// url is now an Option<String> so we must flatten
.flatten(), .flatten(),
join_rule: services() join_rule: services()
.rooms .rooms
@ -336,7 +335,6 @@ pub(crate) async fn get_public_rooms_filtered_helper(
true true
} }
}) })
// We need to collect all, so we can sort by member count
.collect(); .collect();
all_rooms.sort_by(|l, r| r.num_joined_members.cmp(&l.num_joined_members)); all_rooms.sort_by(|l, r| r.num_joined_members.cmp(&l.num_joined_members));

View file

@ -165,7 +165,7 @@ pub(crate) async fn get_message_events_route(
.user_can_see_event(sender_user, &body.room_id, &pdu.event_id) .user_can_see_event(sender_user, &body.room_id, &pdu.event_id)
.unwrap_or(false) .unwrap_or(false)
}) })
.take_while(|&(k, _)| Some(k) != to) // Stop at `to` .take_while(|&(k, _)| Some(k) != to)
.collect(); .collect();
for (_, event) in &events_after { for (_, event) in &events_after {
@ -217,7 +217,7 @@ pub(crate) async fn get_message_events_route(
.user_can_see_event(sender_user, &body.room_id, &pdu.event_id) .user_can_see_event(sender_user, &body.room_id, &pdu.event_id)
.unwrap_or(false) .unwrap_or(false)
}) })
.take_while(|&(k, _)| Some(k) != to) // Stop at `to` .take_while(|&(k, _)| Some(k) != to)
.collect(); .collect();
for (_, event) in &events_before { for (_, event) in &events_before {

View file

@ -22,9 +22,9 @@ pub(crate) async fn get_hierarchy_route(
.try_into() .try_into()
.expect("0-100 should fit in usize"); .expect("0-100 should fit in usize");
// Plus one to skip the space room itself
let max_depth = usize::try_from(body.max_depth.map(|x| x.min(uint!(10))).unwrap_or(uint!(3))) let max_depth = usize::try_from(body.max_depth.map(|x| x.min(uint!(10))).unwrap_or(uint!(3)))
.expect("0-10 should fit in usize") .expect("0-10 should fit in usize")
// Skip the space room itself
+ 1; + 1;
services() services()

View file

@ -211,7 +211,6 @@ async fn send_state_event_for_key_helper(
.rooms .rooms
.alias .alias
.resolve_local_alias(&alias)? .resolve_local_alias(&alias)?
// Make sure it's the right room
.filter(|room| room == room_id) .filter(|room| room == room_id)
.is_none() .is_none()
{ {

View file

@ -678,7 +678,6 @@ async fn load_joined_room(
} }
}) })
.filter_map(Result::ok) .filter_map(Result::ok)
// Filter for possible heroes
.flatten() .flatten()
{ {
if heroes.contains(&hero) || hero == sender_user.as_str() { if heroes.contains(&hero) || hero == sender_user.as_str() {

View file

@ -117,13 +117,13 @@ impl service::rooms::user::Data for KeyValueDatabase {
self.userroomid_joined self.userroomid_joined
.scan_prefix(prefix) .scan_prefix(prefix)
.map(|(key, _)| { .map(|(key, _)| {
// Plus one because the room id starts AFTER the separator
let roomid_index = key let roomid_index = key
.iter() .iter()
.enumerate() .enumerate()
.find(|(_, &b)| b == 0xff) .find(|(_, &b)| b == 0xff)
.ok_or_else(|| Error::bad_database("Invalid userroomid_joined in db."))? .ok_or_else(|| Error::bad_database("Invalid userroomid_joined in db."))?
.0 .0
// +1 because the room id starts AFTER the separator
+ 1; + 1;
let room_id = key[roomid_index..].to_vec(); let room_id = key[roomid_index..].to_vec();

View file

@ -828,9 +828,9 @@ impl service::users::Data for KeyValueDatabase {
let mut last = prefix.clone(); let mut last = prefix.clone();
last.extend_from_slice(&until.to_be_bytes()); last.extend_from_slice(&until.to_be_bytes());
// Include last
for (key, _) in self for (key, _) in self
.todeviceid_events .todeviceid_events
// this includes last
.iter_from(&last, true) .iter_from(&last, true)
.take_while(move |(k, _)| k.starts_with(&prefix)) .take_while(move |(k, _)| k.starts_with(&prefix))
.map(|(key, _)| { .map(|(key, _)| {

View file

@ -378,29 +378,6 @@ fn routes(config: &Config) -> Router {
.ruma_route(client_server::send_state_event_for_key_route) .ruma_route(client_server::send_state_event_for_key_route)
.ruma_route(client_server::get_state_events_route) .ruma_route(client_server::get_state_events_route)
.ruma_route(client_server::get_state_events_for_key_route) .ruma_route(client_server::get_state_events_for_key_route)
// Ruma doesn't have support for multiple paths for a single endpoint yet, and these routes
// share one Ruma request / response type pair with {get,send}_state_event_for_key_route
.route(
"/_matrix/client/r0/rooms/:room_id/state/:event_type",
get(client_server::get_state_events_for_empty_key_route)
.put(client_server::send_state_event_for_empty_key_route),
)
.route(
"/_matrix/client/v3/rooms/:room_id/state/:event_type",
get(client_server::get_state_events_for_empty_key_route)
.put(client_server::send_state_event_for_empty_key_route),
)
// These two endpoints allow trailing slashes
.route(
"/_matrix/client/r0/rooms/:room_id/state/:event_type/",
get(client_server::get_state_events_for_empty_key_route)
.put(client_server::send_state_event_for_empty_key_route),
)
.route(
"/_matrix/client/v3/rooms/:room_id/state/:event_type/",
get(client_server::get_state_events_for_empty_key_route)
.put(client_server::send_state_event_for_empty_key_route),
)
.ruma_route(client_server::sync_events_route) .ruma_route(client_server::sync_events_route)
.ruma_route(client_server::sync_events_v4_route) .ruma_route(client_server::sync_events_v4_route)
.ruma_route(client_server::get_context_route) .ruma_route(client_server::get_context_route)
@ -431,7 +408,34 @@ fn routes(config: &Config) -> Router {
.ruma_route(client_server::get_relating_events_with_rel_type_and_event_type_route) .ruma_route(client_server::get_relating_events_with_rel_type_and_event_type_route)
.ruma_route(client_server::get_relating_events_with_rel_type_route) .ruma_route(client_server::get_relating_events_with_rel_type_route)
.ruma_route(client_server::get_relating_events_route) .ruma_route(client_server::get_relating_events_route)
.ruma_route(client_server::get_hierarchy_route) .ruma_route(client_server::get_hierarchy_route);
// Ruma doesn't have support for multiple paths for a single endpoint yet, and these routes
// share one Ruma request / response type pair with {get,send}_state_event_for_key_route.
// These two endpoints also allow trailing slashes.
let router = router
.route(
"/_matrix/client/r0/rooms/:room_id/state/:event_type",
get(client_server::get_state_events_for_empty_key_route)
.put(client_server::send_state_event_for_empty_key_route),
)
.route(
"/_matrix/client/v3/rooms/:room_id/state/:event_type",
get(client_server::get_state_events_for_empty_key_route)
.put(client_server::send_state_event_for_empty_key_route),
)
.route(
"/_matrix/client/r0/rooms/:room_id/state/:event_type/",
get(client_server::get_state_events_for_empty_key_route)
.put(client_server::send_state_event_for_empty_key_route),
)
.route(
"/_matrix/client/v3/rooms/:room_id/state/:event_type/",
get(client_server::get_state_events_for_empty_key_route)
.put(client_server::send_state_event_for_empty_key_route),
);
let router = router
.route( .route(
"/_matrix/client/r0/rooms/:room_id/initialSync", "/_matrix/client/r0/rooms/:room_id/initialSync",
get(initial_sync), get(initial_sync),

View file

@ -61,10 +61,10 @@ impl Service {
//TODO: Fix ruma: match body.dir { //TODO: Fix ruma: match body.dir {
match ruma::api::Direction::Backward { match ruma::api::Direction::Backward {
ruma::api::Direction::Forward => { ruma::api::Direction::Forward => {
// TODO: should be relations_after
let events_after: Vec<_> = services() let events_after: Vec<_> = services()
.rooms .rooms
.pdu_metadata .pdu_metadata
// TODO: should be relations_after
.relations_until(sender_user, room_id, target, from)? .relations_until(sender_user, room_id, target, from)?
.filter(|r| { .filter(|r| {
r.as_ref().map_or(true, |(_, pdu)| { r.as_ref().map_or(true, |(_, pdu)| {
@ -91,15 +91,14 @@ impl Service {
.user_can_see_event(sender_user, room_id, &pdu.event_id) .user_can_see_event(sender_user, room_id, &pdu.event_id)
.unwrap_or(false) .unwrap_or(false)
}) })
// Stop at `to`
.take_while(|&(k, _)| Some(k) != to) .take_while(|&(k, _)| Some(k) != to)
.collect(); .collect();
next_token = events_after.last().map(|(count, _)| count).copied(); next_token = events_after.last().map(|(count, _)| count).copied();
// Reversed because relations are always most recent first
let events_after: Vec<_> = events_after let events_after: Vec<_> = events_after
.into_iter() .into_iter()
// relations are always most recent first
.rev() .rev()
.map(|(_, pdu)| pdu.to_message_like_event()) .map(|(_, pdu)| pdu.to_message_like_event())
.collect(); .collect();
@ -140,7 +139,6 @@ impl Service {
.user_can_see_event(sender_user, room_id, &pdu.event_id) .user_can_see_event(sender_user, room_id, &pdu.event_id)
.unwrap_or(false) .unwrap_or(false)
}) })
// Stop at `to`
.take_while(|&(k, _)| Some(k) != to) .take_while(|&(k, _)| Some(k) != to)
.collect(); .collect();

View file

@ -371,7 +371,6 @@ impl Service {
.map_err(|_| Error::bad_database("Invalid room avatar event in database.")) .map_err(|_| Error::bad_database("Invalid room avatar event in database."))
}) })
.transpose()? .transpose()?
// url is now an Option<String> so we must flatten
.flatten(), .flatten(),
join_rule: { join_rule: {
let join_rule = services() let join_rule = services()