fix: de-index pdus when redacted

This commit is contained in:
Matthias Ahouansou 2024-06-05 20:17:32 +01:00 committed by Charles Hall
parent cc5a9d3440
commit f74043df9a
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
3 changed files with 50 additions and 2 deletions

View file

@ -414,7 +414,7 @@ impl Service {
&pdu.room_id,
false,
)? {
self.redact_pdu(redact_id, pdu)?;
self.redact_pdu(redact_id, pdu, shortroomid)?;
}
}
}
@ -435,7 +435,7 @@ impl Service {
&pdu.room_id,
false,
)? {
self.redact_pdu(redact_id, pdu)?;
self.redact_pdu(redact_id, pdu, shortroomid)?;
}
}
}
@ -1178,15 +1178,33 @@ impl Service {
&self,
event_id: &EventId,
reason: &PduEvent,
shortroomid: u64,
) -> Result<()> {
// TODO: Don't reserialize, keep original json
if let Some(pdu_id) = self.get_pdu_id(event_id)? {
#[derive(Deserialize)]
struct ExtractBody {
body: String,
}
let mut pdu = self.get_pdu_from_id(&pdu_id)?.ok_or_else(|| {
Error::bad_database("PDU ID points to invalid PDU.")
})?;
if let Ok(content) =
serde_json::from_str::<ExtractBody>(pdu.content.get())
{
services().rooms.search.deindex_pdu(
shortroomid,
&pdu_id,
&content.body,
)?;
}
let room_version_id =
services().rooms.state.get_room_version(&pdu.room_id)?;
pdu.redact(room_version_id, reason)?;
self.replace_pdu(
&pdu_id,
&utils::to_canonical_object(&pdu).expect("PDU is an object"),