fix and enable collapsible_if lint

Signed-off-by: June Strawberry <june@vern.cc>
This commit is contained in:
June Strawberry
2026-01-15 17:39:33 -05:00
parent fb102f0e0a
commit 04e66a03d3
54 changed files with 453 additions and 504 deletions

View File

@@ -93,11 +93,11 @@ pub async fn witness_retain(&self, senders: Witness, ctx: &Context<'_>) -> Witne
continue;
}
if let Status::Seen(seen) = status {
if seen == 0 || ctx.token == Some(seen) {
senders.insert(sender.into());
continue;
}
if let Status::Seen(seen) = status
&& (seen == 0 || ctx.token == Some(seen))
{
senders.insert(sender.into());
continue;
}
}

View File

@@ -500,10 +500,10 @@ fn get_space_child_events<'a>(
.await
})
.ready_filter_map(|(state_key, pdu)| {
if let Ok(content) = pdu.get_content::<SpaceChildEventContent>() {
if content.via.is_empty() {
return None;
}
if let Ok(content) = pdu.get_content::<SpaceChildEventContent>()
&& content.via.is_empty()
{
return None;
}
if RoomId::parse(&state_key).is_err() {

View File

@@ -113,34 +113,32 @@ where
.services
.state
.pdu_shortstatehash(pdu.event_id())
.await && let Ok(prev_state) = self
.services
.state_accessor
.state_get(shortstatehash, &pdu.kind().to_string().into(), state_key)
.await
{
if let Ok(prev_state) = self
.services
.state_accessor
.state_get(shortstatehash, &pdu.kind().to_string().into(), state_key)
.await
{
unsigned.insert(
"prev_content".into(),
CanonicalJsonValue::Object(
utils::to_canonical_object(prev_state.get_content_as_value())
.map_err(|e| {
err!(Database(error!(
"Failed to convert prev_state to canonical JSON: {e}",
)))
})?,
),
);
unsigned.insert(
"prev_sender".into(),
CanonicalJsonValue::String(prev_state.sender().to_string()),
);
unsigned.insert(
"replaces_state".into(),
CanonicalJsonValue::String(prev_state.event_id().to_string()),
);
}
unsigned.insert(
"prev_content".into(),
CanonicalJsonValue::Object(
utils::to_canonical_object(prev_state.get_content_as_value()).map_err(
|e| {
err!(Database(error!(
"Failed to convert prev_state to canonical JSON: {e}",
)))
},
)?,
),
);
unsigned.insert(
"prev_sender".into(),
CanonicalJsonValue::String(prev_state.sender().to_string()),
);
unsigned.insert(
"replaces_state".into(),
CanonicalJsonValue::String(prev_state.event_id().to_string()),
);
}
} else {
error!("Invalid unsigned type in pdu.");
@@ -222,30 +220,28 @@ async fn append_pdu_effects(
match room_version_id {
| V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 => {
if let Some(redact_id) = pdu.redacts() {
if self
if let Some(redact_id) = pdu.redacts()
&& self
.services
.state_accessor
.user_can_redact(redact_id, pdu.sender(), pdu.room_id(), false)
.await?
{
self.redact_pdu(redact_id, pdu, shortroomid)
.await?;
}
{
self.redact_pdu(redact_id, pdu, shortroomid)
.await?;
}
},
| _ => {
let content: RoomRedactionEventContent = pdu.get_content()?;
if let Some(redact_id) = &content.redacts {
if self
if let Some(redact_id) = &content.redacts
&& self
.services
.state_accessor
.user_can_redact(redact_id, pdu.sender(), pdu.room_id(), false)
.await?
{
self.redact_pdu(redact_id, pdu, shortroomid)
.await?;
}
{
self.redact_pdu(redact_id, pdu, shortroomid)
.await?;
}
},
}
@@ -317,15 +313,14 @@ async fn append_pdu_effects(
| _ => {},
}
if let Ok(content) = pdu.get_content::<ExtractRelatesToEventId>() {
if let Ok(related_pducount) = self
if let Ok(content) = pdu.get_content::<ExtractRelatesToEventId>()
&& let Ok(related_pducount) = self
.get_pdu_count(&content.relates_to.event_id)
.await
{
self.services
.pdu_metadata
.add_relation(count, related_pducount);
}
{
self.services
.pdu_metadata
.add_relation(count, related_pducount);
}
if let Ok(content) = pdu.get_content::<ExtractRelatesTo>() {

View File

@@ -70,28 +70,26 @@ pub async fn build_and_append_pdu(
.await?
{
| V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 => {
if let Some(redact_id) = pdu.redacts() {
if !self
if let Some(redact_id) = pdu.redacts()
&& !self
.services
.state_accessor
.user_can_redact(redact_id, pdu.sender(), pdu.room_id(), false)
.await?
{
return Err!(Request(Forbidden("User cannot redact this event.")));
}
{
return Err!(Request(Forbidden("User cannot redact this event.")));
}
},
| _ => {
let content: RoomRedactionEventContent = pdu.get_content()?;
if let Some(redact_id) = &content.redacts {
if !self
if let Some(redact_id) = &content.redacts
&& !self
.services
.state_accessor
.user_can_redact(redact_id, pdu.sender(), pdu.room_id(), false)
.await?
{
return Err!(Request(Forbidden("User cannot redact this event.")));
}
{
return Err!(Request(Forbidden("User cannot redact this event.")));
}
},
}
@@ -155,14 +153,13 @@ pub async fn build_and_append_pdu(
// In case we are kicking or banning a user, we need to inform their server of
// the change
if *pdu.kind() == TimelineEventType::RoomMember {
if let Some(state_key_uid) = &pdu
if *pdu.kind() == TimelineEventType::RoomMember
&& let Some(state_key_uid) = &pdu
.state_key
.as_ref()
.and_then(|state_key| UserId::parse(state_key.as_str()).ok())
{
servers.insert(state_key_uid.server_name().to_owned());
}
{
servers.insert(state_key_uid.server_name().to_owned());
}
// Remove our server from the server list since it will be added to it by

View File

@@ -100,18 +100,16 @@ pub async fn create_hash_and_sign_event(
.saturating_add(uint!(1));
let mut unsigned = unsigned.unwrap_or_default();
if let Some(state_key) = &state_key {
if let Ok(prev_pdu) = self
if let Some(state_key) = &state_key
&& let Ok(prev_pdu) = self
.services
.state_accessor
.room_state_get(room_id, &event_type.to_string().into(), state_key)
.await
{
unsigned.insert("prev_content".to_owned(), prev_pdu.get_content_as_value());
unsigned.insert("prev_sender".to_owned(), serde_json::to_value(prev_pdu.sender())?);
unsigned
.insert("replaces_state".to_owned(), serde_json::to_value(prev_pdu.event_id())?);
}
{
unsigned.insert("prev_content".to_owned(), prev_pdu.get_content_as_value());
unsigned.insert("prev_sender".to_owned(), serde_json::to_value(prev_pdu.sender())?);
unsigned.insert("replaces_state".to_owned(), serde_json::to_value(prev_pdu.event_id())?);
}
let unsigned = unsigned

View File

@@ -31,12 +31,12 @@ pub async fn redact_pdu<Pdu: Event + Send + Sync>(
err!(Database(error!(?pdu_id, ?event_id, ?e, "PDU ID points to invalid PDU.")))
})?;
if let Ok(content) = pdu.get_content::<ExtractBody>() {
if let Some(body) = content.body {
self.services
.search
.deindex_pdu(shortroomid, &pdu_id, &body);
}
if let Ok(content) = pdu.get_content::<ExtractBody>()
&& let Some(body) = content.body
{
self.services
.search
.deindex_pdu(shortroomid, &pdu_id, &body);
}
let room_version_id = self