mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 15:51:23 +01:00
fix: de-index pdus when redacted
This commit is contained in:
parent
cc5a9d3440
commit
f74043df9a
3 changed files with 50 additions and 2 deletions
|
|
@ -33,6 +33,29 @@ impl service::rooms::search::Data for KeyValueDatabase {
|
|||
self.tokenids.insert_batch(&mut batch)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
fn deindex_pdu(
|
||||
&self,
|
||||
shortroomid: u64,
|
||||
pdu_id: &[u8],
|
||||
message_body: &str,
|
||||
) -> Result<()> {
|
||||
let batch = tokenize(message_body).map(|word| {
|
||||
let mut key = shortroomid.to_be_bytes().to_vec();
|
||||
key.extend_from_slice(word.as_bytes());
|
||||
key.push(0xFF);
|
||||
// TODO: currently we save the room id a second time here
|
||||
key.extend_from_slice(pdu_id);
|
||||
key
|
||||
});
|
||||
|
||||
for token in batch {
|
||||
self.tokenids.remove(&token)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn search_pdus<'a>(
|
||||
|
|
|
|||
|
|
@ -10,6 +10,13 @@ pub(crate) trait Data: Send + Sync {
|
|||
message_body: &str,
|
||||
) -> Result<()>;
|
||||
|
||||
fn deindex_pdu(
|
||||
&self,
|
||||
shortroomid: u64,
|
||||
pdu_id: &[u8],
|
||||
message_body: &str,
|
||||
) -> Result<()>;
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn search_pdus<'a>(
|
||||
&'a self,
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue