mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-09-12 17:33:57 +02:00
Split timeline service.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
c06aa49a90
commit
c5c309ec43
7 changed files with 1146 additions and 1068 deletions
51
src/service/rooms/timeline/redact.rs
Normal file
51
src/service/rooms/timeline/redact.rs
Normal file
|
@ -0,0 +1,51 @@
|
|||
use conduwuit_core::{
|
||||
Result, err, implement,
|
||||
matrix::event::Event,
|
||||
utils::{self},
|
||||
};
|
||||
use ruma::EventId;
|
||||
|
||||
use super::ExtractBody;
|
||||
use crate::rooms::short::ShortRoomId;
|
||||
|
||||
/// Replace a PDU with the redacted form.
|
||||
#[implement(super::Service)]
|
||||
#[tracing::instrument(name = "redact", level = "debug", skip(self))]
|
||||
pub async fn redact_pdu<Pdu: Event + Send + Sync>(
|
||||
&self,
|
||||
event_id: &EventId,
|
||||
reason: &Pdu,
|
||||
shortroomid: ShortRoomId,
|
||||
) -> Result {
|
||||
// TODO: Don't reserialize, keep original json
|
||||
let Ok(pdu_id) = self.get_pdu_id(event_id).await else {
|
||||
// If event does not exist, just noop
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let mut pdu = self
|
||||
.get_pdu_from_id(&pdu_id)
|
||||
.await
|
||||
.map(Event::into_pdu)
|
||||
.map_err(|e| {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
let room_version_id = self.services.state.get_room_version(pdu.room_id()).await?;
|
||||
|
||||
pdu.redact(&room_version_id, reason.to_value())?;
|
||||
|
||||
let obj = utils::to_canonical_object(&pdu).map_err(|e| {
|
||||
err!(Database(error!(?event_id, ?e, "Failed to convert PDU to canonical JSON")))
|
||||
})?;
|
||||
|
||||
self.replace_pdu(&pdu_id, &obj).await
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue