chore: Clippy fixes

This commit is contained in:
Ginger
2026-04-13 17:31:52 -04:00
parent e185f56f3a
commit e70004c98f
53 changed files with 110 additions and 118 deletions
+1 -1
View File
@@ -395,7 +395,7 @@ impl Service {
let mut stream = admin_users;
while let Some(user_id) = stream.next().await {
generated_admin_list.push(user_id.to_owned());
generated_admin_list.push(user_id.clone());
}
}
}
+1 -1
View File
@@ -72,7 +72,7 @@ impl Service {
None,
server_user,
GlobalAccountDataEventType::PushRules.to_string().into(),
&serde_json::to_value(&GlobalAccountDataEvent::new(PushRulesEventContent::new(
&serde_json::to_value(GlobalAccountDataEvent::new(PushRulesEventContent::new(
ruleset,
)))
.expect("to json value always works"),
+1 -1
View File
@@ -289,7 +289,7 @@ fn handle_error(
/// requests for either versioned or unversioned endpoints, by requiring that
/// the `Input` of the `PathBuilder` of the endpoint implements
/// `FederationPathBuilderInput`.
pub(crate) trait FederationPathBuilderInput {
pub trait FederationPathBuilderInput {
fn create() -> Self;
}
+1 -1
View File
@@ -210,7 +210,7 @@ pub async fn get_all(
.ignore_err()
.ready_for_each(|((_, _, room_id, session_id), key_backup_data): KeyVal<'_>| {
rooms
.entry(room_id.into())
.entry(room_id)
.or_insert_with(default)
.sessions
.insert(session_id.into(), key_backup_data);
+3 -3
View File
@@ -215,7 +215,7 @@ async fn handle_thumbnail_file(
.await
.map(|()| FileMeta {
content: Some(content.file),
content_type: content.content_type.map(Into::into),
content_type: content.content_type,
content_disposition: Some(content_disposition),
})
}
@@ -243,7 +243,7 @@ async fn handle_content_file(
.await
.map(|()| FileMeta {
content: Some(content.file),
content_type: content.content_type.map(Into::into),
content_type: content.content_type,
content_disposition: Some(content_disposition),
})
}
@@ -364,7 +364,7 @@ pub async fn fetch_remote_thumbnail_legacy(
body.width,
body.height,
);
request.method = body.method.clone();
request.method.clone_from(&body.method);
request.allow_remote = body.allow_remote;
request.allow_redirect = body.allow_redirect;
request.animated = body.animated;
+2 -12
View File
@@ -610,19 +610,9 @@ async fn fix_readreceiptid_readreceipt_duplicates(services: &Services) -> Result
.expect_ok()
.ready_for_each(|key: Key| {
let (ref room_id, _, ref user_id) = key;
let last_room = cur_room.replace(
room_id
.as_str()
.try_into()
.expect("invalid room_id in database"),
);
let last_room = cur_room.replace(room_id.as_str().into());
let last_user = cur_user.replace(
user_id
.as_str()
.try_into()
.expect("invalid user_id in database"),
);
let last_user = cur_user.replace(user_id.as_str().into());
let is_dup = cur_room == last_room && cur_user == last_user;
if is_dup {
+1 -1
View File
@@ -20,7 +20,7 @@ pub struct ResetTokenInfo {
impl ResetTokenInfo {
// one hour
const MAX_TOKEN_AGE: Duration = Duration::from_secs(60 * 60);
const MAX_TOKEN_AGE: Duration = Duration::from_hours(1);
pub fn is_valid(&self) -> bool {
let now = SystemTime::now();
+1 -1
View File
@@ -48,7 +48,7 @@ impl Presence {
let now = utils::millis_since_unix_epoch();
let last_active_ago = Some(UInt::new_saturating(now.saturating_sub(self.last_active_ts)));
let mut content = PresenceEventContent::new(self.state.clone());
content.status_msg = self.status_msg.clone();
content.status_msg.clone_from(&self.status_msg);
content.currently_active = Some(self.currently_active);
content.last_active_ago = last_active_ago;
content.displayname = users.displayname(user_id).await.ok();
+1 -5
View File
@@ -13,7 +13,7 @@ use ipaddress::IPAddress;
use ruma::{
DeviceId, OwnedDeviceId, RoomId, UInt, UserId,
api::{
IncomingResponse, MatrixVersion, OutgoingRequest,
IncomingResponse, OutgoingRequest,
auth_scheme::NoAuthentication,
client::push::{Pusher, PusherKind, set_pusher},
path_builder::SinglePath,
@@ -42,7 +42,6 @@ struct Services {
globals: Dep<globals::Service>,
config: Dep<config::Service>,
client: Dep<client::Service>,
state: Dep<rooms::state::Service>,
state_accessor: Dep<rooms::state_accessor::Service>,
state_cache: Dep<rooms::state_cache::Service>,
users: Dep<users::Service>,
@@ -65,7 +64,6 @@ impl crate::Service for Service {
globals: args.depend::<globals::Service>("globals"),
client: args.depend::<client::Service>("client"),
config: args.depend::<config::Service>("config"),
state: args.depend::<rooms::state::Service>("rooms::state"),
state_accessor: args
.depend::<rooms::state_accessor::Service>("rooms::state_accessor"),
state_cache: args.depend::<rooms::state_cache::Service>("rooms::state_cache"),
@@ -200,8 +198,6 @@ impl Service {
+ Debug
+ Send,
{
const VERSIONS: [MatrixVersion; 1] = [MatrixVersion::V1_0];
let dest = dest.replace(self.services.globals.notification_push_path(), "");
trace!("Push gateway destination: {dest}");
+2 -2
View File
@@ -53,9 +53,9 @@ impl Resolver {
opts.cache_size = config.dns_cache_entries as usize;
opts.preserve_intermediates = true;
opts.negative_min_ttl = Some(Duration::from_secs(config.dns_min_ttl_nxdomain));
opts.negative_max_ttl = Some(Duration::from_secs(60 * 60 * 24 * 30));
opts.negative_max_ttl = Some(Duration::from_hours(720));
opts.positive_min_ttl = Some(Duration::from_secs(config.dns_min_ttl));
opts.positive_max_ttl = Some(Duration::from_secs(60 * 60 * 24 * 7));
opts.positive_max_ttl = Some(Duration::from_hours(168));
opts.timeout = Duration::from_secs(config.dns_timeout);
opts.attempts = config.dns_attempts as usize;
opts.try_tcp_on_error = config.dns_tcp_fallback;
+1 -1
View File
@@ -7,7 +7,7 @@ use conduwuit::{
utils::{ReadyExt, stream::TryIgnore},
};
use database::{Deserialized, Ignore, Interfix, Map};
use futures::{Stream, StreamExt, TryFutureExt};
use futures::{Stream, StreamExt};
use ruma::{
OwnedRoomAliasId, OwnedRoomId, OwnedServerName, OwnedUserId, RoomAliasId, RoomId,
RoomOrAliasId, UserId, events::StateEventType,
@@ -14,7 +14,7 @@ use futures::{
use ruma::{
CanonicalJsonValue, EventId, OwnedUserId, RoomId, ServerName, UserId,
events::{
StateEventType, TimelineEventType,
TimelineEventType,
room::member::{MembershipState, RoomMemberEventContent},
},
};
@@ -209,7 +209,7 @@ pub async fn handle_incoming_pdu<'a>(
}
// Fetch create event
let ref create_event = self
let create_event = &self
.services
.state_accessor
.get_room_create_event(room_id)
+2 -2
View File
@@ -278,8 +278,8 @@ where
let (short_state_keys, short_event_ids): pair_of!(Vec<_>) = short_state.unzip().await;
StreamExt::zip(
self.multi_get_statekey_from_short(stream::iter(short_state_keys.into_iter())),
self.multi_get_eventid_from_short(stream::iter(short_event_ids.into_iter())),
self.multi_get_statekey_from_short(stream::iter(short_state_keys)),
self.multi_get_eventid_from_short(stream::iter(short_event_ids)),
)
.ready_filter_map(|state_event| match state_event {
| (Ok(state_key), Ok(event_id)) => Some(Ok((state_key, event_id))),
+2 -4
View File
@@ -98,18 +98,16 @@ impl Service {
pub async fn is_world_readable(&self, room_id: &RoomId) -> bool {
self.room_state_get_content(room_id, &StateEventType::RoomHistoryVisibility, "")
.await
.map(|c: RoomHistoryVisibilityEventContent| {
.is_ok_and(|c: RoomHistoryVisibilityEventContent| {
c.history_visibility == HistoryVisibility::WorldReadable
})
.unwrap_or(false)
}
/// Checks if guests are able to join a given room
pub async fn guest_can_join(&self, room_id: &RoomId) -> bool {
self.room_state_get_content(room_id, &StateEventType::RoomGuestAccess, "")
.await
.map(|c: RoomGuestAccessEventContent| c.guest_access == GuestAccess::CanJoin)
.unwrap_or(false)
.is_ok_and(|c: RoomGuestAccessEventContent| c.guest_access == GuestAccess::CanJoin)
}
/// Gets the primary alias from canonical alias event
+1 -1
View File
@@ -254,7 +254,7 @@ impl Service {
};
summaries.push(summary.summary);
inaccessible_children.extend(summary.inaccessible_children.into_iter());
inaccessible_children.extend(summary.inaccessible_children);
// Don't traverse the tree deeper than max_depth
#[allow(
+1 -1
View File
@@ -9,7 +9,7 @@ use conduwuit_core::{
},
validated, warn,
};
use futures::{FutureExt, StreamExt};
use futures::FutureExt;
use ruma::{
CanonicalJsonObject, EventId, OwnedServerName, RoomId, ServerName, api::federation,
events::TimelineEventType, uint,
+1 -2
View File
@@ -4,7 +4,7 @@ use bytes::BytesMut;
use conduwuit::{Err, Result, debug_error, err, utils, utils::response::LimitReadExt, warn};
use reqwest::Client;
use ruma::api::{
IncomingResponse, MatrixVersion, OutgoingRequest,
IncomingResponse, OutgoingRequest,
auth_scheme::{AppserviceToken, SendAccessToken},
path_builder::VersionHistory,
};
@@ -23,7 +23,6 @@ where
+ Debug
+ Send,
{
const VERSIONS: [MatrixVersion; 1] = [MatrixVersion::V1_15];
let http_request = request
.try_into_http_request::<BytesMut>(
base_url,
+1 -1
View File
@@ -224,7 +224,7 @@ fn parse_servercurrentevent(key: &[u8], value: &[u8]) -> Result<(Destination, Se
.ok_or_else(|| Error::bad_database("Invalid bytes in servercurrentpdus."))?;
(
Destination::Push(user_id.to_owned(), pushkey_string),
Destination::Push(user_id, pushkey_string),
if value.is_empty() {
SendingEvent::Pdu(event.into())
} else {
+1 -3
View File
@@ -203,9 +203,7 @@ impl Service {
S: Stream<Item = OwnedServerName> + Send,
{
let requests = servers
.map(|server| {
(Destination::Federation(server.into()), SendingEvent::Pdu(pdu_id.to_owned()))
})
.map(|server| (Destination::Federation(server), SendingEvent::Pdu(pdu_id.to_owned())))
.collect::<Vec<_>>()
.await;
+1 -1
View File
@@ -236,5 +236,5 @@ async fn acquire_notary_result(&self, missing: &mut Batch, server_keys: ServerSi
}
fn keys_count(batch: &Batch) -> usize {
batch.iter().flat_map(|(_, key_ids)| key_ids.iter()).count()
batch.values().flat_map(|key_ids| key_ids.iter()).count()
}
+3 -4
View File
@@ -50,7 +50,7 @@ pub type PubKeys = PublicKeySet;
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
let minimum_valid = Duration::from_secs(3600);
let minimum_valid = Duration::from_hours(1);
let (keypair, verify_keys) = keypair::init(args.db)?;
debug_assert!(verify_keys.len() == 1, "only one active verify_key supported");
@@ -171,11 +171,10 @@ pub async fn verify_keys_for(&self, origin: &ServerName) -> VerifyKeys {
let mut keys = self
.signing_keys_for(origin)
.await
.map(|keys| merge_old_keys(keys).verify_keys)
.unwrap_or(BTreeMap::new());
.map_or(BTreeMap::new(), |keys| merge_old_keys(keys).verify_keys);
if self.services.globals.server_is_ours(origin) {
keys.extend(self.verify_keys.clone().into_iter());
keys.extend(self.verify_keys.clone());
}
keys
+2 -2
View File
@@ -23,8 +23,8 @@ pub(super) fn required_keys(
};
let entry = map.entry(server.clone()).or_default();
set.iter()
.map(|(k, _)| k.clone())
set.keys()
.cloned()
.map(TryInto::try_into)
.filter_map(Result::ok)
.for_each(|key_id| entry.push(key_id));
+1
View File
@@ -39,6 +39,7 @@ struct Services {
typing: Dep<rooms::typing::Service>,
}
#[allow(unused, reason = "TODO refactor")]
struct SlidingSyncCache {
lists: BTreeMap<String, v5::request::List>,
subscriptions: BTreeMap<OwnedRoomId, v5::request::RoomSubscription>,
+1 -1
View File
@@ -64,7 +64,7 @@ pub async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result {
futures.push(self.db.pduid_pdu.watch_prefix(&short_roomid));
// EDUs
let typing_room_id = room_id.to_owned();
let typing_room_id = room_id.clone();
let typing_wait_for_update = async move {
self.services.typing.wait_for_update(&typing_room_id).await;
};
+1 -1
View File
@@ -43,7 +43,7 @@ pub(crate) struct ValidationToken {
impl ValidationToken {
// one hour
const MAX_TOKEN_AGE: Duration = Duration::from_secs(60 * 60);
const MAX_TOKEN_AGE: Duration = Duration::from_hours(1);
const RANDOM_TOKEN_LENGTH: usize = 16;
pub(super) fn new_random() -> Self {
+1 -1
View File
@@ -315,7 +315,7 @@ impl Service {
| TxnState::Active(_) => None,
})
.collect();
cached_entries.sort_by(|a, b| a.1.cmp(&b.1));
cached_entries.sort_by_key(|a| a.1);
// Remove the oldest cached entries to get under the limit
for (key, _) in cached_entries.into_iter().take(excess) {
+1 -2
View File
@@ -165,10 +165,9 @@ impl Service {
.account_data
.get_global(recipient_user, GlobalAccountDataEventType::InvitePermissionConfig)
.await
.map(|config: InvitePermissionConfigEvent| {
.map_or(FilterLevel::Allow, |config: InvitePermissionConfigEvent| {
config.content.user_filter_level(sender_user)
})
.unwrap_or(FilterLevel::Allow)
}
}