From 712c0c94874dedccecd061ae007a72370b1b65e9 Mon Sep 17 00:00:00 2001 From: dasha_uwu Date: Tue, 27 Jan 2026 08:35:52 +0500 Subject: [PATCH] Do not overwrite retained PDU --- src/service/rooms/retention/mod.rs | 18 +++++++++++++++++- src/service/rooms/timeline/append.rs | 5 +++-- src/service/rooms/timeline/redact.rs | 6 ++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/service/rooms/retention/mod.rs b/src/service/rooms/retention/mod.rs index e9c53640..3957fd10 100644 --- a/src/service/rooms/retention/mod.rs +++ b/src/service/rooms/retention/mod.rs @@ -10,6 +10,8 @@ use tuwunel_core::{ }; use tuwunel_database::{Deserialized, Json, Map}; +use crate::rooms::timeline::RoomMutexGuard; + pub struct Service { services: Arc, eventid_originalpdu: Arc, @@ -83,11 +85,25 @@ pub async fn get_original_pdu_json(&self, event_id: &EventId) -> Result Result { match *pdu.kind() { | TimelineEventType::RoomRedaction => { @@ -233,7 +234,7 @@ async fn append_pdu_effects( .user_can_redact(redact_id, pdu.sender(), pdu.room_id(), false) .await? { - self.redact_pdu(redact_id, pdu, shortroomid) + self.redact_pdu(redact_id, pdu, shortroomid, state_lock) .await?; } }, diff --git a/src/service/rooms/timeline/redact.rs b/src/service/rooms/timeline/redact.rs index 3632c1e9..16c6fde4 100644 --- a/src/service/rooms/timeline/redact.rs +++ b/src/service/rooms/timeline/redact.rs @@ -4,7 +4,7 @@ use ruma::{ }; use tuwunel_core::{Result, err, implement, matrix::event::Event}; -use crate::rooms::short::ShortRoomId; +use crate::rooms::{short::ShortRoomId, timeline::RoomMutexGuard}; /// Replace a PDU with the redacted form. #[implement(super::Service)] @@ -14,6 +14,7 @@ pub async fn redact_pdu( event_id: &EventId, reason: &Pdu, shortroomid: ShortRoomId, + state_lock: &RoomMutexGuard, ) -> Result { let Ok(pdu_id) = self.get_pdu_id(event_id).await else { // If event does not exist, just noop @@ -30,7 +31,8 @@ pub async fn redact_pdu( self.services .retention - .save_original_pdu(event_id, &pdu); + .save_original_pdu(event_id, &pdu, state_lock) + .await; let body = pdu["content"] .as_object()