Do not overwrite retained PDU
This commit is contained in:
@@ -10,6 +10,8 @@ use tuwunel_core::{
|
|||||||
};
|
};
|
||||||
use tuwunel_database::{Deserialized, Json, Map};
|
use tuwunel_database::{Deserialized, Json, Map};
|
||||||
|
|
||||||
|
use crate::rooms::timeline::RoomMutexGuard;
|
||||||
|
|
||||||
pub struct Service {
|
pub struct Service {
|
||||||
services: Arc<crate::services::OnceServices>,
|
services: Arc<crate::services::OnceServices>,
|
||||||
eventid_originalpdu: Arc<Map>,
|
eventid_originalpdu: Arc<Map>,
|
||||||
@@ -83,11 +85,25 @@ pub async fn get_original_pdu_json(&self, event_id: &EventId) -> Result<Canonica
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[implement(Service)]
|
#[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 {
|
if !self.services.config.save_unredacted_events {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self
|
||||||
|
.eventid_originalpdu
|
||||||
|
.exists(event_id)
|
||||||
|
.await
|
||||||
|
.is_ok()
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let now = SystemTime::now()
|
let now = SystemTime::now()
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ where
|
|||||||
.log_err()
|
.log_err()
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
self.append_pdu_effects(pdu_id, pdu, shortroomid, count)
|
self.append_pdu_effects(pdu_id, pdu, shortroomid, count, state_lock)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
drop(next_count1);
|
drop(next_count1);
|
||||||
@@ -207,6 +207,7 @@ async fn append_pdu_effects(
|
|||||||
pdu: &PduEvent,
|
pdu: &PduEvent,
|
||||||
shortroomid: ShortRoomId,
|
shortroomid: ShortRoomId,
|
||||||
count: PduCount,
|
count: PduCount,
|
||||||
|
state_lock: &RoomMutexGuard,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
match *pdu.kind() {
|
match *pdu.kind() {
|
||||||
| TimelineEventType::RoomRedaction => {
|
| TimelineEventType::RoomRedaction => {
|
||||||
@@ -233,7 +234,7 @@ async fn append_pdu_effects(
|
|||||||
.user_can_redact(redact_id, pdu.sender(), pdu.room_id(), false)
|
.user_can_redact(redact_id, pdu.sender(), pdu.room_id(), false)
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
self.redact_pdu(redact_id, pdu, shortroomid)
|
self.redact_pdu(redact_id, pdu, shortroomid, state_lock)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use ruma::{
|
|||||||
};
|
};
|
||||||
use tuwunel_core::{Result, err, implement, matrix::event::Event};
|
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.
|
/// Replace a PDU with the redacted form.
|
||||||
#[implement(super::Service)]
|
#[implement(super::Service)]
|
||||||
@@ -14,6 +14,7 @@ pub async fn redact_pdu<Pdu: Event + Send + Sync>(
|
|||||||
event_id: &EventId,
|
event_id: &EventId,
|
||||||
reason: &Pdu,
|
reason: &Pdu,
|
||||||
shortroomid: ShortRoomId,
|
shortroomid: ShortRoomId,
|
||||||
|
state_lock: &RoomMutexGuard,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let Ok(pdu_id) = self.get_pdu_id(event_id).await else {
|
let Ok(pdu_id) = self.get_pdu_id(event_id).await else {
|
||||||
// If event does not exist, just noop
|
// If event does not exist, just noop
|
||||||
@@ -30,7 +31,8 @@ pub async fn redact_pdu<Pdu: Event + Send + Sync>(
|
|||||||
|
|
||||||
self.services
|
self.services
|
||||||
.retention
|
.retention
|
||||||
.save_original_pdu(event_id, &pdu);
|
.save_original_pdu(event_id, &pdu, state_lock)
|
||||||
|
.await;
|
||||||
|
|
||||||
let body = pdu["content"]
|
let body = pdu["content"]
|
||||||
.as_object()
|
.as_object()
|
||||||
|
|||||||
Reference in New Issue
Block a user