Add back all commented-out room events
This commit is contained in:
parent
7d303fff7e
commit
74f680f8ed
12
src/room.rs
12
src/room.rs
@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
pub mod aliases;
|
||||
pub mod avatar;
|
||||
// pub mod canonical_alias;
|
||||
pub mod canonical_alias;
|
||||
pub mod create;
|
||||
pub mod encrypted;
|
||||
pub mod encryption;
|
||||
@ -17,12 +17,12 @@ pub mod guest_access;
|
||||
pub mod history_visibility;
|
||||
pub mod join_rules;
|
||||
pub mod member;
|
||||
// pub mod message;
|
||||
// pub mod name;
|
||||
// pub mod pinned_events;
|
||||
// pub mod power_levels;
|
||||
pub mod message;
|
||||
pub mod name;
|
||||
pub mod pinned_events;
|
||||
pub mod power_levels;
|
||||
pub mod redaction;
|
||||
// pub mod server_acl;
|
||||
pub mod server_acl;
|
||||
pub mod third_party_invite;
|
||||
pub mod tombstone;
|
||||
pub mod topic;
|
||||
|
@ -31,15 +31,15 @@ mod tests {
|
||||
time::{Duration, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
use ruma_identifiers::{EventId, RoomAliasId, UserId};
|
||||
use ruma_identifiers::{EventId, RoomAliasId, RoomId, UserId};
|
||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||
|
||||
use super::{CanonicalAliasEvent, CanonicalAliasEventContent};
|
||||
use crate::{EventJson, UnsignedData};
|
||||
use super::CanonicalAliasEventContent;
|
||||
use crate::{EventJson, StateEvent, UnsignedData};
|
||||
|
||||
#[test]
|
||||
fn serialization_with_optional_fields_as_none() {
|
||||
let canonical_alias_event = CanonicalAliasEvent {
|
||||
let canonical_alias_event = StateEvent {
|
||||
content: CanonicalAliasEventContent {
|
||||
alias: Some(RoomAliasId::try_from("#somewhere:localhost").unwrap()),
|
||||
alt_aliases: Vec::new(),
|
||||
@ -47,7 +47,7 @@ mod tests {
|
||||
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1),
|
||||
prev_content: None,
|
||||
room_id: None,
|
||||
room_id: RoomId::try_from("!dummy:example.com").unwrap(),
|
||||
sender: UserId::try_from("@carl:example.com").unwrap(),
|
||||
state_key: "".to_string(),
|
||||
unsigned: UnsignedData::default(),
|
||||
@ -60,6 +60,7 @@ mod tests {
|
||||
},
|
||||
"event_id": "$h29iv0s8:example.com",
|
||||
"origin_server_ts": 1,
|
||||
"room_id": "!dummy:example.com",
|
||||
"sender": "@carl:example.com",
|
||||
"state_key": "",
|
||||
"type": "m.room.canonical_alias"
|
||||
@ -74,13 +75,14 @@ mod tests {
|
||||
"content": {},
|
||||
"event_id": "$h29iv0s8:example.com",
|
||||
"origin_server_ts": 1,
|
||||
"room_id": "!dummy:example.com",
|
||||
"sender": "@carl:example.com",
|
||||
"state_key": "",
|
||||
"type": "m.room.canonical_alias"
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
from_json_value::<EventJson<CanonicalAliasEvent>>(json_data)
|
||||
from_json_value::<EventJson<StateEvent<CanonicalAliasEventContent>>>(json_data)
|
||||
.unwrap()
|
||||
.deserialize()
|
||||
.unwrap()
|
||||
@ -98,12 +100,13 @@ mod tests {
|
||||
},
|
||||
"event_id": "$h29iv0s8:example.com",
|
||||
"origin_server_ts": 1,
|
||||
"room_id": "!dummy:example.com",
|
||||
"sender": "@carl:example.com",
|
||||
"state_key": "",
|
||||
"type": "m.room.canonical_alias"
|
||||
});
|
||||
assert_eq!(
|
||||
from_json_value::<EventJson<CanonicalAliasEvent>>(json_data)
|
||||
from_json_value::<EventJson<StateEvent<CanonicalAliasEventContent>>>(json_data)
|
||||
.unwrap()
|
||||
.deserialize()
|
||||
.unwrap()
|
||||
@ -121,12 +124,13 @@ mod tests {
|
||||
},
|
||||
"event_id": "$h29iv0s8:example.com",
|
||||
"origin_server_ts": 1,
|
||||
"room_id": "!dummy:example.com",
|
||||
"sender": "@carl:example.com",
|
||||
"state_key": "",
|
||||
"type": "m.room.canonical_alias"
|
||||
});
|
||||
assert_eq!(
|
||||
from_json_value::<EventJson<CanonicalAliasEvent>>(json_data)
|
||||
from_json_value::<EventJson<StateEvent<CanonicalAliasEventContent>>>(json_data)
|
||||
.unwrap()
|
||||
.deserialize()
|
||||
.unwrap()
|
||||
@ -145,12 +149,13 @@ mod tests {
|
||||
},
|
||||
"event_id": "$h29iv0s8:example.com",
|
||||
"origin_server_ts": 1,
|
||||
"room_id": "!dummy:example.com",
|
||||
"sender": "@carl:example.com",
|
||||
"state_key": "",
|
||||
"type": "m.room.canonical_alias"
|
||||
});
|
||||
assert_eq!(
|
||||
from_json_value::<EventJson<CanonicalAliasEvent>>(json_data)
|
||||
from_json_value::<EventJson<StateEvent<CanonicalAliasEventContent>>>(json_data)
|
||||
.unwrap()
|
||||
.deserialize()
|
||||
.unwrap()
|
||||
|
@ -3,6 +3,7 @@
|
||||
use std::time::SystemTime;
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_events_macros::MessageEventContent;
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@ -12,7 +13,8 @@ use crate::{FromRaw, UnsignedData};
|
||||
pub mod feedback;
|
||||
|
||||
/// The payload for `MessageEvent`.
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
#[derive(Clone, Debug, Serialize, MessageEventContent)]
|
||||
#[ruma_event(type = "m.room.message")]
|
||||
#[serde(tag = "msgtype")]
|
||||
pub enum MessageEventContent {
|
||||
/// An audio message.
|
||||
@ -473,11 +475,11 @@ mod tests {
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||
|
||||
use super::{
|
||||
AudioMessageEventContent, FormattedBody, MessageEvent, MessageEventContent, MessageFormat,
|
||||
use super::{AudioMessageEventContent, FormattedBody, MessageEventContent, MessageFormat};
|
||||
use crate::{
|
||||
room::message::{InReplyTo, RelatesTo, TextMessageEventContent},
|
||||
EventJson, MessageEvent, UnsignedData,
|
||||
};
|
||||
use crate::room::message::{InReplyTo, RelatesTo, TextMessageEventContent};
|
||||
use crate::{EventJson, UnsignedData};
|
||||
|
||||
#[test]
|
||||
fn serialization() {
|
||||
@ -490,7 +492,7 @@ mod tests {
|
||||
}),
|
||||
event_id: EventId::try_from("$143273582443PhrSn:example.org").unwrap(),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(10_000),
|
||||
room_id: Some(RoomId::try_from("!testroomid:example.org").unwrap()),
|
||||
room_id: RoomId::try_from("!testroomid:example.org").unwrap(),
|
||||
sender: UserId::try_from("@user:example.org").unwrap(),
|
||||
unsigned: UnsignedData::default(),
|
||||
};
|
||||
|
@ -2,13 +2,15 @@
|
||||
|
||||
use std::time::SystemTime;
|
||||
|
||||
use ruma_events_macros::StateEventContent;
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{InvalidInput, TryFromRaw, UnsignedData};
|
||||
|
||||
/// The payload for `NameEvent`.
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
#[derive(Clone, Debug, Serialize, StateEventContent)]
|
||||
#[ruma_event(type = "m.room.name")]
|
||||
pub struct NameEventContent {
|
||||
/// The name of the room. This MUST NOT exceed 255 bytes.
|
||||
pub(crate) name: Option<String>,
|
||||
@ -76,20 +78,20 @@ mod tests {
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||
|
||||
use crate::{EventJson, UnsignedData};
|
||||
use crate::{EventJson, StateEvent, UnsignedData};
|
||||
|
||||
use super::NameEventContent;
|
||||
|
||||
#[test]
|
||||
fn serialization_with_optional_fields_as_none() {
|
||||
let name_event = NameEvent {
|
||||
let name_event = StateEvent {
|
||||
content: NameEventContent {
|
||||
name: Some("The room name".to_string()),
|
||||
},
|
||||
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1),
|
||||
prev_content: None,
|
||||
room_id: None,
|
||||
room_id: RoomId::try_from("!n8f893n9:example.com").unwrap(),
|
||||
sender: UserId::try_from("@carl:example.com").unwrap(),
|
||||
state_key: "".to_string(),
|
||||
unsigned: UnsignedData::default(),
|
||||
@ -102,6 +104,7 @@ mod tests {
|
||||
},
|
||||
"event_id": "$h29iv0s8:example.com",
|
||||
"origin_server_ts": 1,
|
||||
"room_id": "!n8f893n9:example.com",
|
||||
"sender": "@carl:example.com",
|
||||
"state_key": "",
|
||||
"type": "m.room.name"
|
||||
@ -112,7 +115,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn serialization_with_all_fields() {
|
||||
let name_event = NameEvent {
|
||||
let name_event = StateEvent {
|
||||
content: NameEventContent {
|
||||
name: Some("The room name".to_string()),
|
||||
},
|
||||
@ -121,7 +124,7 @@ mod tests {
|
||||
prev_content: Some(NameEventContent {
|
||||
name: Some("The old name".to_string()),
|
||||
}),
|
||||
room_id: Some(RoomId::try_from("!n8f893n9:example.com").unwrap()),
|
||||
room_id: RoomId::try_from("!n8f893n9:example.com").unwrap(),
|
||||
sender: UserId::try_from("@carl:example.com").unwrap(),
|
||||
state_key: "".to_string(),
|
||||
unsigned: UnsignedData {
|
||||
@ -156,12 +159,13 @@ mod tests {
|
||||
"content": {},
|
||||
"event_id": "$h29iv0s8:example.com",
|
||||
"origin_server_ts": 1,
|
||||
"room_id": "!n8f893n9:example.com",
|
||||
"sender": "@carl:example.com",
|
||||
"state_key": "",
|
||||
"type": "m.room.name"
|
||||
});
|
||||
assert_eq!(
|
||||
from_json_value::<EventJson<NameEvent>>(json_data)
|
||||
from_json_value::<EventJson<StateEvent<NameEventContent>>>(json_data)
|
||||
.unwrap()
|
||||
.deserialize()
|
||||
.unwrap()
|
||||
@ -210,12 +214,13 @@ mod tests {
|
||||
},
|
||||
"event_id": "$h29iv0s8:example.com",
|
||||
"origin_server_ts": 1,
|
||||
"room_id": "!n8f893n9:example.com",
|
||||
"sender": "@carl:example.com",
|
||||
"state_key": "",
|
||||
"type": "m.room.name"
|
||||
});
|
||||
assert_eq!(
|
||||
from_json_value::<EventJson<NameEvent>>(json_data)
|
||||
from_json_value::<EventJson<StateEvent<NameEventContent>>>(json_data)
|
||||
.unwrap()
|
||||
.deserialize()
|
||||
.unwrap()
|
||||
@ -233,12 +238,13 @@ mod tests {
|
||||
},
|
||||
"event_id": "$h29iv0s8:example.com",
|
||||
"origin_server_ts": 1,
|
||||
"room_id": "!n8f893n9:example.com",
|
||||
"sender": "@carl:example.com",
|
||||
"state_key": "",
|
||||
"type": "m.room.name"
|
||||
});
|
||||
assert_eq!(
|
||||
from_json_value::<EventJson<NameEvent>>(json_data)
|
||||
from_json_value::<EventJson<StateEvent<NameEventContent>>>(json_data)
|
||||
.unwrap()
|
||||
.deserialize()
|
||||
.unwrap()
|
||||
@ -257,13 +263,14 @@ mod tests {
|
||||
},
|
||||
"event_id": "$h29iv0s8:example.com",
|
||||
"origin_server_ts": 1,
|
||||
"room_id": "!n8f893n9:example.com",
|
||||
"sender": "@carl:example.com",
|
||||
"state_key": "",
|
||||
"type": "m.room.name"
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
from_json_value::<EventJson<NameEvent>>(json_data)
|
||||
from_json_value::<EventJson<StateEvent<NameEventContent>>>(json_data)
|
||||
.unwrap()
|
||||
.deserialize()
|
||||
.unwrap()
|
||||
|
@ -22,10 +22,8 @@ mod tests {
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde_json::to_string;
|
||||
|
||||
use crate::{
|
||||
room::pinned_events::{PinnedEventsEvent, PinnedEventsEventContent},
|
||||
EventJson, UnsignedData,
|
||||
};
|
||||
use super::PinnedEventsEventContent;
|
||||
use crate::{EventJson, StateEvent, UnsignedData};
|
||||
|
||||
#[test]
|
||||
fn serialization_deserialization() {
|
||||
@ -34,23 +32,24 @@ mod tests {
|
||||
content.pinned.push(EventId::new("example.com").unwrap());
|
||||
content.pinned.push(EventId::new("example.com").unwrap());
|
||||
|
||||
let event = PinnedEventsEvent {
|
||||
let event = StateEvent {
|
||||
content: content.clone(),
|
||||
event_id: EventId::new("example.com").unwrap(),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1_432_804_485_886u64),
|
||||
prev_content: None,
|
||||
room_id: Some(RoomId::new("example.com").unwrap()),
|
||||
room_id: RoomId::new("example.com").unwrap(),
|
||||
sender: UserId::new("example.com").unwrap(),
|
||||
state_key: "".to_string(),
|
||||
unsigned: UnsignedData::default(),
|
||||
};
|
||||
|
||||
let serialized_event = to_string(&event).unwrap();
|
||||
let parsed_event: PinnedEventsEvent =
|
||||
serde_json::from_str::<EventJson<_>>(&serialized_event)
|
||||
.unwrap()
|
||||
.deserialize()
|
||||
.unwrap();
|
||||
let parsed_event = serde_json::from_str::<EventJson<StateEvent<PinnedEventsEventContent>>>(
|
||||
&serialized_event,
|
||||
)
|
||||
.unwrap()
|
||||
.deserialize()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(parsed_event.event_id, event.event_id);
|
||||
assert_eq!(parsed_event.room_id, event.room_id);
|
||||
|
@ -138,16 +138,14 @@ mod tests {
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde_json::{json, to_value as to_json_value};
|
||||
|
||||
use super::{
|
||||
default_power_level, NotificationPowerLevels, PowerLevelsEvent, PowerLevelsEventContent,
|
||||
};
|
||||
use crate::{EventType, UnsignedData};
|
||||
use super::{default_power_level, NotificationPowerLevels, PowerLevelsEventContent};
|
||||
use crate::{EventType, StateEvent, UnsignedData};
|
||||
|
||||
#[test]
|
||||
fn serialization_with_optional_fields_as_none() {
|
||||
let default = default_power_level();
|
||||
|
||||
let power_levels_event = PowerLevelsEvent {
|
||||
let power_levels_event = StateEvent {
|
||||
content: PowerLevelsEventContent {
|
||||
ban: default,
|
||||
events: BTreeMap::new(),
|
||||
@ -163,7 +161,7 @@ mod tests {
|
||||
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1),
|
||||
prev_content: None,
|
||||
room_id: None,
|
||||
room_id: RoomId::try_from("!n8f893n9:example.com").unwrap(),
|
||||
unsigned: UnsignedData::default(),
|
||||
sender: UserId::try_from("@carl:example.com").unwrap(),
|
||||
state_key: "".to_string(),
|
||||
@ -174,6 +172,7 @@ mod tests {
|
||||
"content": {},
|
||||
"event_id": "$h29iv0s8:example.com",
|
||||
"origin_server_ts": 1,
|
||||
"room_id": "!n8f893n9:example.com",
|
||||
"sender": "@carl:example.com",
|
||||
"state_key": "",
|
||||
"type": "m.room.power_levels"
|
||||
@ -185,7 +184,7 @@ mod tests {
|
||||
#[test]
|
||||
fn serialization_with_all_fields() {
|
||||
let user = UserId::try_from("@carl:example.com").unwrap();
|
||||
let power_levels_event = PowerLevelsEvent {
|
||||
let power_levels_event = StateEvent {
|
||||
content: PowerLevelsEventContent {
|
||||
ban: Int::from(23),
|
||||
events: btreemap! {
|
||||
@ -225,7 +224,7 @@ mod tests {
|
||||
room: Int::from(42),
|
||||
},
|
||||
}),
|
||||
room_id: Some(RoomId::try_from("!n8f893n9:example.com").unwrap()),
|
||||
room_id: RoomId::try_from("!n8f893n9:example.com").unwrap(),
|
||||
unsigned: UnsignedData {
|
||||
age: Some(Int::from(100)),
|
||||
..UnsignedData::default()
|
||||
|
@ -43,22 +43,26 @@ ruma_event! {
|
||||
mod tests {
|
||||
use serde_json::{from_value as from_json_value, json};
|
||||
|
||||
use super::ServerAclEvent;
|
||||
use crate::EventJson;
|
||||
use super::ServerAclEventContent;
|
||||
use crate::{EventJson, StateEvent};
|
||||
|
||||
#[test]
|
||||
fn default_values() {
|
||||
let json_data = json!({
|
||||
"content": {},
|
||||
"event_id": "$h29iv0s8:example.com","origin_server_ts":1,
|
||||
"event_id": "$h29iv0s8:example.com",
|
||||
"origin_server_ts": 1,
|
||||
"room_id": "!n8f893n9:example.com",
|
||||
"sender": "@carl:example.com",
|
||||
"state_key": "",
|
||||
"type": "m.room.server_acl"
|
||||
});
|
||||
let server_acl_event: ServerAclEvent = from_json_value::<EventJson<_>>(json_data)
|
||||
.unwrap()
|
||||
.deserialize()
|
||||
.unwrap();
|
||||
|
||||
let server_acl_event =
|
||||
from_json_value::<EventJson<StateEvent<ServerAclEventContent>>>(json_data)
|
||||
.unwrap()
|
||||
.deserialize()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(server_acl_event.content.allow_ip_literals, true);
|
||||
assert!(server_acl_event.content.allow.is_empty());
|
||||
|
Loading…
x
Reference in New Issue
Block a user