impl Deserialize for m.room.server_acl
This commit is contained in:
parent
db89aad22c
commit
c309eed2ae
@ -4,11 +4,12 @@ use std::{convert::TryFrom, str::FromStr};
|
|||||||
|
|
||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||||
use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
|
use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
default_true, Event, EventType, InnerInvalidEvent, InvalidEvent, RoomEvent, StateEvent,
|
default_true, Event, EventResult, EventType, InnerInvalidEvent, InvalidEvent, RoomEvent,
|
||||||
|
StateEvent,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// An event to indicate which servers are permitted to participate in the room.
|
/// An event to indicate which servers are permitted to participate in the room.
|
||||||
@ -69,6 +70,46 @@ pub struct ServerAclEventContent {
|
|||||||
pub deny: Vec<String>,
|
pub deny: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'de> Deserialize<'de> for EventResult<ServerAclEvent> {
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let json = serde_json::Value::deserialize(deserializer)?;
|
||||||
|
|
||||||
|
let raw: raw::ServerAclEvent = match serde_json::from_value(json.clone()) {
|
||||||
|
Ok(raw) => raw,
|
||||||
|
Err(error) => {
|
||||||
|
return Ok(EventResult::Err(InvalidEvent(
|
||||||
|
InnerInvalidEvent::Validation {
|
||||||
|
json,
|
||||||
|
message: error.to_string(),
|
||||||
|
},
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(EventResult::Ok(ServerAclEvent {
|
||||||
|
content: ServerAclEventContent {
|
||||||
|
allow_ip_literals: raw.content.allow_ip_literals,
|
||||||
|
allow: raw.content.allow,
|
||||||
|
deny: raw.content.deny,
|
||||||
|
},
|
||||||
|
event_id: raw.event_id,
|
||||||
|
origin_server_ts: raw.origin_server_ts,
|
||||||
|
prev_content: raw.prev_content.map(|prev| ServerAclEventContent {
|
||||||
|
allow_ip_literals: prev.allow_ip_literals,
|
||||||
|
allow: prev.allow,
|
||||||
|
deny: prev.deny,
|
||||||
|
}),
|
||||||
|
room_id: raw.room_id,
|
||||||
|
unsigned: raw.unsigned,
|
||||||
|
sender: raw.sender,
|
||||||
|
state_key: raw.state_key,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl FromStr for ServerAclEvent {
|
impl FromStr for ServerAclEvent {
|
||||||
type Err = InvalidEvent;
|
type Err = InvalidEvent;
|
||||||
|
|
||||||
@ -139,6 +180,33 @@ impl_state_event!(
|
|||||||
EventType::RoomServerAcl
|
EventType::RoomServerAcl
|
||||||
);
|
);
|
||||||
|
|
||||||
|
impl<'de> Deserialize<'de> for EventResult<ServerAclEventContent> {
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let json = serde_json::Value::deserialize(deserializer)?;
|
||||||
|
|
||||||
|
let raw: raw::ServerAclEventContent = match serde_json::from_value(json.clone()) {
|
||||||
|
Ok(raw) => raw,
|
||||||
|
Err(error) => {
|
||||||
|
return Ok(EventResult::Err(InvalidEvent(
|
||||||
|
InnerInvalidEvent::Validation {
|
||||||
|
json,
|
||||||
|
message: error.to_string(),
|
||||||
|
},
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(EventResult::Ok(ServerAclEventContent {
|
||||||
|
allow_ip_literals: raw.allow_ip_literals,
|
||||||
|
allow: raw.allow,
|
||||||
|
deny: raw.deny,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl FromStr for ServerAclEventContent {
|
impl FromStr for ServerAclEventContent {
|
||||||
type Err = InvalidEvent;
|
type Err = InvalidEvent;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user