1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2024-12-28 05:54:31 +01:00

fix: make redactions permanent

This commit is contained in:
timokoesters 2020-06-01 20:58:49 +02:00
parent b519bc6962
commit 5a47c75427
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
3 changed files with 28 additions and 7 deletions

View file

@ -2260,12 +2260,12 @@ pub fn get_message_events_route(
.map(|pdu| pdu.to_room_event()) .map(|pdu| pdu.to_room_event())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
MatrixResult(Ok(dbg!(get_message_events::Response { MatrixResult(Ok(get_message_events::Response {
start: Some(body.from.clone()), start: Some(body.from.clone()),
end: prev_batch, end: prev_batch,
chunk: room_events, chunk: room_events,
state: Vec::new(), state: Vec::new(),
}))) }))
} else { } else {
MatrixResult(Err(Error { MatrixResult(Err(Error {
kind: ErrorKind::Unknown, kind: ErrorKind::Unknown,

View file

@ -8,6 +8,7 @@ use ruma_events::{
room::{ room::{
join_rules, member, join_rules, member,
power_levels::{self, PowerLevelsEventContent}, power_levels::{self, PowerLevelsEventContent},
redaction,
}, },
EventJson, EventType, EventJson, EventType,
}; };
@ -207,7 +208,6 @@ impl Rooms {
globals: &super::globals::Globals, globals: &super::globals::Globals,
) -> Result<EventId> { ) -> Result<EventId> {
// TODO: Make sure this isn't called twice in parallel // TODO: Make sure this isn't called twice in parallel
let prev_events = self.get_pdu_leaves(&room_id)?; let prev_events = self.get_pdu_leaves(&room_id)?;
// Is the event authorized? // Is the event authorized?
@ -404,7 +404,6 @@ impl Rooms {
authorized authorized
} }
EventType::RoomCreate => prev_events.is_empty(), EventType::RoomCreate => prev_events.is_empty(),
// Not allow any of the following events if the sender is not joined. // Not allow any of the following events if the sender is not joined.
_ if sender_membership != member::MembershipState::Join => false, _ if sender_membership != member::MembershipState::Join => false,
@ -450,15 +449,15 @@ impl Rooms {
origin_server_ts: utils::millis_since_unix_epoch() origin_server_ts: utils::millis_since_unix_epoch()
.try_into() .try_into()
.expect("this only fails many years in the future"), .expect("this only fails many years in the future"),
kind: event_type, kind: event_type.clone(),
content, content: content.clone(),
state_key, state_key,
prev_events, prev_events,
depth: depth depth: depth
.try_into() .try_into()
.expect("depth can overflow and should be deprecated..."), .expect("depth can overflow and should be deprecated..."),
auth_events: Vec::new(), auth_events: Vec::new(),
redacts, redacts: redacts.clone(),
unsigned, unsigned,
hashes: ruma_federation_api::EventHash { hashes: ruma_federation_api::EventHash {
sha256: "aaa".to_owned(), sha256: "aaa".to_owned(),
@ -506,6 +505,22 @@ impl Rooms {
self.roomstateid_pdu.insert(key, &*pdu_json.to_string())?; self.roomstateid_pdu.insert(key, &*pdu_json.to_string())?;
} }
match event_type {
EventType::RoomRedaction => {
if let Some(redact_id) = &redacts {
// TODO: Reason
let _reason = serde_json::from_value::<
EventJson<redaction::RedactionEventContent>,
>(content)?
.deserialize()?
.reason;
self.redact_pdu(&redact_id)?;
}
}
_ => {}
}
self.edus.room_read_set(&room_id, &sender, index)?; self.edus.room_read_set(&room_id, &sender, index)?;
Ok(pdu.event_id) Ok(pdu.event_id)

View file

@ -7,6 +7,7 @@ use ruma_events::{
use ruma_federation_api::EventHash; use ruma_federation_api::EventHash;
use ruma_identifiers::{EventId, RoomId, UserId}; use ruma_identifiers::{EventId, RoomId, UserId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::json;
use std::collections::HashMap; use std::collections::HashMap;
#[derive(Deserialize, Serialize)] #[derive(Deserialize, Serialize)]
@ -62,6 +63,11 @@ impl PduEvent {
} }
} }
self.unsigned.insert(
"redacted_because".to_owned(),
json!({"content": {}, "type": "m.room.redaction"}),
);
self.content = new_content.into(); self.content = new_content.into();
} }