Convert m.call.*, m.room.message.feedback, and m.room.redaction to the new

API.
This commit is contained in:
Jimmy Cuadra 2019-06-20 17:37:55 -07:00
parent 20d2482108
commit 22c15277a7
9 changed files with 98 additions and 95 deletions

View File

@ -1,24 +1,24 @@
//! Types for the *m.call.answer* event. //! Types for the *m.call.answer* event.
use js_int::UInt; use js_int::UInt;
use serde::{Deserialize, Serialize}; use ruma_events_macros::ruma_event;
use super::SessionDescription; use super::SessionDescription;
room_event! { ruma_event! {
/// This event is sent by the callee when they wish to answer the call. /// This event is sent by the callee when they wish to answer the call.
pub struct AnswerEvent(AnswerEventContent) {} AnswerEvent {
} kind: RoomEvent,
event_type: CallAnswer,
/// The payload of an `AnswerEvent`. content: {
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] /// The VoIP session description object. The session description type must be *answer*.
pub struct AnswerEventContent { pub answer: SessionDescription,
/// 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 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, }
} }

View File

@ -1,26 +1,27 @@
//! Types for the *m.call.candidates* event. //! Types for the *m.call.candidates* event.
use js_int::UInt; use js_int::UInt;
use ruma_events_macros::ruma_event;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
room_event! { ruma_event! {
/// This event is sent by callers after sending an invite and by the callee after answering. /// 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 /// Its purpose is to give the other party additional ICE candidates to try using to
/// communicate. /// 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`. /// A list of candidates.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] pub candidates: Vec<Candidate>,
pub struct CandidatesEventContent {
/// The ID of the call this event relates to.
pub call_id: String,
/// A list of candidates. /// The version of the VoIP specification this messages adheres to.
pub candidates: Vec<Candidate>, pub version: UInt,
},
/// The version of the VoIP specification this messages adheres to. }
pub version: UInt,
} }
/// An ICE (Interactive Connectivity Establishment) candidate. /// An ICE (Interactive Connectivity Establishment) candidate.

View File

@ -1,25 +1,26 @@
//! Types for the *m.call.hangup* event. //! Types for the *m.call.hangup* event.
use js_int::UInt; use js_int::UInt;
use ruma_events_macros::ruma_event;
use serde::{Deserialize, Serialize}; 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 /// 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. /// 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`. /// The version of the VoIP specification this messages adheres to.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] pub version: UInt,
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. /// Optional error reason for the hangup.
pub version: UInt, pub reason: Option<Reason>,
},
/// Optional error reason for the hangup. }
pub reason: Option<Reason>,
} }
/// A reason for a hangup. /// A reason for a hangup.

View File

@ -1,29 +1,29 @@
//! Types for the *m.call.invite* event. //! Types for the *m.call.invite* event.
use js_int::UInt; use js_int::UInt;
use serde::{Deserialize, Serialize}; use ruma_events_macros::ruma_event;
use super::SessionDescription; use super::SessionDescription;
room_event! { ruma_event! {
/// This event is sent by the caller when they wish to establish a call. /// This event is sent by the caller when they wish to establish a call.
pub struct InviteEvent(InviteEventContent) {} InviteEvent {
} kind: RoomEvent,
event_type: CallInvite,
/// The payload of an `InviteEvent`. content: {
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] /// A unique identifer for the call.
pub struct InviteEventContent { pub call_id: String,
/// 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
/// The time in milliseconds that the invite is valid for. Once the invite age exceeds this /// answer in the UI.
/// value, clients should discard it. They should also no longer show the call as awaiting an pub lifetime: UInt,
/// answer in the UI.
pub lifetime: UInt, /// The session description object. The session description type must be *offer*.
pub offer: SessionDescription,
/// 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,
/// The version of the VoIP specification this messages adheres to. },
pub version: UInt, }
} }

View File

@ -3,7 +3,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use ruma_identifiers::UserId; use ruma_identifiers::UserId;
use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer}; use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
use crate::{Empty, Event, EventType}; use crate::{Empty, Event, EventType};
@ -41,8 +41,8 @@ impl Serialize for IgnoredUserListEvent {
{ {
let mut state = serializer.serialize_struct("IgnoredUserListEvent", 2)?; let mut state = serializer.serialize_struct("IgnoredUserListEvent", 2)?;
state.serialize_field("content", &self.content); state.serialize_field("content", &self.content)?;
state.serialize_field("type", &self.event_type()); state.serialize_field("type", &self.event_type())?;
state.end() state.end()
} }

View File

@ -120,7 +120,7 @@ pub use custom_state::CustomStateEvent;
#[macro_use] #[macro_use]
mod macros; mod macros;
// pub mod call; pub mod call;
// /// Enums for heterogeneous collections of events. // /// Enums for heterogeneous collections of events.
// pub mod collections { // pub mod collections {
// pub mod all; // pub mod all;

View File

@ -21,7 +21,7 @@ use serde::{Deserialize, Serialize};
// pub mod name; // pub mod name;
// pub mod pinned_events; // pub mod pinned_events;
// pub mod power_levels; // pub mod power_levels;
// pub mod redaction; pub mod redaction;
// pub mod server_acl; // pub mod server_acl;
// pub mod third_party_invite; // pub mod third_party_invite;
// pub mod tombstone; // pub mod tombstone;

View File

@ -1,26 +1,27 @@
//! Types for the *m.room.message.feedback* event. //! Types for the *m.room.message.feedback* event.
use js_int::UInt; use js_int::UInt;
use ruma_events_macros::ruma_event;
use ruma_identifiers::EventId; use ruma_identifiers::EventId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
room_event! { ruma_event! {
/// An acknowledgement of a message. /// An acknowledgement of a message.
/// ///
/// N.B.: Usage of this event is discouraged in favor of the receipts module. Most clients will /// N.B.: Usage of this event is discouraged in favor of the receipts module. Most clients will
/// not recognise this event. /// not recognize this event.
pub struct FeedbackEvent(FeedbackEventContent) {} 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. /// The type of feedback.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] #[serde(rename = "type")]
pub struct FeedbackEventContent { pub feedback_type: FeedbackType,
/// The event that this feedback is related to. },
pub target_event_id: EventId, }
/// The type of feedback.
#[serde(rename = "type")]
pub feedback_type: FeedbackType,
} }
/// A type of feedback. /// A type of feedback.

View File

@ -1,21 +1,21 @@
//! Types for the *m.room.redaction* event. //! Types for the *m.room.redaction* event.
use js_int::UInt; use ruma_events_macros::ruma_event;
use ruma_identifiers::EventId; use ruma_identifiers::EventId;
use serde::{Deserialize, Serialize};
room_event! { ruma_event! {
/// A redaction of an event. /// A redaction of an event.
pub struct RedactionEvent(RedactionEventContent) { RedactionEvent {
/// The ID of the event that was redacted. kind: RoomEvent,
pub redacts: EventId 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<String>,
}
} }
} }
/// 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<String>,
}