Derive Debug and {De,}Serialize for all types.
This commit is contained in:
parent
d525766c99
commit
09ecdfa470
18
Cargo.toml
18
Cargo.toml
@ -1,11 +1,15 @@
|
||||
[package]
|
||||
name = "ruma-events"
|
||||
version = "0.1.0"
|
||||
authors = ["Jimmy Cuadra <jimmy@jimmycuadra.com>"]
|
||||
description = "Serializable types for the events in the Matrix specification."
|
||||
license = "MIT"
|
||||
readme = "README.md"
|
||||
keywords = ["matrix", "matrix.org", "chat", "messaging", "ruma"]
|
||||
repository = "https://github.com/ruma/ruma-events"
|
||||
homepage = "https://github.com/ruma/ruma-events"
|
||||
documentation = "http://ruma.github.io/ruma-events/ruma-events"
|
||||
homepage = "https://github.com/ruma/ruma-events"
|
||||
keywords = ["matrix", "matrix.org", "chat", "messaging", "ruma"]
|
||||
license = "MIT"
|
||||
name = "ruma-events"
|
||||
readme = "README.md"
|
||||
repository = "https://github.com/ruma/ruma-events"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
serde = "0.7.7"
|
||||
serde_macros = "0.7.7"
|
||||
|
@ -4,6 +4,7 @@ use core::EventType;
|
||||
use super::SessionDescription;
|
||||
|
||||
/// This event is sent by the callee when they wish to answer the call.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct AnswerEvent {
|
||||
pub content: AnswerEventContent,
|
||||
pub event_id: String,
|
||||
@ -13,6 +14,7 @@ pub struct AnswerEvent {
|
||||
}
|
||||
|
||||
/// The payload of an `AnswerEvent`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct AnswerEventContent {
|
||||
/// The VoIP session description.
|
||||
pub answer: SessionDescription,
|
||||
|
@ -4,6 +4,7 @@ use core::EventType;
|
||||
|
||||
/// 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.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct CandidatesEvent {
|
||||
pub content: CandidatesEventContent,
|
||||
pub event_id: String,
|
||||
@ -13,6 +14,7 @@ pub struct CandidatesEvent {
|
||||
}
|
||||
|
||||
/// The payload of a `CandidatesEvent`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct CandidatesEventContent {
|
||||
/// The ID of the call this event relates to.
|
||||
pub call_id: String,
|
||||
@ -23,6 +25,7 @@ pub struct CandidatesEventContent {
|
||||
}
|
||||
|
||||
/// An ICE (Interactive Connectivity Establishment) candidate.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct Candidate {
|
||||
/// The SDP "a" line of the candidate.
|
||||
pub candidate: String,
|
||||
|
@ -4,6 +4,7 @@ use core::EventType;
|
||||
|
||||
/// 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.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct HangupEvent {
|
||||
pub content: HangupEventContent,
|
||||
pub event_id: String,
|
||||
@ -13,6 +14,7 @@ pub struct HangupEvent {
|
||||
}
|
||||
|
||||
/// The payload of a `HangupEvent`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct HangupEventContent {
|
||||
/// The ID of the call this event relates to.
|
||||
pub call_id: String,
|
||||
|
@ -4,6 +4,7 @@ use core::EventType;
|
||||
use super::SessionDescription;
|
||||
|
||||
/// This event is sent by the caller when they wish to establish a call.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct InviteEvent {
|
||||
pub content: InviteEventContent,
|
||||
pub event_id: String,
|
||||
@ -13,6 +14,7 @@ pub struct InviteEvent {
|
||||
}
|
||||
|
||||
/// The payload of an `InviteEvent`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct InviteEventContent {
|
||||
/// A unique identifer for the call.
|
||||
pub call_id: String,
|
||||
|
@ -8,6 +8,7 @@ pub mod hangup;
|
||||
pub mod invite;
|
||||
|
||||
/// A VoIP session description.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct SessionDescription {
|
||||
/// The type of session description.
|
||||
pub session_type: SessionDescriptionType,
|
||||
@ -16,6 +17,7 @@ pub struct SessionDescription {
|
||||
}
|
||||
|
||||
/// The type of VoIP session description.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum SessionDescriptionType {
|
||||
/// An answer.
|
||||
Answer,
|
||||
|
@ -6,6 +6,7 @@ use room::join_rules::JoinRulesEventContent;
|
||||
use room::name::NameEventContent;
|
||||
|
||||
/// The type of an event.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum EventType {
|
||||
CallAnswer,
|
||||
CallCandidates,
|
||||
@ -33,6 +34,7 @@ pub enum EventType {
|
||||
}
|
||||
|
||||
/// A stripped-down version of a state event that is included along with some other events.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum StrippedState {
|
||||
RoomAvatar(StrippedRoomAvatar),
|
||||
RoomCanonicalAlias(StrippedRoomCanonicalAlias),
|
||||
@ -41,6 +43,7 @@ pub enum StrippedState {
|
||||
}
|
||||
|
||||
/// The general form of a `StrippedState`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct StrippedStateContent<T> {
|
||||
pub content: T,
|
||||
pub event_type: EventType,
|
||||
|
@ -1,6 +1,9 @@
|
||||
//! Crate ruma_events contains serializable types for the events in the [Matrix](https://matrix.org)
|
||||
//! specification that can be shared by client and server code.
|
||||
|
||||
#![feature(custom_derive, plugin)]
|
||||
#![plugin(serde_macros)]
|
||||
|
||||
pub mod call;
|
||||
pub mod core;
|
||||
pub mod presence;
|
||||
|
@ -3,6 +3,7 @@
|
||||
use core::EventType;
|
||||
|
||||
/// Informs the client of a user's presence state change.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct PresenceEvent {
|
||||
pub content: PresenceEventContent,
|
||||
pub event_id: String,
|
||||
@ -10,6 +11,7 @@ pub struct PresenceEvent {
|
||||
}
|
||||
|
||||
/// The payload of a `PresenceEvent`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct PresenceEventContent {
|
||||
/// The current avatar URL for this user.
|
||||
pub avatar_url: Option<String>,
|
||||
@ -22,6 +24,7 @@ pub struct PresenceEventContent {
|
||||
}
|
||||
|
||||
/// A description of a user's connectivity and availability for chat.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum PresenceState {
|
||||
/// Connected to the service and available for chat.
|
||||
FreeForChat,
|
||||
|
@ -5,6 +5,7 @@ use std::collections::HashMap;
|
||||
use core::EventType;
|
||||
|
||||
/// Informs the client of new receipts.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct ReceiptEvent {
|
||||
pub content: ReceiptEventContent,
|
||||
pub event_type: EventType,
|
||||
@ -18,6 +19,7 @@ pub struct ReceiptEvent {
|
||||
pub type ReceiptEventContent = HashMap<String, Receipts>;
|
||||
|
||||
/// A collection of receipts.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct Receipts {
|
||||
/// A collection of users who have sent *m.read* receipts for this event.
|
||||
pub m_read: UserReceipts,
|
||||
@ -29,6 +31,7 @@ pub struct Receipts {
|
||||
pub type UserReceipts = HashMap<String, Receipt>;
|
||||
|
||||
/// An acknowledgement of an event.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct Receipt {
|
||||
/// The timestamp the receipt was sent at.
|
||||
pub ts: u64,
|
||||
|
@ -3,6 +3,7 @@
|
||||
use core::EventType;
|
||||
|
||||
/// Informs the room about what room aliases it has been given.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct AliasesEvent {
|
||||
pub content: AliasesEventContent,
|
||||
pub event_id: String,
|
||||
@ -15,6 +16,7 @@ pub struct AliasesEvent {
|
||||
}
|
||||
|
||||
/// The payload of an `AliasesEvent`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct AliasesEventContent {
|
||||
/// A list of room aliases.
|
||||
pub aliases: Vec<String>,
|
||||
|
@ -6,6 +6,7 @@ use super::ImageInfo;
|
||||
/// A picture that is associated with the room.
|
||||
///
|
||||
/// This can be displayed alongside the room information.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct AvatarEvent {
|
||||
pub content: AvatarEventContent,
|
||||
pub event_id: String,
|
||||
@ -17,6 +18,7 @@ pub struct AvatarEvent {
|
||||
}
|
||||
|
||||
/// The payload of an `AvatarEvent`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct AvatarEventContent {
|
||||
pub info: ImageInfo,
|
||||
pub thumbnail_info: ImageInfo,
|
||||
|
@ -3,6 +3,7 @@
|
||||
use core::EventType;
|
||||
|
||||
/// Informs the room as to which alias is the canonical one.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct CanonicalAliasEvent {
|
||||
pub content: CanonicalAliasEventContent,
|
||||
pub event_id: String,
|
||||
@ -14,6 +15,7 @@ pub struct CanonicalAliasEvent {
|
||||
}
|
||||
|
||||
/// The payload of a `CanonicalAliasEvent`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct CanonicalAliasEventContent {
|
||||
/// The canonical alias.
|
||||
pub alias: String,
|
||||
|
@ -4,6 +4,7 @@ use core::EventType;
|
||||
|
||||
/// This is the first event in a room and cannot be changed. It acts as the root of all other
|
||||
/// events.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct CreateEvent {
|
||||
pub content: CreateEventContent,
|
||||
pub event_id: String,
|
||||
@ -15,6 +16,7 @@ pub struct CreateEvent {
|
||||
}
|
||||
|
||||
/// The payload of a `CreateEvent`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct CreateEventContent {
|
||||
/// The `user_id` of the room creator. This is set by the homeserver.
|
||||
pub creator: String,
|
||||
|
@ -6,6 +6,7 @@ use core::EventType;
|
||||
///
|
||||
/// This event controls whether guest users are allowed to join rooms. If this event is absent,
|
||||
/// servers should act as if it is present and has the value `GuestAccess::Forbidden`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct GuestAccessEvent {
|
||||
pub content: GuestAccessEventContent,
|
||||
pub event_id: String,
|
||||
@ -17,11 +18,13 @@ pub struct GuestAccessEvent {
|
||||
}
|
||||
|
||||
/// The payload of a `GuestAccessEvent`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct GuestAccessEventContent {
|
||||
pub guest_access: GuestAccess,
|
||||
}
|
||||
|
||||
/// A policy for guest user access to a room.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum GuestAccess {
|
||||
/// Guests are allowed to join the room.
|
||||
CanJoin,
|
||||
|
@ -4,6 +4,7 @@ use core::EventType;
|
||||
|
||||
/// This event controls whether a member of a room can see the events that happened in a room from
|
||||
/// before they joined.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct HistoryVisibilityEvent {
|
||||
pub content: HistoryVisibilityEventContent,
|
||||
pub event_id: String,
|
||||
@ -15,12 +16,14 @@ pub struct HistoryVisibilityEvent {
|
||||
}
|
||||
|
||||
/// The payload of a `HistoryVisibilityEvent`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct HistoryVisibilityEventContent {
|
||||
/// Who can see the room history.
|
||||
pub history_visibility: HistoryVisibility,
|
||||
}
|
||||
|
||||
/// Who can see a room's history.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum HistoryVisibility {
|
||||
/// Previous events are accessible to newly joined members from the point they were invited
|
||||
/// onwards. Events stop being accessible when the member's state changes to something other
|
||||
|
@ -3,6 +3,7 @@
|
||||
use core::EventType;
|
||||
|
||||
/// Describes how users are allowed to join the room.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct JoinRulesEvent {
|
||||
pub content: JoinRulesEventContent,
|
||||
pub event_id: String,
|
||||
@ -14,12 +15,14 @@ pub struct JoinRulesEvent {
|
||||
}
|
||||
|
||||
/// The payload of a `JoinRulesEvent`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct JoinRulesEventContent {
|
||||
/// The type of rules used for users wishing to join this room.
|
||||
pub join_rule: JoinRule,
|
||||
}
|
||||
|
||||
/// The rule used for users wishing to join this room.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum JoinRule {
|
||||
/// A user who wishes to join the room must first receive an invite to the room from someone
|
||||
/// already inside of the room.
|
||||
|
@ -15,6 +15,7 @@ use core::{EventType, StrippedState};
|
||||
/// This event may also include an *invite_room_state* key outside the *content* key. If present,
|
||||
/// this contains an array of `StrippedState` events. These events provide information on a few
|
||||
/// select state events such as the room name.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct MemberEvent {
|
||||
pub content: MemberEventContent,
|
||||
pub event_id: String,
|
||||
@ -27,6 +28,7 @@ pub struct MemberEvent {
|
||||
}
|
||||
|
||||
/// The payload of a `MemberEvent`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct MemberEventContent {
|
||||
pub avatar_url: Option<String>,
|
||||
pub displayname: Option<String>,
|
||||
@ -36,6 +38,7 @@ pub struct MemberEventContent {
|
||||
}
|
||||
|
||||
/// The membership state of a user.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum MembershipState {
|
||||
Ban,
|
||||
Invite,
|
||||
|
@ -18,6 +18,7 @@ pub mod third_party_invite;
|
||||
pub mod topic;
|
||||
|
||||
/// Metadata about an image.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct ImageInfo {
|
||||
pub height: u64,
|
||||
pub mimetype: String,
|
||||
|
@ -3,6 +3,7 @@
|
||||
use core::EventType;
|
||||
|
||||
/// A human-friendly room name designed to be displayed to the end-user.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct NameEvent {
|
||||
pub content: NameEventContent,
|
||||
pub event_id: String,
|
||||
@ -14,6 +15,7 @@ pub struct NameEvent {
|
||||
}
|
||||
|
||||
/// The payload of a `NameEvent`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct NameEventContent {
|
||||
/// The name of the room. This MUST NOT exceed 255 bytes.
|
||||
pub name: String,
|
||||
|
@ -5,6 +5,7 @@ use std::collections::HashMap;
|
||||
use core::EventType;
|
||||
|
||||
/// Defines the power levels (privileges) of users in the room.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct PowerLevelsEvent {
|
||||
pub content: PowerLevelsEventContent,
|
||||
pub event_id: String,
|
||||
@ -16,6 +17,7 @@ pub struct PowerLevelsEvent {
|
||||
}
|
||||
|
||||
/// The payload of a `PowerLevelsEvent`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct PowerLevelsEventContent {
|
||||
pub ban: u64,
|
||||
pub events: HashMap<String, u64>,
|
||||
|
@ -3,6 +3,7 @@
|
||||
use core::EventType;
|
||||
|
||||
/// A redaction of an event.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct RedactionEvent {
|
||||
pub content: RedactionEventContent,
|
||||
pub event_id: String,
|
||||
@ -14,6 +15,7 @@ pub struct RedactionEvent {
|
||||
}
|
||||
|
||||
/// The payload of a `RedactionEvent`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct RedactionEventContent {
|
||||
/// The reason for the redaction, if any.
|
||||
pub reason: Option<String>,
|
||||
|
@ -7,6 +7,7 @@ use core::EventType;
|
||||
/// Acts as an *m.room.member* invite event, where there isn't a target user_id to invite. This
|
||||
/// event contains a token and a public key whose private key must be used to sign the token. Any
|
||||
/// user who can present that signature may use this invitation to join the target room.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct ThirdPartyInviteEvent {
|
||||
pub content: ThirdPartyInviteEventContent,
|
||||
pub event_id: String,
|
||||
@ -18,6 +19,7 @@ pub struct ThirdPartyInviteEvent {
|
||||
}
|
||||
|
||||
/// The payload of a `ThirdPartyInviteEvent`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct ThirdPartyInviteEventContent {
|
||||
pub display_name: String,
|
||||
pub key_validity_url: String,
|
||||
|
@ -3,6 +3,7 @@
|
||||
use core::EventType;
|
||||
|
||||
/// A topic is a short message detailing what is currently being discussed in the room.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct TopicEvent {
|
||||
pub content: TopicEventContent,
|
||||
pub event_id: String,
|
||||
@ -14,6 +15,7 @@ pub struct TopicEvent {
|
||||
}
|
||||
|
||||
/// The payload of a `TopicEvent`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct TopicEventContent {
|
||||
/// The topic text.
|
||||
pub topic: String,
|
||||
|
@ -5,6 +5,7 @@ use std::collections::HashMap;
|
||||
use core::EventType;
|
||||
|
||||
/// Informs the client of tags on a room.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct TagEvent {
|
||||
/// The payload.
|
||||
pub content: TagEventContent,
|
||||
@ -12,12 +13,14 @@ pub struct TagEvent {
|
||||
}
|
||||
|
||||
/// The payload of a `TagEvent`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct TagEventContent {
|
||||
/// A map of tag names to tag info.
|
||||
pub tags: HashMap<String, TagInfo>,
|
||||
}
|
||||
|
||||
/// Information about a tag.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct TagInfo {
|
||||
pub order: Option<u64>,
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
use core::EventType;
|
||||
|
||||
/// Informs the client of the list of users currently typing.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct TypingEvent {
|
||||
/// The payload.
|
||||
pub content: TypingEventContent,
|
||||
@ -12,6 +13,7 @@ pub struct TypingEvent {
|
||||
}
|
||||
|
||||
/// The payload of a `TypingEvent`.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct TypingEventContent {
|
||||
/// The list of user IDs typing in this room, if any.
|
||||
pub user_ids: Vec<String>,
|
||||
|
Loading…
x
Reference in New Issue
Block a user