Do not overwrite retained PDU

This commit is contained in:
dasha_uwu
2026-01-27 08:35:52 +05:00
committed by Jason Volk
parent 010c519677
commit 712c0c9487
3 changed files with 24 additions and 5 deletions

View File

@@ -10,6 +10,8 @@ use tuwunel_core::{
};
use tuwunel_database::{Deserialized, Json, Map};
use crate::rooms::timeline::RoomMutexGuard;
pub struct Service {
services: Arc<crate::services::OnceServices>,
eventid_originalpdu: Arc<Map>,
@@ -83,11 +85,25 @@ pub async fn get_original_pdu_json(&self, event_id: &EventId) -> Result<Canonica
}
#[implement(Service)]
pub fn save_original_pdu(&self, event_id: &EventId, pdu: &CanonicalJsonObject) {
pub async fn save_original_pdu(
&self,
event_id: &EventId,
pdu: &CanonicalJsonObject,
_state_lock: &RoomMutexGuard,
) {
if !self.services.config.save_unredacted_events {
return;
}
if self
.eventid_originalpdu
.exists(event_id)
.await
.is_ok()
{
return;
}
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()

View File

@@ -184,7 +184,7 @@ where
.log_err()
.ok();
self.append_pdu_effects(pdu_id, pdu, shortroomid, count)
self.append_pdu_effects(pdu_id, pdu, shortroomid, count, state_lock)
.await?;
drop(next_count1);
@@ -207,6 +207,7 @@ async fn append_pdu_effects(
pdu: &PduEvent,
shortroomid: ShortRoomId,
count: PduCount,
state_lock: &RoomMutexGuard,
) -> 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?;
}
},

View File

@@ -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<Pdu: Event + Send + Sync>(
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<Pdu: Event + Send + Sync>(
self.services
.retention
.save_original_pdu(event_id, &pdu);
.save_original_pdu(event_id, &pdu, state_lock)
.await;
let body = pdu["content"]
.as_object()