resolve the last few relevant pedantic clippy lints
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
fa71dd4b4c
commit
48d1a3af3c
20 changed files with 464 additions and 560 deletions
|
@ -119,26 +119,25 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) ->
|
|||
using get_alias_helper to fetch room ID remotely"
|
||||
);
|
||||
|
||||
let room_id = match services().rooms.alias.resolve_local_alias(&room_alias)? {
|
||||
Some(room_id) => room_id,
|
||||
None => {
|
||||
debug!(
|
||||
"We don't have this room alias to a room ID locally, attempting to fetch room ID over \
|
||||
federation"
|
||||
);
|
||||
let room_id = if let Some(room_id) = services().rooms.alias.resolve_local_alias(&room_alias)? {
|
||||
room_id
|
||||
} else {
|
||||
debug!(
|
||||
"We don't have this room alias to a room ID locally, attempting to fetch room ID over \
|
||||
federation"
|
||||
);
|
||||
|
||||
match get_alias_helper(room_alias).await {
|
||||
Ok(response) => {
|
||||
debug!("Got federation response fetching room ID for room {room}: {:?}", response);
|
||||
response.room_id
|
||||
},
|
||||
Err(e) => {
|
||||
return Ok(RoomMessageEventContent::text_plain(format!(
|
||||
"Failed to resolve room alias {room} to a room ID: {e}"
|
||||
)));
|
||||
},
|
||||
}
|
||||
},
|
||||
match get_alias_helper(room_alias).await {
|
||||
Ok(response) => {
|
||||
debug!("Got federation response fetching room ID for room {room}: {:?}", response);
|
||||
response.room_id
|
||||
},
|
||||
Err(e) => {
|
||||
return Ok(RoomMessageEventContent::text_plain(format!(
|
||||
"Failed to resolve room alias {room} to a room ID: {e}"
|
||||
)));
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
services().rooms.metadata.ban_room(&room_id, true)?;
|
||||
|
@ -352,14 +351,12 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) ->
|
|||
|
||||
if disable_federation {
|
||||
return Ok(RoomMessageEventContent::text_plain(format!(
|
||||
"Finished bulk room ban, banned {} total rooms, evicted all users, and disabled incoming \
|
||||
federation with the room.",
|
||||
room_ban_count
|
||||
"Finished bulk room ban, banned {room_ban_count} total rooms, evicted all users, and disabled \
|
||||
incoming federation with the room."
|
||||
)));
|
||||
}
|
||||
return Ok(RoomMessageEventContent::text_plain(format!(
|
||||
"Finished bulk room ban, banned {} total rooms and evicted all users.",
|
||||
room_ban_count
|
||||
"Finished bulk room ban, banned {room_ban_count} total rooms and evicted all users."
|
||||
)));
|
||||
}
|
||||
|
||||
|
@ -403,26 +400,25 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) ->
|
|||
using get_alias_helper to fetch room ID remotely"
|
||||
);
|
||||
|
||||
let room_id = match services().rooms.alias.resolve_local_alias(&room_alias)? {
|
||||
Some(room_id) => room_id,
|
||||
None => {
|
||||
debug!(
|
||||
"We don't have this room alias to a room ID locally, attempting to fetch room ID over \
|
||||
federation"
|
||||
);
|
||||
let room_id = if let Some(room_id) = services().rooms.alias.resolve_local_alias(&room_alias)? {
|
||||
room_id
|
||||
} else {
|
||||
debug!(
|
||||
"We don't have this room alias to a room ID locally, attempting to fetch room ID over \
|
||||
federation"
|
||||
);
|
||||
|
||||
match get_alias_helper(room_alias).await {
|
||||
Ok(response) => {
|
||||
debug!("Got federation response fetching room ID for room {room}: {:?}", response);
|
||||
response.room_id
|
||||
},
|
||||
Err(e) => {
|
||||
return Ok(RoomMessageEventContent::text_plain(format!(
|
||||
"Failed to resolve room alias {room} to a room ID: {e}"
|
||||
)));
|
||||
},
|
||||
}
|
||||
},
|
||||
match get_alias_helper(room_alias).await {
|
||||
Ok(response) => {
|
||||
debug!("Got federation response fetching room ID for room {room}: {:?}", response);
|
||||
response.room_id
|
||||
},
|
||||
Err(e) => {
|
||||
return Ok(RoomMessageEventContent::text_plain(format!(
|
||||
"Failed to resolve room alias {room} to a room ID: {e}"
|
||||
)));
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
services().rooms.metadata.ban_room(&room_id, false)?;
|
||||
|
|
|
@ -214,13 +214,10 @@ impl Service {
|
|||
})
|
||||
.transpose()?;
|
||||
|
||||
let mxc_s = match mxc {
|
||||
Some(mxc) => mxc,
|
||||
None => {
|
||||
return Err(Error::bad_database(
|
||||
"Parsed MXC URL unicode bytes from database but still is None",
|
||||
));
|
||||
},
|
||||
let Some(mxc_s) = mxc else {
|
||||
return Err(Error::bad_database(
|
||||
"Parsed MXC URL unicode bytes from database but still is None",
|
||||
));
|
||||
};
|
||||
|
||||
debug!("Parsed MXC key to URL: {}", mxc_s);
|
||||
|
|
|
@ -314,9 +314,8 @@ impl Service {
|
|||
Ok(ruma::signatures::Verified::Signatures) => {
|
||||
// Redact
|
||||
warn!("Calculated hash does not match: {}", event_id);
|
||||
let obj = match ruma::canonical_json::redact(value, room_version_id, None) {
|
||||
Ok(obj) => obj,
|
||||
Err(_) => return Err(Error::BadRequest(ErrorKind::InvalidParam, "Redaction failed")),
|
||||
let Ok(obj) = ruma::canonical_json::redact(value, room_version_id, None) else {
|
||||
return Err(Error::BadRequest(ErrorKind::InvalidParam, "Redaction failed"));
|
||||
};
|
||||
|
||||
// Skip the PDU if it is redacted and we already have it as an outlier event
|
||||
|
@ -373,12 +372,9 @@ impl Service {
|
|||
// Build map of auth events
|
||||
let mut auth_events = HashMap::new();
|
||||
for id in &incoming_pdu.auth_events {
|
||||
let auth_event = match services().rooms.timeline.get_pdu(id)? {
|
||||
Some(e) => e,
|
||||
None => {
|
||||
warn!("Could not find auth event {}", id);
|
||||
continue;
|
||||
},
|
||||
let Some(auth_event) = services().rooms.timeline.get_pdu(id)? else {
|
||||
warn!("Could not find auth event {}", id);
|
||||
continue;
|
||||
};
|
||||
|
||||
self.check_room_id(room_id, &auth_event)?;
|
||||
|
@ -525,20 +521,16 @@ impl Service {
|
|||
|
||||
let mut okay = true;
|
||||
for prev_eventid in &incoming_pdu.prev_events {
|
||||
let prev_event = if let Ok(Some(pdu)) = services().rooms.timeline.get_pdu(prev_eventid) {
|
||||
pdu
|
||||
} else {
|
||||
let Ok(Some(prev_event)) = services().rooms.timeline.get_pdu(prev_eventid) else {
|
||||
okay = false;
|
||||
break;
|
||||
};
|
||||
|
||||
let sstatehash = if let Ok(Some(s)) = services()
|
||||
let Ok(Some(sstatehash)) = services()
|
||||
.rooms
|
||||
.state_accessor
|
||||
.pdu_shortstatehash(prev_eventid)
|
||||
{
|
||||
s
|
||||
} else {
|
||||
else {
|
||||
okay = false;
|
||||
break;
|
||||
};
|
||||
|
@ -1072,14 +1064,12 @@ impl Service {
|
|||
{
|
||||
Ok(res) => {
|
||||
info!("Got {} over federation", next_id);
|
||||
let (calculated_event_id, value) =
|
||||
match pdu::gen_event_id_canonical_json(&res.pdu, room_version_id) {
|
||||
Ok(t) => t,
|
||||
Err(_) => {
|
||||
back_off((*next_id).to_owned()).await;
|
||||
continue;
|
||||
},
|
||||
};
|
||||
let Ok((calculated_event_id, value)) =
|
||||
pdu::gen_event_id_canonical_json(&res.pdu, room_version_id)
|
||||
else {
|
||||
back_off((*next_id).to_owned()).await;
|
||||
continue;
|
||||
};
|
||||
|
||||
if calculated_event_id != *next_id {
|
||||
warn!(
|
||||
|
@ -1616,21 +1606,18 @@ impl Service {
|
|||
|
||||
/// Returns Ok if the acl allows the server
|
||||
pub fn acl_check(&self, server_name: &ServerName, room_id: &RoomId) -> Result<()> {
|
||||
let acl_event =
|
||||
match services()
|
||||
let acl_event = if let Some(acl) =
|
||||
services()
|
||||
.rooms
|
||||
.state_accessor
|
||||
.room_state_get(room_id, &StateEventType::RoomServerAcl, "")?
|
||||
{
|
||||
Some(acl) => {
|
||||
debug!("ACL event found: {acl:?}");
|
||||
acl
|
||||
},
|
||||
None => {
|
||||
info!("No ACL event found");
|
||||
return Ok(());
|
||||
},
|
||||
};
|
||||
{
|
||||
debug!("ACL event found: {acl:?}");
|
||||
acl
|
||||
} else {
|
||||
debug!("No ACL event found");
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let acl_event_content: RoomServerAclEventContent = match serde_json::from_str(acl_event.content.get()) {
|
||||
Ok(content) => {
|
||||
|
|
|
@ -90,7 +90,7 @@ impl Arena {
|
|||
|
||||
/// Returns the first untraversed node, marking it as traversed in the
|
||||
/// process
|
||||
pub fn first_untraversed(&mut self) -> Option<NodeId> {
|
||||
fn first_untraversed(&mut self) -> Option<NodeId> {
|
||||
if self.nodes.is_empty() {
|
||||
None
|
||||
} else if let Some(untraversed) = self.first_untraversed {
|
||||
|
@ -133,7 +133,7 @@ impl Arena {
|
|||
}
|
||||
|
||||
/// Adds all the given nodes as children of the parent node
|
||||
pub fn push(&mut self, parent: NodeId, mut children: Vec<OwnedRoomId>) {
|
||||
fn push(&mut self, parent: NodeId, mut children: Vec<OwnedRoomId>) {
|
||||
if children.is_empty() {
|
||||
self.traverse(parent);
|
||||
} else if self.nodes.get(parent.index).is_some() {
|
||||
|
@ -204,7 +204,7 @@ impl Arena {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new(root: OwnedRoomId, max_depth: usize) -> Self {
|
||||
fn new(root: OwnedRoomId, max_depth: usize) -> Self {
|
||||
let zero_depth = max_depth == 0;
|
||||
|
||||
Arena {
|
||||
|
@ -229,11 +229,11 @@ impl Arena {
|
|||
|
||||
// Note: perhaps use some better form of token rather than just room count
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct PagnationToken {
|
||||
pub skip: UInt,
|
||||
pub limit: UInt,
|
||||
pub max_depth: UInt,
|
||||
pub suggested_only: bool,
|
||||
pub(crate) struct PagnationToken {
|
||||
pub(crate) skip: UInt,
|
||||
pub(crate) limit: UInt,
|
||||
pub(crate) max_depth: UInt,
|
||||
pub(crate) suggested_only: bool,
|
||||
}
|
||||
|
||||
impl FromStr for PagnationToken {
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::{
|
|||
sync::Arc,
|
||||
};
|
||||
|
||||
pub use data::Data;
|
||||
pub(crate) use data::Data;
|
||||
use ruma::{
|
||||
api::client::error::ErrorKind,
|
||||
events::{
|
||||
|
@ -43,9 +43,8 @@ impl Service {
|
|||
.ok()
|
||||
.map(|(_, id)| id)
|
||||
}) {
|
||||
let pdu = match services().rooms.timeline.get_pdu_json(&event_id)? {
|
||||
Some(pdu) => pdu,
|
||||
None => continue,
|
||||
let Some(pdu) = services().rooms.timeline.get_pdu_json(&event_id)? else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let pdu: PduEvent = match serde_json::from_str(
|
||||
|
@ -57,19 +56,16 @@ impl Service {
|
|||
|
||||
match pdu.kind {
|
||||
TimelineEventType::RoomMember => {
|
||||
let membership_event = match serde_json::from_str::<RoomMemberEventContent>(pdu.content.get()) {
|
||||
Ok(e) => e,
|
||||
Err(_) => continue,
|
||||
let Ok(membership_event) = serde_json::from_str::<RoomMemberEventContent>(pdu.content.get()) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let state_key = match pdu.state_key {
|
||||
Some(k) => k,
|
||||
None => continue,
|
||||
let Some(state_key) = pdu.state_key else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let user_id = match UserId::parse(state_key) {
|
||||
Ok(id) => id,
|
||||
Err(_) => continue,
|
||||
let Ok(user_id) = UserId::parse(state_key) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
services()
|
||||
|
@ -355,12 +351,9 @@ impl Service {
|
|||
&self, room_id: &RoomId, kind: &TimelineEventType, sender: &UserId, state_key: Option<&str>,
|
||||
content: &serde_json::value::RawValue,
|
||||
) -> Result<StateMap<Arc<PduEvent>>> {
|
||||
let shortstatehash =
|
||||
if let Some(current_shortstatehash) = services().rooms.state.get_room_shortstatehash(room_id)? {
|
||||
current_shortstatehash
|
||||
} else {
|
||||
return Ok(HashMap::new());
|
||||
};
|
||||
let Some(shortstatehash) = services().rooms.state.get_room_shortstatehash(room_id)? else {
|
||||
return Ok(HashMap::new());
|
||||
};
|
||||
|
||||
let auth_events =
|
||||
state_res::auth_types_for_event(kind, sender, state_key, content).expect("content is a valid JSON object");
|
||||
|
|
|
@ -143,9 +143,8 @@ impl Service {
|
|||
/// the room's history_visibility at that event's state.
|
||||
#[tracing::instrument(skip(self, user_id, room_id, event_id))]
|
||||
pub fn user_can_see_event(&self, user_id: &UserId, room_id: &RoomId, event_id: &EventId) -> Result<bool> {
|
||||
let shortstatehash = match self.pdu_shortstatehash(event_id)? {
|
||||
Some(shortstatehash) => shortstatehash,
|
||||
None => return Ok(true),
|
||||
let Some(shortstatehash) = self.pdu_shortstatehash(event_id)? else {
|
||||
return Ok(true);
|
||||
};
|
||||
|
||||
if let Some(visibility) = self
|
||||
|
|
|
@ -473,7 +473,7 @@ impl Service {
|
|||
}
|
||||
|
||||
/// Ensure that a user only sees signatures from themselves and the target user
|
||||
pub fn clean_signatures<F: Fn(&UserId) -> bool>(
|
||||
pub(crate) fn clean_signatures<F: Fn(&UserId) -> bool>(
|
||||
cross_signing_key: &mut serde_json::Value, sender_user: Option<&UserId>, user_id: &UserId, allowed_signatures: F,
|
||||
) -> Result<(), Error> {
|
||||
if let Some(signatures) = cross_signing_key
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue