mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-15 13:16:56 +00:00
feat: Allow room moderators to view redacted event content (MSC2815)
This commit is contained in:
1 parent
2c605151eb
commit
98fe280de4
9 files changed
+133
-3
No files matched your search
@@ -8,6 +8,7 @@ use conduwuit::{
|
||||
use database::{Database, Deserialized, Json, KeyVal, Map};
|
||||
use futures::{FutureExt, Stream, TryFutureExt, TryStreamExt, future::select_ok, pin_mut};
|
||||
use ruma::{CanonicalJsonObject, EventId, OwnedUserId, RoomId, api::Direction};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
||||
use super::{PduId, RawPduId};
|
||||
use crate::{Dep, rooms, rooms::short::ShortRoomId};
|
||||
@@ -16,6 +17,7 @@ pub(super) struct Data {
|
||||
eventid_outlierpdu: Arc<Map>,
|
||||
eventid_pduid: Arc<Map>,
|
||||
pduid_pdu: Arc<Map>,
|
||||
pduid_unredactedcontent: Arc<Map>,
|
||||
roomid_lasttimelinecount: Arc<Map>,
|
||||
userroomid_highlightcount: Arc<Map>,
|
||||
userroomid_notificationcount: Arc<Map>,
|
||||
@@ -36,6 +38,7 @@ impl Data {
|
||||
eventid_outlierpdu: db["eventid_outlierpdu"].clone(),
|
||||
eventid_pduid: db["eventid_pduid"].clone(),
|
||||
pduid_pdu: db["pduid_pdu"].clone(),
|
||||
pduid_unredactedcontent: db["pduid_unredactedcontent"].clone(),
|
||||
roomid_lasttimelinecount: db["roomid_lasttimelinecount"].clone(),
|
||||
userroomid_highlightcount: db["userroomid_highlightcount"].clone(),
|
||||
userroomid_notificationcount: db["userroomid_notificationcount"].clone(),
|
||||
@@ -234,6 +237,20 @@ impl Data {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn save_unredacted_content(&self, pdu_id: &RawPduId, content: &RawJsonValue) {
|
||||
self.pduid_unredactedcontent.raw_put(pdu_id, Json(content));
|
||||
}
|
||||
|
||||
pub(super) async fn get_unredacted_content(
|
||||
&self,
|
||||
pdu_id: &RawPduId,
|
||||
) -> Result<Box<RawJsonValue>> {
|
||||
self.pduid_unredactedcontent
|
||||
.get(pdu_id)
|
||||
.await
|
||||
.deserialized()
|
||||
}
|
||||
|
||||
/// Returns an iterator over all events and their tokens in a room that
|
||||
/// happened before the event with id `until` in reverse-chronological
|
||||
/// order.
|
||||
|
||||
@@ -25,6 +25,7 @@ use ruma::{
|
||||
events::room::encrypted::Relation,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
||||
use self::data::Data;
|
||||
pub use self::{create::pdu_fits, data::PdusIterItem};
|
||||
@@ -242,6 +243,11 @@ impl Service {
|
||||
self.db.replace_pdu(pdu_id, pdu_json).await
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn get_unredacted_content(&self, pdu_id: &RawPduId) -> Result<Box<RawJsonValue>> {
|
||||
self.db.get_unredacted_content(pdu_id).await
|
||||
}
|
||||
|
||||
/// Returns an iterator over all PDUs in a room. Unknown rooms produce no
|
||||
/// items.
|
||||
#[inline]
|
||||
|
||||
@@ -52,6 +52,15 @@ 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
|
||||
{
|
||||
self.db.save_unredacted_content(&pdu_id, &pdu.content);
|
||||
}
|
||||
|
||||
pdu.redact(&room_version_id, Some(reason.event_id()))?;
|
||||
|
||||
let obj = utils::to_canonical_object(&pdu).map_err(|e| {
|
||||
|
||||
Reference in new issue
Block a user