resolve couple pedantic clippy lints, remove unnecessary qualifications
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
6d7ef80aba
commit
9d0b647911
35 changed files with 127 additions and 148 deletions
|
@ -482,7 +482,7 @@ impl Service {
|
|||
let conduit_user = UserId::parse(format!("@conduit:{}", services().globals.server_name()))
|
||||
.expect("@conduit:server_name is valid");
|
||||
|
||||
if let Ok(Some(conduit_room)) = services().admin.get_admin_room() {
|
||||
if let Ok(Some(conduit_room)) = Self::get_admin_room() {
|
||||
loop {
|
||||
tokio::select! {
|
||||
Some(event) = receiver.recv() => {
|
||||
|
@ -1131,7 +1131,7 @@ impl Service {
|
|||
.try_into()
|
||||
.expect("#admins:server_name is a valid alias name");
|
||||
|
||||
if let Some(admin_room_id) = services().admin.get_admin_room()? {
|
||||
if let Some(admin_room_id) = Self::get_admin_room()? {
|
||||
if room.to_string().eq(&admin_room_id) || room.to_string().eq(&admin_room_alias) {
|
||||
return Ok(RoomMessageEventContent::text_plain(
|
||||
"Not allowed to ban the admin room.",
|
||||
|
@ -1304,7 +1304,7 @@ impl Service {
|
|||
match <&RoomId>::try_from(room_id) {
|
||||
Ok(owned_room_id) => {
|
||||
// silently ignore deleting admin room
|
||||
if let Some(admin_room_id) = services().admin.get_admin_room()? {
|
||||
if let Some(admin_room_id) = Self::get_admin_room()? {
|
||||
if owned_room_id.eq(&admin_room_id) {
|
||||
info!("User specified admin room in bulk ban list, ignoring");
|
||||
continue;
|
||||
|
@ -1550,7 +1550,7 @@ impl Service {
|
|||
.rooms
|
||||
.metadata
|
||||
.iter_ids()
|
||||
.filter_map(std::result::Result::ok)
|
||||
.filter_map(Result::ok)
|
||||
.map(|id: OwnedRoomId| Self::get_room_info(&id))
|
||||
.collect::<Vec<_>>();
|
||||
rooms.sort_by_key(|r| r.1);
|
||||
|
@ -1751,7 +1751,7 @@ impl Service {
|
|||
.rooms
|
||||
.directory
|
||||
.public_rooms()
|
||||
.filter_map(std::result::Result::ok)
|
||||
.filter_map(Result::ok)
|
||||
.map(|id: OwnedRoomId| Self::get_room_info(&id))
|
||||
.collect::<Vec<_>>();
|
||||
rooms.sort_by_key(|r| r.1);
|
||||
|
@ -2152,7 +2152,7 @@ impl Service {
|
|||
},
|
||||
DebugCommand::ForceDeviceListUpdates => {
|
||||
// Force E2EE device list updates for all users
|
||||
for user_id in services().users.iter().filter_map(std::result::Result::ok) {
|
||||
for user_id in services().users.iter().filter_map(Result::ok) {
|
||||
services().users.mark_device_key_update(&user_id)?;
|
||||
}
|
||||
RoomMessageEventContent::text_plain("Marked all devices for all users as having new keys to update")
|
||||
|
@ -2486,7 +2486,7 @@ impl Service {
|
|||
///
|
||||
/// Errors are propagated from the database, and will have None if there is
|
||||
/// no admin room
|
||||
pub(crate) fn get_admin_room(&self) -> Result<Option<OwnedRoomId>> {
|
||||
pub(crate) fn get_admin_room() -> Result<Option<OwnedRoomId>> {
|
||||
let admin_room_alias: Box<RoomAliasId> = format!("#admins:{}", services().globals.server_name())
|
||||
.try_into()
|
||||
.expect("#admins:server_name is a valid alias name");
|
||||
|
@ -2498,7 +2498,7 @@ impl Service {
|
|||
///
|
||||
/// In conduit, this is equivalent to granting admin privileges.
|
||||
pub(crate) async fn make_user_admin(&self, user_id: &UserId, displayname: String) -> Result<()> {
|
||||
if let Some(room_id) = services().admin.get_admin_room()? {
|
||||
if let Some(room_id) = Self::get_admin_room()? {
|
||||
let mutex_state =
|
||||
Arc::clone(services().globals.roomid_mutex_state.write().await.entry(room_id.clone()).or_default());
|
||||
let state_lock = mutex_state.lock().await;
|
||||
|
|
|
@ -60,17 +60,18 @@ impl Service {
|
|||
#[allow(clippy::unnecessary_operation)] // error[E0658]: attributes on expressions are experimental
|
||||
#[cfg(feature = "sha256_media")]
|
||||
{
|
||||
path = services().globals.get_media_file_new(&key)
|
||||
path = services().globals.get_media_file_new(&key);
|
||||
};
|
||||
|
||||
#[allow(clippy::unnecessary_operation)] // error[E0658]: attributes on expressions are experimental
|
||||
#[cfg(not(feature = "sha256_media"))]
|
||||
{
|
||||
path = services().globals.get_media_file(&key)
|
||||
path = services().globals.get_media_file(&key);
|
||||
};
|
||||
|
||||
let mut f = File::create(path).await?;
|
||||
f.write_all(file).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -83,13 +84,13 @@ impl Service {
|
|||
#[allow(clippy::unnecessary_operation)] // error[E0658]: attributes on expressions are experimental
|
||||
#[cfg(feature = "sha256_media")]
|
||||
{
|
||||
file_path = services().globals.get_media_file_new(&key)
|
||||
file_path = services().globals.get_media_file_new(&key);
|
||||
};
|
||||
|
||||
#[allow(clippy::unnecessary_operation)] // error[E0658]: attributes on expressions are experimental
|
||||
#[cfg(not(feature = "sha256_media"))]
|
||||
{
|
||||
file_path = services().globals.get_media_file(&key)
|
||||
file_path = services().globals.get_media_file(&key);
|
||||
};
|
||||
|
||||
debug!("Got local file path: {:?}", file_path);
|
||||
|
@ -133,7 +134,7 @@ impl Service {
|
|||
#[allow(clippy::unnecessary_operation)] // error[E0658]: attributes on expressions are experimental
|
||||
#[cfg(not(feature = "sha256_media"))]
|
||||
{
|
||||
path = services().globals.get_media_file(&key)
|
||||
path = services().globals.get_media_file(&key);
|
||||
};
|
||||
|
||||
let mut f = File::create(path).await?;
|
||||
|
@ -150,13 +151,13 @@ impl Service {
|
|||
#[allow(clippy::unnecessary_operation)] // error[E0658]: attributes on expressions are experimental
|
||||
#[cfg(feature = "sha256_media")]
|
||||
{
|
||||
path = services().globals.get_media_file_new(&key)
|
||||
path = services().globals.get_media_file_new(&key);
|
||||
};
|
||||
|
||||
#[allow(clippy::unnecessary_operation)] // error[E0658]: attributes on expressions are experimental
|
||||
#[cfg(not(feature = "sha256_media"))]
|
||||
{
|
||||
path = services().globals.get_media_file(&key)
|
||||
path = services().globals.get_media_file(&key);
|
||||
};
|
||||
|
||||
let mut file = Vec::new();
|
||||
|
@ -236,7 +237,7 @@ impl Service {
|
|||
#[allow(clippy::unnecessary_operation)] // error[E0658]: attributes on expressions are experimental
|
||||
#[cfg(not(feature = "sha256_media"))]
|
||||
{
|
||||
path = services().globals.get_media_file(&key)
|
||||
path = services().globals.get_media_file(&key);
|
||||
};
|
||||
|
||||
debug!("MXC path: {:?}", path);
|
||||
|
@ -316,13 +317,13 @@ impl Service {
|
|||
#[allow(clippy::unnecessary_operation)] // error[E0658]: attributes on expressions are experimental
|
||||
#[cfg(feature = "sha256_media")]
|
||||
{
|
||||
path = services().globals.get_media_file_new(&key)
|
||||
path = services().globals.get_media_file_new(&key);
|
||||
};
|
||||
|
||||
#[allow(clippy::unnecessary_operation)] // error[E0658]: attributes on expressions are experimental
|
||||
#[cfg(not(feature = "sha256_media"))]
|
||||
{
|
||||
path = services().globals.get_media_file(&key)
|
||||
path = services().globals.get_media_file(&key);
|
||||
};
|
||||
|
||||
let mut file = Vec::new();
|
||||
|
@ -340,13 +341,13 @@ impl Service {
|
|||
#[allow(clippy::unnecessary_operation)] // error[E0658]: attributes on expressions are experimental
|
||||
#[cfg(feature = "sha256_media")]
|
||||
{
|
||||
path = services().globals.get_media_file_new(&key)
|
||||
path = services().globals.get_media_file_new(&key);
|
||||
};
|
||||
|
||||
#[allow(clippy::unnecessary_operation)] // error[E0658]: attributes on expressions are experimental
|
||||
#[cfg(not(feature = "sha256_media"))]
|
||||
{
|
||||
path = services().globals.get_media_file(&key)
|
||||
path = services().globals.get_media_file(&key);
|
||||
};
|
||||
|
||||
let mut file = Vec::new();
|
||||
|
@ -427,13 +428,13 @@ impl Service {
|
|||
#[allow(clippy::unnecessary_operation)] // error[E0658]: attributes on expressions are experimental
|
||||
#[cfg(feature = "sha256_media")]
|
||||
{
|
||||
path = services().globals.get_media_file_new(&thumbnail_key)
|
||||
path = services().globals.get_media_file_new(&thumbnail_key);
|
||||
};
|
||||
|
||||
#[allow(clippy::unnecessary_operation)] // error[E0658]: attributes on expressions are experimental
|
||||
#[cfg(not(feature = "sha256_media"))]
|
||||
{
|
||||
path = services().globals.get_media_file(&thumbnail_key)
|
||||
path = services().globals.get_media_file(&thumbnail_key);
|
||||
};
|
||||
|
||||
let mut f = File::create(path).await?;
|
||||
|
|
|
@ -45,17 +45,20 @@ impl Service {
|
|||
async fn typings_maintain(&self, room_id: &RoomId) -> Result<()> {
|
||||
let current_timestamp = utils::millis_since_unix_epoch();
|
||||
let mut removable = Vec::new();
|
||||
|
||||
{
|
||||
let typing = self.typing.read().await;
|
||||
let Some(room) = typing.get(room_id) else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
for (user, timeout) in room {
|
||||
if *timeout < current_timestamp {
|
||||
removable.push(user.clone());
|
||||
}
|
||||
}
|
||||
drop(typing)
|
||||
|
||||
drop(typing);
|
||||
};
|
||||
|
||||
if !removable.is_empty() {
|
||||
|
|
|
@ -1491,14 +1491,13 @@ impl Service {
|
|||
let permit =
|
||||
services().globals.servername_ratelimiter.read().await.get(origin).map(|s| Arc::clone(s).acquire_owned());
|
||||
|
||||
let permit = match permit {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
let mut write = services().globals.servername_ratelimiter.write().await;
|
||||
let s = Arc::clone(write.entry(origin.to_owned()).or_insert_with(|| Arc::new(Semaphore::new(1))));
|
||||
let permit = if let Some(p) = permit {
|
||||
p
|
||||
} else {
|
||||
let mut write = services().globals.servername_ratelimiter.write().await;
|
||||
let s = Arc::clone(write.entry(origin.to_owned()).or_insert_with(|| Arc::new(Semaphore::new(1))));
|
||||
|
||||
s.acquire_owned()
|
||||
},
|
||||
s.acquire_owned()
|
||||
}
|
||||
.await;
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ impl Service {
|
|||
})
|
||||
})
|
||||
.take(limit)
|
||||
.filter_map(std::result::Result::ok) // Filter out buggy events
|
||||
.filter_map(Result::ok) // Filter out buggy events
|
||||
.filter(|(_, pdu)| {
|
||||
services()
|
||||
.rooms
|
||||
|
@ -113,7 +113,7 @@ impl Service {
|
|||
})
|
||||
})
|
||||
.take(limit)
|
||||
.filter_map(std::result::Result::ok) // Filter out buggy events
|
||||
.filter_map(Result::ok) // Filter out buggy events
|
||||
.filter(|(_, pdu)| {
|
||||
services()
|
||||
.rooms
|
||||
|
|
|
@ -109,7 +109,7 @@ impl Arena {
|
|||
if let Some(next) = self.next_sibling(current) {
|
||||
current = next;
|
||||
} else if let Some(parent) = self.parent(current) {
|
||||
current = parent
|
||||
current = parent;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ impl Arena {
|
|||
)];
|
||||
|
||||
while let Some(parent) = self.parent(parents.last().expect("Has at least one value, as above").0) {
|
||||
parents.push((parent, self.get(parent).expect("It is some, as above").room_id.clone()))
|
||||
parents.push((parent, self.get(parent).expect("It is some, as above").room_id.clone()));
|
||||
}
|
||||
|
||||
// If at max_depth, don't add new rooms
|
||||
|
@ -607,9 +607,9 @@ impl Service {
|
|||
arena.push(current_room, children);
|
||||
|
||||
if left_to_skip > 0 {
|
||||
left_to_skip -= 1
|
||||
left_to_skip -= 1;
|
||||
} else {
|
||||
results.push(summary_to_chunk(*summary.clone()))
|
||||
results.push(summary_to_chunk(*summary.clone()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -111,7 +111,7 @@ impl Service {
|
|||
.rooms
|
||||
.state_cache
|
||||
.room_members(room_id)
|
||||
.filter_map(std::result::Result::ok)
|
||||
.filter_map(Result::ok)
|
||||
.filter(|member| member.server_name() == origin);
|
||||
|
||||
let visibility = match history_visibility {
|
||||
|
|
|
@ -37,6 +37,7 @@ use super::state_compressor::CompressedStateEvent;
|
|||
use crate::{
|
||||
api::server_server,
|
||||
service::{
|
||||
self,
|
||||
appservice::NamespaceRegex,
|
||||
pdu::{EventHash, PduBuilder},
|
||||
},
|
||||
|
@ -476,7 +477,7 @@ impl Service {
|
|||
// the administrator can execute commands as conduit
|
||||
let from_conduit = pdu.sender == server_user && services().globals.emergency_password().is_none();
|
||||
|
||||
if let Some(admin_room) = services().admin.get_admin_room()? {
|
||||
if let Some(admin_room) = service::admin::Service::get_admin_room()? {
|
||||
if to_conduit && !from_conduit && admin_room == pdu.room_id {
|
||||
services().admin.process_message(body, pdu.event_id.clone());
|
||||
}
|
||||
|
@ -540,7 +541,7 @@ impl Service {
|
|||
.rooms
|
||||
.alias
|
||||
.local_aliases_for_room(&pdu.room_id)
|
||||
.filter_map(std::result::Result::ok)
|
||||
.filter_map(Result::ok)
|
||||
.any(|room_alias| aliases.is_match(room_alias.as_str()))
|
||||
};
|
||||
|
||||
|
@ -721,7 +722,7 @@ impl Service {
|
|||
) -> Result<Arc<EventId>> {
|
||||
let (pdu, pdu_json) = self.create_hash_and_sign_event(pdu_builder, sender, room_id, state_lock)?;
|
||||
|
||||
if let Some(admin_room) = services().admin.get_admin_room()? {
|
||||
if let Some(admin_room) = service::admin::Service::get_admin_room()? {
|
||||
if admin_room == room_id {
|
||||
match pdu.event_type() {
|
||||
TimelineEventType::RoomEncryption => {
|
||||
|
@ -756,7 +757,7 @@ impl Service {
|
|||
.rooms
|
||||
.state_cache
|
||||
.room_members(room_id)
|
||||
.filter_map(std::result::Result::ok)
|
||||
.filter_map(Result::ok)
|
||||
.filter(|m| m.server_name() == server_name)
|
||||
.filter(|m| m != target)
|
||||
.count();
|
||||
|
@ -782,7 +783,7 @@ impl Service {
|
|||
.rooms
|
||||
.state_cache
|
||||
.room_members(room_id)
|
||||
.filter_map(std::result::Result::ok)
|
||||
.filter_map(Result::ok)
|
||||
.filter(|m| m.server_name() == server_name)
|
||||
.filter(|m| m != target)
|
||||
.count();
|
||||
|
@ -821,7 +822,7 @@ impl Service {
|
|||
services().rooms.state.set_room_state(room_id, statehashid, state_lock)?;
|
||||
|
||||
let mut servers: HashSet<OwnedServerName> =
|
||||
services().rooms.state_cache.room_servers(room_id).filter_map(std::result::Result::ok).collect();
|
||||
services().rooms.state_cache.room_servers(room_id).filter_map(Result::ok).collect();
|
||||
|
||||
// In case we are kicking or banning a user, we need to inform their server of
|
||||
// the change
|
||||
|
|
|
@ -126,7 +126,7 @@ impl Service {
|
|||
// Retry requests we could not finish yet
|
||||
let mut initial_transactions = HashMap::<OutgoingKind, Vec<SendingEventType>>::new();
|
||||
|
||||
for (key, outgoing_kind, event) in self.db.active_requests().filter_map(std::result::Result::ok) {
|
||||
for (key, outgoing_kind, event) in self.db.active_requests().filter_map(Result::ok) {
|
||||
let entry = initial_transactions.entry(outgoing_kind.clone()).or_default();
|
||||
|
||||
if entry.len() > 30 {
|
||||
|
@ -152,7 +152,7 @@ impl Service {
|
|||
self.db.delete_all_active_requests_for(&outgoing_kind)?;
|
||||
|
||||
// Find events that have been added since starting the last request
|
||||
let new_events = self.db.queued_requests(&outgoing_kind).filter_map(std::result::Result::ok).take(30).collect::<Vec<_>>();
|
||||
let new_events = self.db.queued_requests(&outgoing_kind).filter_map(Result::ok).take(30).collect::<Vec<_>>();
|
||||
|
||||
if !new_events.is_empty() {
|
||||
// Insert pdus we found
|
||||
|
@ -236,7 +236,7 @@ impl Service {
|
|||
|
||||
if retry {
|
||||
// We retry the previous transaction
|
||||
for (_, e) in self.db.active_requests_for(outgoing_kind).filter_map(std::result::Result::ok) {
|
||||
for (_, e) in self.db.active_requests_for(outgoing_kind).filter_map(Result::ok) {
|
||||
events.push(e);
|
||||
}
|
||||
} else {
|
||||
|
@ -274,7 +274,7 @@ impl Service {
|
|||
services()
|
||||
.users
|
||||
.keys_changed(room_id.as_ref(), since, None)
|
||||
.filter_map(std::result::Result::ok)
|
||||
.filter_map(Result::ok)
|
||||
.filter(|user_id| user_id.server_name() == services().globals.server_name()),
|
||||
);
|
||||
|
||||
|
@ -409,7 +409,7 @@ impl Service {
|
|||
}
|
||||
|
||||
#[tracing::instrument(skip(self, server, serialized))]
|
||||
pub fn send_reliable_edu(&self, server: &ServerName, serialized: Vec<u8>, id: u64) -> Result<()> {
|
||||
pub fn send_reliable_edu(&self, server: &ServerName, serialized: Vec<u8>, _id: u64) -> Result<()> {
|
||||
let outgoing_kind = OutgoingKind::Normal(server.to_owned());
|
||||
let event = SendingEventType::Edu(serialized);
|
||||
let _cork = services().globals.db.cork()?;
|
||||
|
@ -433,7 +433,7 @@ impl Service {
|
|||
#[tracing::instrument(skip(self, room_id))]
|
||||
pub fn flush_room(&self, room_id: &RoomId) -> Result<()> {
|
||||
let servers: HashSet<OwnedServerName> =
|
||||
services().rooms.state_cache.room_servers(room_id).filter_map(std::result::Result::ok).collect();
|
||||
services().rooms.state_cache.room_servers(room_id).filter_map(Result::ok).collect();
|
||||
|
||||
self.flush_servers(servers.into_iter())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue