untwist the redaction check stanza
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
1a8482b3b4
commit
ff8bbd4cfa
2 changed files with 28 additions and 42 deletions
|
@ -90,3 +90,21 @@ pub fn copy_redacts(&self) -> (Option<OwnedEventId>, Box<RawJsonValue>) {
|
||||||
|
|
||||||
(self.redacts.clone(), self.content.clone())
|
(self.redacts.clone(), self.content.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[implement(super::Pdu)]
|
||||||
|
#[must_use]
|
||||||
|
pub fn redacts_id(&self, room_version: &RoomVersionId) -> Option<OwnedEventId> {
|
||||||
|
use RoomVersionId::*;
|
||||||
|
|
||||||
|
if self.kind != TimelineEventType::RoomRedaction {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
match *room_version {
|
||||||
|
| V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 => self.redacts.clone(),
|
||||||
|
| _ =>
|
||||||
|
self.get_content::<RoomRedactionEventContent>()
|
||||||
|
.ok()?
|
||||||
|
.redacts,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -13,9 +13,9 @@ use conduwuit::{
|
||||||
};
|
};
|
||||||
use futures::{future::ready, FutureExt, StreamExt};
|
use futures::{future::ready, FutureExt, StreamExt};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
events::{room::redaction::RoomRedactionEventContent, StateEventType, TimelineEventType},
|
events::StateEventType,
|
||||||
state_res::{self, EventTypeExt},
|
state_res::{self, EventTypeExt},
|
||||||
CanonicalJsonValue, RoomId, RoomVersionId, ServerName,
|
CanonicalJsonValue, RoomId, ServerName,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{get_room_version_id, to_room_version};
|
use super::{get_room_version_id, to_room_version};
|
||||||
|
@ -127,46 +127,14 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu(
|
||||||
|
|
||||||
// Soft fail check before doing state res
|
// Soft fail check before doing state res
|
||||||
debug!("Performing soft-fail check");
|
debug!("Performing soft-fail check");
|
||||||
let soft_fail = {
|
let soft_fail = match (auth_check, incoming_pdu.redacts_id(&room_version_id)) {
|
||||||
use RoomVersionId::*;
|
| (false, _) => true,
|
||||||
|
| (true, None) => false,
|
||||||
!auth_check
|
| (true, Some(redact_id)) =>
|
||||||
|| incoming_pdu.kind == TimelineEventType::RoomRedaction
|
self.services
|
||||||
&& match room_version_id {
|
.state_accessor
|
||||||
| V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 => {
|
.user_can_redact(&redact_id, &incoming_pdu.sender, &incoming_pdu.room_id, true)
|
||||||
if let Some(redact_id) = &incoming_pdu.redacts {
|
.await?,
|
||||||
!self
|
|
||||||
.services
|
|
||||||
.state_accessor
|
|
||||||
.user_can_redact(
|
|
||||||
redact_id,
|
|
||||||
&incoming_pdu.sender,
|
|
||||||
&incoming_pdu.room_id,
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
.await?
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
| _ => {
|
|
||||||
let content: RoomRedactionEventContent = incoming_pdu.get_content()?;
|
|
||||||
if let Some(redact_id) = &content.redacts {
|
|
||||||
!self
|
|
||||||
.services
|
|
||||||
.state_accessor
|
|
||||||
.user_can_redact(
|
|
||||||
redact_id,
|
|
||||||
&incoming_pdu.sender,
|
|
||||||
&incoming_pdu.room_id,
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
.await?
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 13. Use state resolution to find new room state
|
// 13. Use state resolution to find new room state
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue