use std::ops::Deref;
use ruma_common::{room::JoinRuleKind, serde::from_raw_json_value};
use serde::Deserialize;
use super::Event;
#[derive(Debug, Clone)]
pub struct RoomJoinRulesEvent<E: Event>(E);
impl<E: Event> RoomJoinRulesEvent<E> {
pub fn new(event: E) -> Self {
Self(event)
}
pub fn join_rule(&self) -> Result<JoinRuleKind, String> {
#[derive(Deserialize)]
struct RoomJoinRulesContentJoinRule {
join_rule: JoinRuleKind,
}
let content: RoomJoinRulesContentJoinRule =
from_raw_json_value(self.content()).map_err(|err: serde_json::Error| {
format!("missing or invalid `join_rule` field in `m.room.join_rules` event: {err}")
})?;
Ok(content.join_rule)
}
}
impl<E: Event> Deref for RoomJoinRulesEvent<E> {
type Target = E;
fn deref(&self) -> &Self::Target {
&self.0
}
}