refactor various patterns for serde_json::from_ elim

bump ruma

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-10-03 09:57:43 +00:00 committed by strawberry
parent 55c85f6851
commit d526db681f
9 changed files with 64 additions and 96 deletions

View file

@ -30,8 +30,8 @@ use ruma::{
int,
serde::Base64,
state_res::{self, EventTypeExt, RoomVersion, StateMap},
uint, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId,
RoomVersionId, ServerName,
uint, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, RoomId, RoomVersionId,
ServerName, UserId,
};
use tokio::sync::RwLock;
@ -157,14 +157,10 @@ impl Service {
self.acl_check(origin, room_id).await?;
// 1.3.2 Check room ACL on sender's server name
let sender: OwnedUserId = serde_json::from_value(
value
.get("sender")
.ok_or_else(|| Error::BadRequest(ErrorKind::InvalidParam, "PDU does not have a sender key"))?
.clone()
.into(),
)
.map_err(|_| Error::BadRequest(ErrorKind::BadJson, "User ID in sender is invalid"))?;
let sender: &UserId = value
.get("sender")
.try_into()
.map_err(|e| err!(Request(InvalidParam("PDU does not have a valid sender key: {e}"))))?;
self.acl_check(sender.server_name(), room_id).await?;

View file

@ -9,6 +9,7 @@ use std::{
use conduit::{
err,
result::FlatOk,
utils::{calculate_hash, stream::TryIgnore, IterStream, MutexMap, MutexMapGuard},
warn, PduEvent, Result,
};

View file

@ -528,12 +528,8 @@ impl Service {
for pdu in pdus {
// Redacted events are not notification targets (we don't send push for them)
if let Some(unsigned) = &pdu.unsigned {
if let Ok(unsigned) = serde_json::from_str::<serde_json::Value>(unsigned.get()) {
if unsigned.get("redacted_because").is_some() {
continue;
}
}
if pdu.contains_unsigned_property("redacted_because", serde_json::Value::is_string) {
continue;
}
let rules_for_user = self