drop redacted events from search results
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
@@ -141,11 +141,12 @@ pub(crate) async fn search_events_route(body: Ruma<search_events::v3::Request>)
|
|||||||
.get_pdu_from_id(result)
|
.get_pdu_from_id(result)
|
||||||
.ok()?
|
.ok()?
|
||||||
.filter(|pdu| {
|
.filter(|pdu| {
|
||||||
services()
|
!pdu.is_redacted()
|
||||||
.rooms
|
&& services()
|
||||||
.state_accessor
|
.rooms
|
||||||
.user_can_see_event(sender_user, &pdu.room_id, &pdu.event_id)
|
.state_accessor
|
||||||
.unwrap_or(false)
|
.user_can_see_event(sender_user, &pdu.room_id, &pdu.event_id)
|
||||||
|
.unwrap_or(false)
|
||||||
})
|
})
|
||||||
.map(|pdu| pdu.to_room_event())
|
.map(|pdu| pdu.to_room_event())
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ use tracing::warn;
|
|||||||
|
|
||||||
use crate::{services, Error};
|
use crate::{services, Error};
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct ExtractRedactedBecause {
|
||||||
|
redacted_because: Option<serde::de::IgnoredAny>,
|
||||||
|
}
|
||||||
|
|
||||||
/// Content hashes of a PDU.
|
/// Content hashes of a PDU.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct EventHash {
|
pub struct EventHash {
|
||||||
@@ -76,6 +81,19 @@ impl PduEvent {
|
|||||||
Ok(())
|
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<()> {
|
pub fn remove_transaction_id(&mut self) -> crate::Result<()> {
|
||||||
if let Some(unsigned) = &self.unsigned {
|
if let Some(unsigned) = &self.unsigned {
|
||||||
let mut unsigned: BTreeMap<String, Box<RawJsonValue>> = serde_json::from_str(unsigned.get())
|
let mut unsigned: BTreeMap<String, Box<RawJsonValue>> = serde_json::from_str(unsigned.get())
|
||||||
|
|||||||
Reference in New Issue
Block a user