From 22c15277a7b58acdb6db6b725048986efd5e5ae4 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 20 Jun 2019 17:37:55 -0700 Subject: [PATCH] Convert m.call.*, m.room.message.feedback, and m.room.redaction to the new API. --- src/call/answer.rs | 32 +++++++++++++-------------- src/call/candidates.rs | 27 ++++++++++++----------- src/call/hangup.rs | 27 ++++++++++++----------- src/call/invite.rs | 42 ++++++++++++++++++------------------ src/ignored_user_list.rs | 6 +++--- src/lib.rs | 2 +- src/room.rs | 2 +- src/room/message/feedback.rs | 27 ++++++++++++----------- src/room/redaction.rs | 28 ++++++++++++------------ 9 files changed, 98 insertions(+), 95 deletions(-) diff --git a/src/call/answer.rs b/src/call/answer.rs index 3153b128..c70c945a 100644 --- a/src/call/answer.rs +++ b/src/call/answer.rs @@ -1,24 +1,24 @@ //! Types for the *m.call.answer* event. use js_int::UInt; -use serde::{Deserialize, Serialize}; +use ruma_events_macros::ruma_event; use super::SessionDescription; -room_event! { +ruma_event! { /// This event is sent by the callee when they wish to answer the call. - pub struct AnswerEvent(AnswerEventContent) {} -} - -/// The payload of an `AnswerEvent`. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] -pub struct AnswerEventContent { - /// The VoIP session description object. The session description type must be *answer*. - pub answer: SessionDescription, - - /// The ID of the call this event relates to. - pub call_id: String, - - /// The version of the VoIP specification this messages adheres to. - pub version: UInt, + AnswerEvent { + kind: RoomEvent, + event_type: CallAnswer, + content: { + /// The VoIP session description object. The session description type must be *answer*. + pub answer: SessionDescription, + + /// The ID of the call this event relates to. + pub call_id: String, + + /// The version of the VoIP specification this messages adheres to. + pub version: UInt, + }, + } } diff --git a/src/call/candidates.rs b/src/call/candidates.rs index 5dc084f7..70546395 100644 --- a/src/call/candidates.rs +++ b/src/call/candidates.rs @@ -1,26 +1,27 @@ //! Types for the *m.call.candidates* event. use js_int::UInt; +use ruma_events_macros::ruma_event; use serde::{Deserialize, Serialize}; -room_event! { +ruma_event! { /// This event is sent by callers after sending an invite and by the callee after answering. /// Its purpose is to give the other party additional ICE candidates to try using to /// communicate. - pub struct CandidatesEvent(CandidatesEventContent) {} -} + CandidatesEvent { + kind: RoomEvent, + event_type: CallCandidates, + content: { + /// The ID of the call this event relates to. + pub call_id: String, -/// The payload of a `CandidatesEvent`. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] -pub struct CandidatesEventContent { - /// The ID of the call this event relates to. - pub call_id: String, + /// A list of candidates. + pub candidates: Vec, - /// A list of candidates. - pub candidates: Vec, - - /// The version of the VoIP specification this messages adheres to. - pub version: UInt, + /// The version of the VoIP specification this messages adheres to. + pub version: UInt, + }, + } } /// An ICE (Interactive Connectivity Establishment) candidate. diff --git a/src/call/hangup.rs b/src/call/hangup.rs index 0cad2923..78087656 100644 --- a/src/call/hangup.rs +++ b/src/call/hangup.rs @@ -1,25 +1,26 @@ //! Types for the *m.call.hangup* event. use js_int::UInt; +use ruma_events_macros::ruma_event; use serde::{Deserialize, Serialize}; -room_event! { +ruma_event! { /// Sent by either party to signal their termination of the call. This can be sent either once /// the call has has been established or before to abort the call. - pub struct HangupEvent(HangupEventContent) {} -} + HangupEvent { + kind: RoomEvent, + event_type: CallHangup, + content: { + /// The ID of the call this event relates to. + pub call_id: String, -/// The payload of a `HangupEvent`. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] -pub struct HangupEventContent { - /// The ID of the call this event relates to. - pub call_id: String, + /// The version of the VoIP specification this messages adheres to. + pub version: UInt, - /// The version of the VoIP specification this messages adheres to. - pub version: UInt, - - /// Optional error reason for the hangup. - pub reason: Option, + /// Optional error reason for the hangup. + pub reason: Option, + }, + } } /// A reason for a hangup. diff --git a/src/call/invite.rs b/src/call/invite.rs index ffdf8c15..98b93fd9 100644 --- a/src/call/invite.rs +++ b/src/call/invite.rs @@ -1,29 +1,29 @@ //! Types for the *m.call.invite* event. use js_int::UInt; -use serde::{Deserialize, Serialize}; +use ruma_events_macros::ruma_event; use super::SessionDescription; -room_event! { +ruma_event! { /// This event is sent by the caller when they wish to establish a call. - pub struct InviteEvent(InviteEventContent) {} -} - -/// The payload of an `InviteEvent`. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] -pub struct InviteEventContent { - /// A unique identifer for the call. - pub call_id: String, - - /// The time in milliseconds that the invite is valid for. Once the invite age exceeds this - /// value, clients should discard it. They should also no longer show the call as awaiting an - /// answer in the UI. - pub lifetime: UInt, - - /// The session description object. The session description type must be *offer*. - pub offer: SessionDescription, - - /// The version of the VoIP specification this messages adheres to. - pub version: UInt, + InviteEvent { + kind: RoomEvent, + event_type: CallInvite, + content: { + /// A unique identifer for the call. + pub call_id: String, + + /// The time in milliseconds that the invite is valid for. Once the invite age exceeds this + /// value, clients should discard it. They should also no longer show the call as awaiting an + /// answer in the UI. + pub lifetime: UInt, + + /// The session description object. The session description type must be *offer*. + pub offer: SessionDescription, + + /// The version of the VoIP specification this messages adheres to. + pub version: UInt, + }, + } } diff --git a/src/ignored_user_list.rs b/src/ignored_user_list.rs index 23f53025..4bad50d7 100644 --- a/src/ignored_user_list.rs +++ b/src/ignored_user_list.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use ruma_identifiers::UserId; -use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer}; +use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer}; use crate::{Empty, Event, EventType}; @@ -41,8 +41,8 @@ impl Serialize for IgnoredUserListEvent { { let mut state = serializer.serialize_struct("IgnoredUserListEvent", 2)?; - state.serialize_field("content", &self.content); - state.serialize_field("type", &self.event_type()); + state.serialize_field("content", &self.content)?; + state.serialize_field("type", &self.event_type())?; state.end() } diff --git a/src/lib.rs b/src/lib.rs index cedcf5ae..580c25bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -120,7 +120,7 @@ pub use custom_state::CustomStateEvent; #[macro_use] mod macros; -// pub mod call; +pub mod call; // /// Enums for heterogeneous collections of events. // pub mod collections { // pub mod all; diff --git a/src/room.rs b/src/room.rs index bee104f5..30f67d25 100644 --- a/src/room.rs +++ b/src/room.rs @@ -21,7 +21,7 @@ use serde::{Deserialize, Serialize}; // pub mod name; // pub mod pinned_events; // pub mod power_levels; -// pub mod redaction; +pub mod redaction; // pub mod server_acl; // pub mod third_party_invite; // pub mod tombstone; diff --git a/src/room/message/feedback.rs b/src/room/message/feedback.rs index 9849cd86..03541b84 100644 --- a/src/room/message/feedback.rs +++ b/src/room/message/feedback.rs @@ -1,26 +1,27 @@ //! Types for the *m.room.message.feedback* event. use js_int::UInt; +use ruma_events_macros::ruma_event; use ruma_identifiers::EventId; use serde::{Deserialize, Serialize}; -room_event! { +ruma_event! { /// An acknowledgement of a message. /// /// N.B.: Usage of this event is discouraged in favor of the receipts module. Most clients will - /// not recognise this event. - pub struct FeedbackEvent(FeedbackEventContent) {} -} + /// not recognize this event. + FeedbackEvent { + kind: RoomEvent, + event_type: RoomMessageFeedback, + content: { + /// The event that this feedback is related to. + pub target_event_id: EventId, -/// The payload of an *m.room.message.feedback* event. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] -pub struct FeedbackEventContent { - /// The event that this feedback is related to. - pub target_event_id: EventId, - - /// The type of feedback. - #[serde(rename = "type")] - pub feedback_type: FeedbackType, + /// The type of feedback. + #[serde(rename = "type")] + pub feedback_type: FeedbackType, + }, + } } /// A type of feedback. diff --git a/src/room/redaction.rs b/src/room/redaction.rs index 31306bf2..b69268cc 100644 --- a/src/room/redaction.rs +++ b/src/room/redaction.rs @@ -1,21 +1,21 @@ //! Types for the *m.room.redaction* event. -use js_int::UInt; +use ruma_events_macros::ruma_event; use ruma_identifiers::EventId; -use serde::{Deserialize, Serialize}; -room_event! { +ruma_event! { /// A redaction of an event. - pub struct RedactionEvent(RedactionEventContent) { - /// The ID of the event that was redacted. - pub redacts: EventId + RedactionEvent { + kind: RoomEvent, + event_type: RoomRedaction, + fields: { + /// The ID of the event that was redacted. + pub redacts: EventId, + }, + content: { + /// The reason for the redaction, if any. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option, + } } } - -/// The payload of a `RedactionEvent`. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] -pub struct RedactionEventContent { - /// The reason for the redaction, if any. - #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option, -}