mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
chore: Clippy fixes
This commit is contained in:
@@ -38,6 +38,7 @@ pub(super) fn dispatch(services: Arc<Services>, command: CommandInput) -> Proces
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all, name = "admin", level = "info")]
|
||||
#[allow(clippy::result_large_err)]
|
||||
async fn handle_command(services: Arc<Services>, command: CommandInput) -> ProcessorResult {
|
||||
AssertUnwindSafe(Box::pin(process_command(services, &command)))
|
||||
.catch_unwind()
|
||||
|
||||
@@ -806,7 +806,7 @@ pub(super) async fn put_room_tag(
|
||||
.account_data
|
||||
.get_room(&room_id, &user_id, RoomAccountDataEventType::Tag)
|
||||
.await
|
||||
.unwrap_or(TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
||||
.unwrap_or_else(|_| TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
||||
|
||||
tags_event
|
||||
.content
|
||||
@@ -843,7 +843,7 @@ pub(super) async fn delete_room_tag(
|
||||
.account_data
|
||||
.get_room(&room_id, &user_id, RoomAccountDataEventType::Tag)
|
||||
.await
|
||||
.unwrap_or(TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
||||
.unwrap_or_else(|_| TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
||||
|
||||
tags_event.content.tags.remove(&tag.clone().into());
|
||||
|
||||
@@ -873,7 +873,7 @@ pub(super) async fn get_room_tags(&self, user_id: String, room_id: OwnedRoomId)
|
||||
.account_data
|
||||
.get_room(&room_id, &user_id, RoomAccountDataEventType::Tag)
|
||||
.await
|
||||
.unwrap_or(TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
||||
.unwrap_or_else(|_| TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
||||
|
||||
self.write_str(&format!("```\n{:#?}\n```", tags_event.content.tags))
|
||||
.await
|
||||
|
||||
@@ -24,7 +24,7 @@ pub(crate) async fn list_rooms(
|
||||
.iter_ids()
|
||||
.filter_map(|room_id| async move {
|
||||
if !services.rooms.metadata.is_banned(&room_id).await {
|
||||
Some(room_id.to_owned())
|
||||
Some(room_id.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
@@ -173,8 +173,8 @@ pub(crate) async fn change_password_route(
|
||||
.get_pusher_device(&pushkey)
|
||||
.await
|
||||
.ok()
|
||||
.filter(|pusher_device| pusher_device != body.sender_device())
|
||||
.is_some()
|
||||
.as_ref()
|
||||
.is_some_and(|pusher_device| pusher_device != body.sender_device())
|
||||
.then_some(pushkey)
|
||||
})
|
||||
.for_each(async |pushkey| {
|
||||
|
||||
@@ -314,7 +314,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
||||
.collect()
|
||||
.await;
|
||||
|
||||
all_rooms.sort_by(|l, r| r.num_joined_members.cmp(&l.num_joined_members));
|
||||
all_rooms.sort_by_key(|r| std::cmp::Reverse(r.num_joined_members));
|
||||
|
||||
let total_room_count_estimate = UInt::try_from(all_rooms.len())
|
||||
.unwrap_or_else(|_| uint!(0))
|
||||
|
||||
@@ -431,7 +431,7 @@ where
|
||||
add_unsigned_device_display_name(&mut keys, metadata, include_display_names)
|
||||
.map_err(|_| err!(Database("invalid device keys in database")))?;
|
||||
|
||||
container.insert(device_id.to_owned(), keys);
|
||||
container.insert(device_id.clone(), keys);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ pub(crate) async fn ban_user_route(
|
||||
.unwrap_or_else(|_| RoomMemberEventContent::new(MembershipState::Ban));
|
||||
|
||||
content.membership = MembershipState::Ban;
|
||||
content.reason = body.reason.clone();
|
||||
content.reason.clone_from(&body.reason);
|
||||
content.displayname = None;
|
||||
content.avatar_url = None;
|
||||
content.is_direct = None;
|
||||
|
||||
@@ -426,7 +426,9 @@ async fn join_room_by_id_helper_remote(
|
||||
join_content.avatar_url = services.users.avatar_url(sender_user).await.ok();
|
||||
join_content.blurhash = services.users.blurhash(sender_user).await.ok();
|
||||
join_content.reason = reason;
|
||||
join_content.join_authorized_via_users_server = join_authorized_via_users_server.clone();
|
||||
join_content
|
||||
.join_authorized_via_users_server
|
||||
.clone_from(&join_authorized_via_users_server);
|
||||
|
||||
join_event_stub.insert(
|
||||
"content".to_owned(),
|
||||
@@ -752,7 +754,7 @@ async fn join_room_by_id_helper_local(
|
||||
content.displayname = services.users.displayname(sender_user).await.ok();
|
||||
content.avatar_url = services.users.avatar_url(sender_user).await.ok();
|
||||
content.blurhash = services.users.blurhash(sender_user).await.ok();
|
||||
content.reason = reason.clone();
|
||||
content.reason.clone_from(&reason);
|
||||
content.join_authorized_via_users_server = auth_user;
|
||||
|
||||
// Try normal join first
|
||||
@@ -861,7 +863,7 @@ async fn make_join_request(
|
||||
);
|
||||
return Err(e);
|
||||
},
|
||||
| ErrorKind::Forbidden { .. } => {
|
||||
| ErrorKind::Forbidden => {
|
||||
warn!("{remote_server} refuses to let us join: {e}.");
|
||||
return Err(e);
|
||||
},
|
||||
|
||||
@@ -39,7 +39,7 @@ pub(crate) async fn kick_user_route(
|
||||
}
|
||||
|
||||
event.membership = MembershipState::Leave;
|
||||
event.reason = body.reason.clone();
|
||||
event.reason.clone_from(&body.reason);
|
||||
event.is_direct = None;
|
||||
event.join_authorized_via_users_server = None;
|
||||
event.third_party_invite = None;
|
||||
|
||||
@@ -347,7 +347,7 @@ async fn knock_room_helper_local(
|
||||
content.displayname = services.users.displayname(sender_user).await.ok();
|
||||
content.avatar_url = services.users.avatar_url(sender_user).await.ok();
|
||||
content.blurhash = services.users.blurhash(sender_user).await.ok();
|
||||
content.reason = reason.clone();
|
||||
content.reason.clone_from(&reason.clone());
|
||||
|
||||
// Try normal knock first
|
||||
let Err(error) = services
|
||||
|
||||
@@ -119,5 +119,5 @@ fn membership_filter<Pdu: Event>(
|
||||
return None;
|
||||
}
|
||||
|
||||
return Some(pdu);
|
||||
Some(pdu)
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ pub(crate) async fn unban_user_route(
|
||||
}
|
||||
|
||||
current_member_content.membership = MembershipState::Leave;
|
||||
current_member_content.reason = body.reason.clone();
|
||||
current_member_content.reason.clone_from(&body.reason);
|
||||
current_member_content.join_authorized_via_users_server = None;
|
||||
current_member_content.third_party_invite = None;
|
||||
current_member_content.is_direct = None;
|
||||
|
||||
@@ -36,7 +36,7 @@ pub(crate) async fn get_profile_route(
|
||||
return Err!(Request(NotFound("This user's profile could not be fetched.")));
|
||||
};
|
||||
|
||||
Ok(get_profile::v3::Response::from_iter(profile.into_iter()))
|
||||
Ok(get_profile::v3::Response::from_iter(profile))
|
||||
}
|
||||
|
||||
pub(crate) async fn get_profile_field_route(
|
||||
@@ -115,7 +115,7 @@ async fn fetch_full_profile(
|
||||
services.users.clear_profile(user_id).await;
|
||||
|
||||
for (field, value) in response.iter() {
|
||||
let Ok(value) = ProfileFieldValue::new(&field, value.to_owned()) else {
|
||||
let Ok(value) = ProfileFieldValue::new(field, value.to_owned()) else {
|
||||
// Skip malformed fields
|
||||
continue;
|
||||
};
|
||||
@@ -123,7 +123,7 @@ async fn fetch_full_profile(
|
||||
set_profile_field(services, user_id, ProfileFieldChange::Set(value)).await;
|
||||
}
|
||||
|
||||
Some(BTreeMap::from_iter(response.into_iter()))
|
||||
Some(BTreeMap::from_iter(response))
|
||||
}
|
||||
|
||||
async fn fetch_profile_field(
|
||||
@@ -192,7 +192,7 @@ pub(crate) async fn get_local_profile(
|
||||
profile.insert(key, value);
|
||||
}
|
||||
|
||||
return profile;
|
||||
profile
|
||||
}
|
||||
|
||||
pub(crate) async fn get_local_profile_field(
|
||||
@@ -238,13 +238,13 @@ enum ProfileFieldChange {
|
||||
impl ProfileFieldChange {
|
||||
fn field_name(&self) -> ProfileFieldName {
|
||||
match self {
|
||||
| &ProfileFieldChange::Delete(ref name) => name.clone(),
|
||||
| &ProfileFieldChange::Set(ref value) => value.field_name(),
|
||||
| &Self::Delete(ref name) => name.clone(),
|
||||
| &Self::Set(ref value) => value.field_name(),
|
||||
}
|
||||
}
|
||||
|
||||
fn value(&self) -> Option<Value> {
|
||||
if let &ProfileFieldChange::Set(ref value) = self {
|
||||
if let Self::Set(value) = self {
|
||||
Some(value.value().into_owned())
|
||||
} else {
|
||||
None
|
||||
|
||||
@@ -238,8 +238,8 @@ pub(crate) async fn create_room_route(
|
||||
.as_object()
|
||||
.unwrap()
|
||||
.get("origin_server_ts")
|
||||
.and_then(|value| value.as_integer())
|
||||
.map(|value| value.into())
|
||||
.and_then(ruma::CanonicalJsonValue::as_integer)
|
||||
.map(Into::into)
|
||||
.and_then(|value: i64| value.try_into().ok())
|
||||
.map(MilliSecondsSinceUnixEpoch);
|
||||
|
||||
@@ -266,7 +266,7 @@ pub(crate) async fn create_room_route(
|
||||
| None => {
|
||||
let as_room_id = create_event_id.as_str().replace('$', "!");
|
||||
trace!("Creating room with v12 room ID {as_room_id}");
|
||||
RoomId::parse(&as_room_id)?.to_owned()
|
||||
RoomId::parse(&as_room_id)?.clone()
|
||||
},
|
||||
};
|
||||
drop(state_lock);
|
||||
@@ -342,7 +342,7 @@ pub(crate) async fn create_room_route(
|
||||
let power_levels_content = default_power_levels_content(
|
||||
body.power_level_content_override
|
||||
.as_ref()
|
||||
.map(|power_levels| power_levels.cast_ref()),
|
||||
.map(Raw::cast_ref),
|
||||
&body.visibility,
|
||||
power_levels_to_grant,
|
||||
creators,
|
||||
|
||||
@@ -90,7 +90,7 @@ pub(crate) async fn room_initial_sync_route(
|
||||
|
||||
Ok(assign!(Response::new(room_id.to_owned()), {
|
||||
account_data: vec![],
|
||||
state: state.into(),
|
||||
state: state,
|
||||
messages: messages.chunk.is_empty().or_some(messages),
|
||||
visibility: visibility.into(),
|
||||
membership,
|
||||
|
||||
@@ -50,7 +50,7 @@ pub(crate) async fn search_events_route(
|
||||
|
||||
if let Some(criteria) = &body.search_categories.room_events {
|
||||
result_categories.room_events =
|
||||
category_room_events(&services, sender_user, next_batch, criteria).await?
|
||||
category_room_events(&services, sender_user, next_batch, criteria).await?;
|
||||
}
|
||||
|
||||
Ok(Response::new(result_categories))
|
||||
|
||||
@@ -170,7 +170,8 @@ pub(crate) async fn handle_login(
|
||||
debug!("Got password login type");
|
||||
|
||||
let user_id_or_localpart = match (identifier, user) {
|
||||
| (Some(UserIdentifier::Matrix(MatrixUserIdentifier { user, .. })), _) => user,
|
||||
| (Some(UserIdentifier::Matrix(MatrixUserIdentifier { user, .. })), _)
|
||||
| (None, Some(user)) => user,
|
||||
| (Some(UserIdentifier::Email(EmailUserIdentifier { address, .. })), _) => {
|
||||
let email = Address::try_from(address.to_owned())
|
||||
.map_err(|_| err!(Request(InvalidParam("Email is malformed"))))?;
|
||||
@@ -181,7 +182,6 @@ pub(crate) async fn handle_login(
|
||||
.await
|
||||
.ok_or_else(|| err!(Request(Forbidden("Invalid identifier or password"))))?
|
||||
},
|
||||
| (None, Some(user)) => user,
|
||||
| _ => {
|
||||
return Err!(Request(InvalidParam("Identifier type not recognized")));
|
||||
},
|
||||
|
||||
@@ -941,13 +941,13 @@ where
|
||||
)
|
||||
.await
|
||||
{
|
||||
device_list_changes.insert(user_id.to_owned());
|
||||
device_list_changes.insert(user_id.clone());
|
||||
}
|
||||
},
|
||||
| MembershipState::Leave => {
|
||||
// Write down users that have left encrypted rooms we
|
||||
// are in
|
||||
left_encrypted_users.insert(user_id.to_owned());
|
||||
left_encrypted_users.insert(user_id.clone());
|
||||
},
|
||||
| _ => {},
|
||||
}
|
||||
@@ -968,7 +968,7 @@ where
|
||||
// already
|
||||
.filter_map(async |user_id| {
|
||||
share_encrypted_room(services, sender_user, &user_id, Some(room_id))
|
||||
.map(|res| res.or_some(user_id.to_owned()))
|
||||
.map(|res| res.or_some(user_id.clone()))
|
||||
.await
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
|
||||
@@ -27,7 +27,7 @@ pub(crate) async fn update_tag_route(
|
||||
.account_data
|
||||
.get_room(&body.room_id, sender_user, RoomAccountDataEventType::Tag)
|
||||
.await
|
||||
.unwrap_or(TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
||||
.unwrap_or_else(|_| TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
||||
|
||||
tags_event
|
||||
.content
|
||||
@@ -62,7 +62,7 @@ pub(crate) async fn delete_tag_route(
|
||||
.account_data
|
||||
.get_room(&body.room_id, sender_user, RoomAccountDataEventType::Tag)
|
||||
.await
|
||||
.unwrap_or(TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
||||
.unwrap_or_else(|_| TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
||||
|
||||
tags_event.content.tags.remove(&body.tag.clone().into());
|
||||
|
||||
@@ -94,7 +94,7 @@ pub(crate) async fn get_tags_route(
|
||||
.account_data
|
||||
.get_room(&body.room_id, sender_user, RoomAccountDataEventType::Tag)
|
||||
.await
|
||||
.unwrap_or(TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
||||
.unwrap_or_else(|_| TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
||||
|
||||
Ok(get_tags::v3::Response::new(tags_event.content.tags))
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ pub(crate) async fn send_event_to_device_route(
|
||||
event_type,
|
||||
event.clone(),
|
||||
)
|
||||
.await
|
||||
.await;
|
||||
})
|
||||
.await;
|
||||
},
|
||||
|
||||
@@ -36,7 +36,7 @@ pub(super) trait CheckAuth: AuthScheme {
|
||||
async move {
|
||||
let route = TypeId::of::<R>();
|
||||
|
||||
let output = Self::extract_authentication(&incoming_request).map_err(|err| {
|
||||
let output = Self::extract_authentication(incoming_request).map_err(|err| {
|
||||
err!(Request(Unauthorized(warn!(
|
||||
"Failed to extract authorization: {}",
|
||||
err.into()
|
||||
@@ -85,8 +85,8 @@ impl CheckAuth for ServerSignatures {
|
||||
let keys: PubKeyMap = [(output.origin.as_str().into(), keys)].into();
|
||||
|
||||
match output.verify_request(request, destination, &keys) {
|
||||
| Ok(_) => Ok(Auth {
|
||||
origin: Some(output.origin.to_owned()),
|
||||
| Ok(()) => Ok(Auth {
|
||||
origin: Some(output.origin.clone()),
|
||||
..Default::default()
|
||||
}),
|
||||
| Err(err) =>
|
||||
@@ -123,11 +123,11 @@ impl CheckAuth for AccessToken {
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(Auth {
|
||||
Ok(Auth {
|
||||
sender_user: Some(sender_user),
|
||||
sender_device: Some(sender_device),
|
||||
..Default::default()
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ pub(crate) async fn create_invite_route(
|
||||
|
||||
if let Err(e) = services
|
||||
.antispam
|
||||
.user_may_invite(sender_user.to_owned(), recipient_user.clone(), body.room_id.clone())
|
||||
.user_may_invite(sender_user.clone(), recipient_user.clone(), body.room_id.clone())
|
||||
.await
|
||||
{
|
||||
warn!("Antispam rejected invite: {e:?}");
|
||||
|
||||
@@ -56,7 +56,7 @@ pub(crate) async fn get_server_keys_route(
|
||||
}
|
||||
|
||||
fn valid_until_ts() -> MilliSecondsSinceUnixEpoch {
|
||||
let dur = Duration::from_secs(86400 * 7);
|
||||
let dur = Duration::from_hours(168);
|
||||
let timepoint = timepoint_from_now(dur).expect("SystemTime should not overflow");
|
||||
MilliSecondsSinceUnixEpoch::from_system_time(timepoint).expect("UInt should not overflow")
|
||||
}
|
||||
|
||||
@@ -744,7 +744,7 @@ async fn handle_edu_direct_to_device_event(
|
||||
ev_type,
|
||||
event.clone(),
|
||||
)
|
||||
.await
|
||||
.await;
|
||||
})
|
||||
.await;
|
||||
},
|
||||
|
||||
@@ -212,11 +212,7 @@ impl Service {
|
||||
root_summary.inaccessible_children.into_iter().collect();
|
||||
|
||||
// TODO refactor this with Vec::peek_mut once it's stabilized
|
||||
loop {
|
||||
let Some(layer) = queue.last_mut() else {
|
||||
break;
|
||||
};
|
||||
|
||||
while let Some(layer) = queue.last_mut() {
|
||||
let Some(SpaceChild { room_id, via }) = layer.pop() else {
|
||||
// If this layer is empty, discard it from the queue and continue
|
||||
queue.pop();
|
||||
|
||||
Reference in New Issue
Block a user