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.
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,
},
}
}

View File

@ -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<Candidate>,
/// A list of candidates.
pub candidates: Vec<Candidate>,
/// 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.

View File

@ -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<Reason>,
/// Optional error reason for the hangup.
pub reason: Option<Reason>,
},
}
}
/// A reason for a hangup.

View File

@ -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,
},
}
}

View File

@ -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()
}

View File

@ -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;

View File

@ -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;

View File

@ -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.

View File

@ -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<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>,
}