reduce RoomVersionId patterns
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
b87f1649d4
commit
b8baa1223d
7 changed files with 121 additions and 197 deletions
|
@ -551,49 +551,44 @@ impl Service {
|
|||
|
||||
// Soft fail check before doing state res
|
||||
debug!("Performing soft-fail check");
|
||||
let soft_fail = !state_res::event_auth::auth_check(&room_version, &incoming_pdu, None::<PduEvent>, |k, s| {
|
||||
auth_events.get(&(k.clone(), s.to_owned()))
|
||||
})
|
||||
.map_err(|_e| Error::BadRequest(ErrorKind::forbidden(), "Auth check failed."))?
|
||||
|| incoming_pdu.kind == TimelineEventType::RoomRedaction
|
||||
&& match room_version_id {
|
||||
RoomVersionId::V1
|
||||
| RoomVersionId::V2
|
||||
| RoomVersionId::V3
|
||||
| RoomVersionId::V4
|
||||
| RoomVersionId::V5
|
||||
| RoomVersionId::V6
|
||||
| RoomVersionId::V7
|
||||
| RoomVersionId::V8
|
||||
| RoomVersionId::V9
|
||||
| RoomVersionId::V10 => {
|
||||
if let Some(redact_id) = &incoming_pdu.redacts {
|
||||
!services().rooms.state_accessor.user_can_redact(
|
||||
redact_id,
|
||||
&incoming_pdu.sender,
|
||||
&incoming_pdu.room_id,
|
||||
true,
|
||||
)?
|
||||
} else {
|
||||
false
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
let content = serde_json::from_str::<RoomRedactionEventContent>(incoming_pdu.content.get())
|
||||
.map_err(|_| Error::bad_database("Invalid content in redaction pdu."))?;
|
||||
let soft_fail = {
|
||||
use RoomVersionId::*;
|
||||
|
||||
if let Some(redact_id) = &content.redacts {
|
||||
!services().rooms.state_accessor.user_can_redact(
|
||||
redact_id,
|
||||
&incoming_pdu.sender,
|
||||
&incoming_pdu.room_id,
|
||||
true,
|
||||
)?
|
||||
} else {
|
||||
false
|
||||
}
|
||||
},
|
||||
};
|
||||
!state_res::event_auth::auth_check(&room_version, &incoming_pdu, None::<PduEvent>, |k, s| {
|
||||
auth_events.get(&(k.clone(), s.to_owned()))
|
||||
})
|
||||
.map_err(|_e| Error::BadRequest(ErrorKind::forbidden(), "Auth check failed."))?
|
||||
|| incoming_pdu.kind == TimelineEventType::RoomRedaction
|
||||
&& match room_version_id {
|
||||
V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 => {
|
||||
if let Some(redact_id) = &incoming_pdu.redacts {
|
||||
!services().rooms.state_accessor.user_can_redact(
|
||||
redact_id,
|
||||
&incoming_pdu.sender,
|
||||
&incoming_pdu.room_id,
|
||||
true,
|
||||
)?
|
||||
} else {
|
||||
false
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
let content = serde_json::from_str::<RoomRedactionEventContent>(incoming_pdu.content.get())
|
||||
.map_err(|_| Error::bad_database("Invalid content in redaction pdu."))?;
|
||||
|
||||
if let Some(redact_id) = &content.redacts {
|
||||
!services().rooms.state_accessor.user_can_redact(
|
||||
redact_id,
|
||||
&incoming_pdu.sender,
|
||||
&incoming_pdu.room_id,
|
||||
true,
|
||||
)?
|
||||
} else {
|
||||
false
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// 13. Use state resolution to find new room state
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue