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,18 +1,16 @@
//! 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)]
pub struct AnswerEventContent {
/// The VoIP session description object. The session description type must be *answer*. /// The VoIP session description object. The session description type must be *answer*.
pub answer: SessionDescription, pub answer: SessionDescription,
@ -21,4 +19,6 @@ pub struct AnswerEventContent {
/// The version of the VoIP specification this messages adheres to. /// The version of the VoIP specification this messages adheres to.
pub version: UInt, pub version: UInt,
},
}
} }

View File

@ -1,18 +1,17 @@
//! 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,
/// The payload of a `CandidatesEvent`. content: {
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct CandidatesEventContent {
/// The ID of the call this event relates to. /// The ID of the call this event relates to.
pub call_id: String, pub call_id: String,
@ -21,6 +20,8 @@ pub struct CandidatesEventContent {
/// The version of the VoIP specification this messages adheres to. /// The version of the VoIP specification this messages adheres to.
pub version: UInt, pub version: UInt,
},
}
} }
/// An ICE (Interactive Connectivity Establishment) candidate. /// An ICE (Interactive Connectivity Establishment) candidate.

View File

@ -1,17 +1,16 @@
//! 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,
/// The payload of a `HangupEvent`. content: {
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct HangupEventContent {
/// The ID of the call this event relates to. /// The ID of the call this event relates to.
pub call_id: String, pub call_id: String,
@ -20,6 +19,8 @@ pub struct HangupEventContent {
/// Optional error reason for the hangup. /// Optional error reason for the hangup.
pub reason: Option<Reason>, pub reason: Option<Reason>,
},
}
} }
/// A reason for a hangup. /// A reason for a hangup.

View File

@ -1,18 +1,16 @@
//! 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)]
pub struct InviteEventContent {
/// A unique identifer for the call. /// A unique identifer for the call.
pub call_id: String, pub call_id: String,
@ -26,4 +24,6 @@ pub struct InviteEventContent {
/// The version of the VoIP specification this messages adheres to. /// The version of the VoIP specification this messages adheres to.
pub version: UInt, 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,
/// The payload of an *m.room.message.feedback* event. content: {
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct FeedbackEventContent {
/// The event that this feedback is related to. /// The event that this feedback is related to.
pub target_event_id: EventId, pub target_event_id: EventId,
/// The type of feedback. /// The type of feedback.
#[serde(rename = "type")] #[serde(rename = "type")]
pub feedback_type: FeedbackType, 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 {
kind: RoomEvent,
event_type: RoomRedaction,
fields: {
/// The ID of the event that was redacted. /// The ID of the event that was redacted.
pub redacts: EventId pub redacts: EventId,
} },
} content: {
/// The payload of a `RedactionEvent`.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct RedactionEventContent {
/// The reason for the redaction, if any. /// The reason for the redaction, if any.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub reason: Option<String>, pub reason: Option<String>,
}
}
} }