|
|
@ -1,5 +1,6 @@
|
|
|
|
use crate::Error;
|
|
|
|
use crate::Error;
|
|
|
|
use ruma::{
|
|
|
|
use ruma::{
|
|
|
|
|
|
|
|
canonical_json::redact_content_in_place,
|
|
|
|
events::{
|
|
|
|
events::{
|
|
|
|
room::member::RoomMemberEventContent, space::child::HierarchySpaceChildEvent,
|
|
|
|
room::member::RoomMemberEventContent, space::child::HierarchySpaceChildEvent,
|
|
|
|
AnyEphemeralRoomEvent, AnyMessageLikeEvent, AnyStateEvent, AnyStrippedStateEvent,
|
|
|
|
AnyEphemeralRoomEvent, AnyMessageLikeEvent, AnyStateEvent, AnyStrippedStateEvent,
|
|
|
@ -56,53 +57,16 @@ impl PduEvent {
|
|
|
|
) -> crate::Result<()> {
|
|
|
|
) -> crate::Result<()> {
|
|
|
|
self.unsigned = None;
|
|
|
|
self.unsigned = None;
|
|
|
|
|
|
|
|
|
|
|
|
let allowed: &[&str] = match self.kind {
|
|
|
|
let mut content = serde_json::from_str(self.content.get())
|
|
|
|
TimelineEventType::RoomMember => &["join_authorised_via_users_server", "membership"],
|
|
|
|
.map_err(|_| Error::bad_database("PDU in db has invalid content."))?;
|
|
|
|
TimelineEventType::RoomCreate => match room_version_id {
|
|
|
|
redact_content_in_place(&mut content, &room_version_id, self.kind.to_string())
|
|
|
|
RoomVersionId::V1
|
|
|
|
.map_err(|e| Error::RedactionError(self.sender.server_name().to_owned(), e))?;
|
|
|
|
| RoomVersionId::V2
|
|
|
|
|
|
|
|
| RoomVersionId::V3
|
|
|
|
|
|
|
|
| RoomVersionId::V4
|
|
|
|
|
|
|
|
| RoomVersionId::V5
|
|
|
|
|
|
|
|
| RoomVersionId::V6
|
|
|
|
|
|
|
|
| RoomVersionId::V7
|
|
|
|
|
|
|
|
| RoomVersionId::V8
|
|
|
|
|
|
|
|
| RoomVersionId::V9
|
|
|
|
|
|
|
|
| RoomVersionId::V10 => &["creator"],
|
|
|
|
|
|
|
|
_ => &[], // V11 removed the creator key
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
TimelineEventType::RoomJoinRules => &["join_rule"],
|
|
|
|
|
|
|
|
TimelineEventType::RoomPowerLevels => &[
|
|
|
|
|
|
|
|
"ban",
|
|
|
|
|
|
|
|
"events",
|
|
|
|
|
|
|
|
"events_default",
|
|
|
|
|
|
|
|
"kick",
|
|
|
|
|
|
|
|
"redact",
|
|
|
|
|
|
|
|
"state_default",
|
|
|
|
|
|
|
|
"users",
|
|
|
|
|
|
|
|
"users_default",
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
TimelineEventType::RoomHistoryVisibility => &["history_visibility"],
|
|
|
|
|
|
|
|
_ => &[],
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut old_content: BTreeMap<String, serde_json::Value> =
|
|
|
|
|
|
|
|
serde_json::from_str(self.content.get())
|
|
|
|
|
|
|
|
.map_err(|_| Error::bad_database("PDU in db has invalid content."))?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut new_content = serde_json::Map::new();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for key in allowed {
|
|
|
|
|
|
|
|
if let Some(value) = old_content.remove(*key) {
|
|
|
|
|
|
|
|
new_content.insert((*key).to_owned(), value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.unsigned = Some(to_raw_value(&json!({
|
|
|
|
self.unsigned = Some(to_raw_value(&json!({
|
|
|
|
"redacted_because": serde_json::to_value(reason).expect("to_value(PduEvent) always works")
|
|
|
|
"redacted_because": serde_json::to_value(reason).expect("to_value(PduEvent) always works")
|
|
|
|
})).expect("to string always works"));
|
|
|
|
})).expect("to string always works"));
|
|
|
|
|
|
|
|
|
|
|
|
self.content = to_raw_value(&new_content).expect("to string always works");
|
|
|
|
self.content = to_raw_value(&content).expect("to string always works");
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|