events: Make TypingEventContent non-exhaustive and derive Default for it

This commit is contained in:
Jonas Platte 2021-04-18 14:32:54 +02:00
parent 624a48a724
commit 7f01a6d73b
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
2 changed files with 13 additions and 7 deletions

View File

@ -10,9 +10,17 @@ use crate::EphemeralRoomEvent;
pub type TypingEvent = EphemeralRoomEvent<TypingEventContent>; pub type TypingEvent = EphemeralRoomEvent<TypingEventContent>;
/// The payload for `TypingEvent`. /// The payload for `TypingEvent`.
#[derive(Clone, Debug, Deserialize, Serialize, EphemeralRoomEventContent)] #[derive(Clone, Debug, Default, Deserialize, Serialize, EphemeralRoomEventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.typing")] #[ruma_event(type = "m.typing")]
pub struct TypingEventContent { pub struct TypingEventContent {
/// The list of user IDs typing in this room, if any. /// The list of user IDs typing in this room, if any.
pub user_ids: Vec<UserId>, pub user_ids: Vec<UserId>,
} }
impl TypingEventContent {
/// Creates a new `TypingEventContent` with the given user IDs.
pub fn new(user_ids: Vec<UserId>) -> Self {
Self { user_ids }
}
}

View File

@ -15,9 +15,9 @@ use ruma_events::{
#[test] #[test]
fn ephemeral_serialize_typing() { fn ephemeral_serialize_typing() {
let aliases_event = EphemeralRoomEvent { let aliases_event = EphemeralRoomEvent {
content: AnyEphemeralRoomEventContent::Typing(TypingEventContent { content: AnyEphemeralRoomEventContent::Typing(TypingEventContent::new(vec![user_id!(
user_ids: vec![user_id!("@carl:example.com")], "@carl:example.com"
}), )])),
room_id: room_id!("!roomid:room.com"), room_id: room_id!("!roomid:room.com"),
}; };
@ -49,9 +49,7 @@ fn deserialize_ephemeral_typing() {
.deserialize() .deserialize()
.unwrap(), .unwrap(),
EphemeralRoomEvent { EphemeralRoomEvent {
content: AnyEphemeralRoomEventContent::Typing(TypingEventContent { content: AnyEphemeralRoomEventContent::Typing(TypingEventContent { user_ids, .. }),
user_ids,
}),
room_id, room_id,
} if user_ids[0] == user_id!("@carl:example.com") } if user_ids[0] == user_id!("@carl:example.com")
&& room_id == room_id!("!roomid:room.com") && room_id == room_id!("!roomid:room.com")