From 0688a96c379f5ce6dad6e63f23076a0294cb5028 Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Wed, 12 Jun 2024 00:36:38 -0400 Subject: [PATCH] drop redacted events from search results Signed-off-by: strawberry --- src/api/client/search.rs | 11 ++++++----- src/service/pdu.rs | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/api/client/search.rs b/src/api/client/search.rs index b9bf9b62..e88558fd 100644 --- a/src/api/client/search.rs +++ b/src/api/client/search.rs @@ -141,11 +141,12 @@ pub(crate) async fn search_events_route(body: Ruma) .get_pdu_from_id(result) .ok()? .filter(|pdu| { - services() - .rooms - .state_accessor - .user_can_see_event(sender_user, &pdu.room_id, &pdu.event_id) - .unwrap_or(false) + !pdu.is_redacted() + && services() + .rooms + .state_accessor + .user_can_see_event(sender_user, &pdu.room_id, &pdu.event_id) + .unwrap_or(false) }) .map(|pdu| pdu.to_room_event()) }) diff --git a/src/service/pdu.rs b/src/service/pdu.rs index 6274d635..135ae1fd 100644 --- a/src/service/pdu.rs +++ b/src/service/pdu.rs @@ -21,6 +21,11 @@ use tracing::warn; use crate::{services, Error}; +#[derive(Deserialize)] +struct ExtractRedactedBecause { + redacted_because: Option, +} + /// Content hashes of a PDU. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct EventHash { @@ -76,6 +81,19 @@ impl PduEvent { Ok(()) } + #[must_use] + pub fn is_redacted(&self) -> bool { + let Some(unsigned) = &self.unsigned else { + return false; + }; + + let Ok(unsigned) = ExtractRedactedBecause::deserialize(&**unsigned) else { + return false; + }; + + unsigned.redacted_because.is_some() + } + pub fn remove_transaction_id(&mut self) -> crate::Result<()> { if let Some(unsigned) = &self.unsigned { let mut unsigned: BTreeMap> = serde_json::from_str(unsigned.get())