events: Make some more types non-exhaustive

This commit is contained in:
Jonas Platte 2020-09-22 23:11:53 +02:00
parent 7b8754b2c9
commit 7c535badf6
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
4 changed files with 24 additions and 0 deletions

View File

@ -12,6 +12,7 @@ pub mod invite;
/// A VoIP session description.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct SessionDescription {
/// The type of session description.
#[serde(rename = "type")]
@ -21,6 +22,13 @@ pub struct SessionDescription {
pub sdp: String,
}
impl SessionDescription {
/// Creates a new `SessionDescription` with the given session type and SDP text.
pub fn new(session_type: SessionDescriptionType, sdp: String) -> Self {
Self { session_type, sdp }
}
}
/// The type of VoIP session description.
#[derive(Clone, Copy, Debug, PartialEq, Display, EnumString, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]

View File

@ -12,6 +12,7 @@ pub type AnswerEvent = MessageEvent<AnswerEventContent>;
/// The payload for `AnswerEvent`.
#[derive(Clone, Debug, Deserialize, Serialize, MessageEventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.call.answer")]
pub struct AnswerEventContent {
/// The VoIP session description object. The session description type must be *answer*.
@ -23,3 +24,10 @@ pub struct AnswerEventContent {
/// The version of the VoIP specification this messages adheres to.
pub version: UInt,
}
impl AnswerEventContent {
/// Creates an `AnswerEventContent` with the gieven answer, call ID and VoIP version.
pub fn new(answer: SessionDescription, call_id: String, version: UInt) -> Self {
Self { answer, call_id, version }
}
}

View File

@ -46,9 +46,11 @@ fn deserialize_message_event() {
answer: SessionDescription {
session_type: SessionDescriptionType::Answer,
sdp,
..
},
call_id,
version,
..
},
event_id,
origin_server_ts,

View File

@ -89,9 +89,11 @@ fn deserialize_message_call_answer_content() {
answer: SessionDescription {
session_type: SessionDescriptionType::Answer,
sdp,
..
},
call_id,
version,
..
}) if sdp == "Hello" && call_id == "foofoo" && version == UInt::new(1).unwrap()
);
}
@ -124,9 +126,11 @@ fn deserialize_message_call_answer() {
answer: SessionDescription {
session_type: SessionDescriptionType::Answer,
sdp,
..
},
call_id,
version,
..
}),
event_id,
origin_server_ts,
@ -255,9 +259,11 @@ fn deserialize_message_then_convert_to_full() {
answer: SessionDescription {
session_type: SessionDescriptionType::Answer,
sdp,
..
},
call_id,
version,
..
}),
event_id,
origin_server_ts,