diff --git a/src/api/client/room/event.rs b/src/api/client/room/event.rs index b66f8bcaf..379cc2dd6 100644 --- a/src/api/client/room/event.rs +++ b/src/api/client/room/event.rs @@ -95,18 +95,18 @@ pub(crate) async fn get_room_event_route( } async fn unredact(services: &crate::State, sender_user: &UserId, event: &mut PduEvent) -> Result { - let power_levels = services - .rooms - .state_accessor - .get_room_power_levels(&event.room_id_or_hash()) - .await; + if !services.users.is_admin(sender_user).await { + let power_levels = services + .rooms + .state_accessor + .get_room_power_levels(&event.room_id_or_hash()) + .await; - if power_levels.for_user(sender_user) < power_levels.redact - && !services.users.is_admin(sender_user).await - { - return Err!(Request(Forbidden( - "You don't have permission to view redacted content in this room." - ))); + if power_levels.for_user(sender_user) < power_levels.redact { + return Err!(Request(Forbidden( + "You don't have permission to view redacted content in this room." + ))); + } } let content = services diff --git a/src/service/rooms/timeline/mod.rs b/src/service/rooms/timeline/mod.rs index d603757c6..69c7faa70 100644 --- a/src/service/rooms/timeline/mod.rs +++ b/src/service/rooms/timeline/mod.rs @@ -93,7 +93,7 @@ struct Services { users: Dep, } -const PURGE_INTERVAL_SECS: u64 = 60 * 60; +const PURGE_INTERVAL_SECS: u64 = 3600; type RoomMutexMap = MutexMap; pub type RoomMutexGuard = MutexMapGuard; diff --git a/src/service/rooms/timeline/redact.rs b/src/service/rooms/timeline/redact.rs index 6fa9fb020..d6a67be63 100644 --- a/src/service/rooms/timeline/redact.rs +++ b/src/service/rooms/timeline/redact.rs @@ -4,7 +4,7 @@ use conduwuit_core::{ utils::{self}, warn, }; -use ruma::{EventId, events::room::encrypted::Relation}; +use ruma::{EventId, events::room::encrypted::Relation, signatures::content_hash}; use super::{ExtractBody, ExtractRelatesTo}; use crate::rooms::short::ShortRoomId; @@ -52,13 +52,18 @@ impl super::Service { .get_room_version(&pdu.room_id_or_hash()) .await?; - if !pdu.is_redacted() - && self - .services - .config - .allow_moderators_to_view_redacted_content + if self + .services + .config + .allow_moderators_to_view_redacted_content { - self.db.save_unredacted_content(&pdu_id, &pdu.content); + let mut pdu_json = self.get_pdu_json_from_id(&pdu_id).await?; + pdu_json.remove("event_id"); + if content_hash(&pdu_json) + .is_ok_and(|hash| hash.encode() == pdu.hashes.sha256.trim_end_matches('=')) + { + self.db.save_unredacted_content(&pdu_id, &pdu.content); + } } pdu.redact(&room_version_id, Some(reason.event_id()))?;