commit
9d5449b219
1
.rustfmt.toml
Normal file
1
.rustfmt.toml
Normal file
@ -0,0 +1 @@
|
|||||||
|
merge_imports = true
|
@ -9,6 +9,7 @@ name = "ruma-events"
|
|||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
repository = "https://github.com/ruma/ruma-events"
|
repository = "https://github.com/ruma/ruma-events"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ruma-identifiers = "0.11.0"
|
ruma-identifiers = "0.11.0"
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
//! Types for the *m.call.answer* event.
|
//! Types for the *m.call.answer* event.
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::SessionDescription;
|
use super::SessionDescription;
|
||||||
|
|
||||||
room_event! {
|
room_event! {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
//! Types for the *m.call.candidates* event.
|
//! Types for the *m.call.candidates* event.
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
room_event! {
|
room_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
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
//! Types for the *m.call.hangup* event.
|
//! Types for the *m.call.hangup* event.
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
room_event! {
|
room_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.
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
//! Types for the *m.call.invite* event.
|
//! Types for the *m.call.invite* event.
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::SessionDescription;
|
use super::SessionDescription;
|
||||||
|
|
||||||
room_event! {
|
room_event! {
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
//!
|
//!
|
||||||
//! This module also contains types shared by events in its child namespaces.
|
//! This module also contains types shared by events in its child namespaces.
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub mod answer;
|
pub mod answer;
|
||||||
pub mod candidates;
|
pub mod candidates;
|
||||||
pub mod hangup;
|
pub mod hangup;
|
||||||
|
@ -1,34 +1,27 @@
|
|||||||
//! Enums for heterogeneous collections of events, inclusive for every event type that implements
|
//! Enums for heterogeneous collections of events, inclusive for every event type that implements
|
||||||
//! the trait of the same name.
|
//! the trait of the same name.
|
||||||
|
|
||||||
use call::answer::AnswerEvent;
|
use crate::{
|
||||||
use call::candidates::CandidatesEvent;
|
call::{
|
||||||
use call::hangup::HangupEvent;
|
answer::AnswerEvent, candidates::CandidatesEvent, hangup::HangupEvent, invite::InviteEvent,
|
||||||
use call::invite::InviteEvent;
|
},
|
||||||
use direct::DirectEvent;
|
direct::DirectEvent,
|
||||||
use presence::PresenceEvent;
|
presence::PresenceEvent,
|
||||||
use receipt::ReceiptEvent;
|
receipt::ReceiptEvent,
|
||||||
use room::aliases::AliasesEvent;
|
room::{
|
||||||
use room::avatar::AvatarEvent;
|
aliases::AliasesEvent, avatar::AvatarEvent, canonical_alias::CanonicalAliasEvent,
|
||||||
use room::canonical_alias::CanonicalAliasEvent;
|
create::CreateEvent, guest_access::GuestAccessEvent,
|
||||||
use room::create::CreateEvent;
|
history_visibility::HistoryVisibilityEvent, join_rules::JoinRulesEvent,
|
||||||
use room::guest_access::GuestAccessEvent;
|
member::MemberEvent, message::MessageEvent, name::NameEvent,
|
||||||
use room::history_visibility::HistoryVisibilityEvent;
|
pinned_events::PinnedEventsEvent, power_levels::PowerLevelsEvent,
|
||||||
use room::join_rules::JoinRulesEvent;
|
redaction::RedactionEvent, third_party_invite::ThirdPartyInviteEvent, topic::TopicEvent,
|
||||||
use room::member::MemberEvent;
|
},
|
||||||
use room::message::MessageEvent;
|
tag::TagEvent,
|
||||||
use room::name::NameEvent;
|
typing::TypingEvent,
|
||||||
use room::pinned_events::PinnedEventsEvent;
|
CustomEvent, CustomRoomEvent, CustomStateEvent, EventType,
|
||||||
use room::power_levels::PowerLevelsEvent;
|
};
|
||||||
use room::redaction::RedactionEvent;
|
|
||||||
use room::third_party_invite::ThirdPartyInviteEvent;
|
|
||||||
use room::topic::TopicEvent;
|
|
||||||
use tag::TagEvent;
|
|
||||||
use typing::TypingEvent;
|
|
||||||
use {CustomEvent, CustomRoomEvent, CustomStateEvent, EventType};
|
|
||||||
|
|
||||||
use serde::de::Error;
|
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
|
||||||
use serde_json::{from_value, Value};
|
use serde_json::{from_value, Value};
|
||||||
|
|
||||||
/// A basic event, room event, or state event.
|
/// A basic event, room event, or state event.
|
||||||
@ -425,7 +418,8 @@ impl<'de> Deserialize<'de> for Event {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(Event::CustomState(event))
|
Ok(Event::CustomState(event))
|
||||||
} else if value.get("event_id").is_some() && value.get("room_id").is_some()
|
} else if value.get("event_id").is_some()
|
||||||
|
&& value.get("room_id").is_some()
|
||||||
&& value.get("sender").is_some()
|
&& value.get("sender").is_some()
|
||||||
{
|
{
|
||||||
let event = match from_value::<CustomRoomEvent>(value) {
|
let event = match from_value::<CustomRoomEvent>(value) {
|
||||||
|
@ -1,24 +1,22 @@
|
|||||||
//! Enums for heterogeneous collections of events, exclusive to event types that implement "at
|
//! Enums for heterogeneous collections of events, exclusive to event types that implement "at
|
||||||
//! most" the trait of the same name.
|
//! most" the trait of the same name.
|
||||||
|
|
||||||
use call::answer::AnswerEvent;
|
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};
|
||||||
use call::candidates::CandidatesEvent;
|
|
||||||
use call::hangup::HangupEvent;
|
|
||||||
use call::invite::InviteEvent;
|
|
||||||
use direct::DirectEvent;
|
|
||||||
use presence::PresenceEvent;
|
|
||||||
use receipt::ReceiptEvent;
|
|
||||||
use room::message::MessageEvent;
|
|
||||||
use room::redaction::RedactionEvent;
|
|
||||||
use tag::TagEvent;
|
|
||||||
use typing::TypingEvent;
|
|
||||||
use {CustomEvent, CustomRoomEvent, EventType};
|
|
||||||
|
|
||||||
use serde::de::Error;
|
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
|
||||||
use serde_json::{from_value, Value};
|
use serde_json::{from_value, Value};
|
||||||
|
|
||||||
pub use super::all::StateEvent;
|
pub use super::all::StateEvent;
|
||||||
|
use crate::{
|
||||||
|
call::{
|
||||||
|
answer::AnswerEvent, candidates::CandidatesEvent, hangup::HangupEvent, invite::InviteEvent,
|
||||||
|
},
|
||||||
|
direct::DirectEvent,
|
||||||
|
presence::PresenceEvent,
|
||||||
|
receipt::ReceiptEvent,
|
||||||
|
room::{message::MessageEvent, redaction::RedactionEvent},
|
||||||
|
tag::TagEvent,
|
||||||
|
typing::TypingEvent,
|
||||||
|
CustomEvent, CustomRoomEvent, EventType,
|
||||||
|
};
|
||||||
|
|
||||||
/// A basic event.
|
/// A basic event.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use ruma_identifiers::{RoomId, UserId};
|
use ruma_identifiers::{RoomId, UserId};
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
event! {
|
event! {
|
||||||
/// Informs the client about the rooms that are considered direct by a user.
|
/// Informs the client about the rooms that are considered direct by a user.
|
||||||
@ -22,9 +23,11 @@ mod tests {
|
|||||||
use ruma_identifiers::{RoomId, UserId};
|
use ruma_identifiers::{RoomId, UserId};
|
||||||
use serde_json::{from_str, to_string};
|
use serde_json::{from_str, to_string};
|
||||||
|
|
||||||
use super::super::EventType;
|
use crate::{
|
||||||
use collections;
|
collections,
|
||||||
use direct::{DirectEvent, DirectEventContent};
|
direct::{DirectEvent, DirectEventContent},
|
||||||
|
EventType,
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialization() {
|
fn serialization() {
|
||||||
|
18
src/lib.rs
18
src/lib.rs
@ -100,18 +100,14 @@
|
|||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
|
|
||||||
extern crate ruma_identifiers;
|
|
||||||
extern crate ruma_signatures;
|
|
||||||
extern crate serde;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate serde_derive;
|
|
||||||
extern crate serde_json;
|
|
||||||
|
|
||||||
use std::fmt::{Debug, Display, Error as FmtError, Formatter, Result as FmtResult};
|
use std::fmt::{Debug, Display, Error as FmtError, Formatter, Result as FmtResult};
|
||||||
|
|
||||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||||
use serde::de::{Error as SerdeError, Visitor};
|
use serde::{
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
de::{Error as SerdeError, Visitor},
|
||||||
|
Deserialize, Deserializer, Serialize, Serializer,
|
||||||
|
};
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@ -251,7 +247,7 @@ state_event! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Display for EventType {
|
impl Display for EventType {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> {
|
||||||
let event_type_str = match *self {
|
let event_type_str = match *self {
|
||||||
EventType::CallAnswer => "m.call.answer",
|
EventType::CallAnswer => "m.call.answer",
|
||||||
EventType::CallCandidates => "m.call.candidates",
|
EventType::CallCandidates => "m.call.candidates",
|
||||||
@ -335,7 +331,7 @@ impl<'de> Deserialize<'de> for EventType {
|
|||||||
impl<'de> Visitor<'de> for EventTypeVisitor {
|
impl<'de> Visitor<'de> for EventTypeVisitor {
|
||||||
type Value = EventType;
|
type Value = EventType;
|
||||||
|
|
||||||
fn expecting(&self, formatter: &mut Formatter) -> FmtResult {
|
fn expecting(&self, formatter: &mut Formatter<'_>) -> FmtResult {
|
||||||
write!(formatter, "a Matrix event type as a string")
|
write!(formatter, "a Matrix event type as a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
macro_rules! impl_enum {
|
macro_rules! impl_enum {
|
||||||
($name:ident { $($variant:ident => $s:expr,)+ }) => {
|
($name:ident { $($variant:ident => $s:expr,)+ }) => {
|
||||||
impl ::std::fmt::Display for $name {
|
impl ::std::fmt::Display for $name {
|
||||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
|
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
|
||||||
let variant = match *self {
|
let variant = match *self {
|
||||||
$($name::$variant => $s,)*
|
$($name::$variant => $s,)*
|
||||||
};
|
};
|
||||||
@ -39,7 +39,7 @@ macro_rules! event {
|
|||||||
pub content: $content_type,
|
pub content: $content_type,
|
||||||
|
|
||||||
/// The type of the event.
|
/// The type of the event.
|
||||||
#[serde(rename="type")]
|
#[serde(rename = "type")]
|
||||||
pub event_type: $crate::EventType,
|
pub event_type: $crate::EventType,
|
||||||
|
|
||||||
$(
|
$(
|
||||||
@ -87,7 +87,7 @@ macro_rules! room_event {
|
|||||||
pub event_id: ::ruma_identifiers::EventId,
|
pub event_id: ::ruma_identifiers::EventId,
|
||||||
|
|
||||||
/// The type of the event.
|
/// The type of the event.
|
||||||
#[serde(rename="type")]
|
#[serde(rename = "type")]
|
||||||
pub event_type: $crate::EventType,
|
pub event_type: $crate::EventType,
|
||||||
|
|
||||||
/// Timestamp in milliseconds on originating homeserver when this event was sent.
|
/// Timestamp in milliseconds on originating homeserver when this event was sent.
|
||||||
@ -98,7 +98,7 @@ macro_rules! room_event {
|
|||||||
pub room_id: Option<::ruma_identifiers::RoomId>,
|
pub room_id: Option<::ruma_identifiers::RoomId>,
|
||||||
|
|
||||||
/// Additional key-value pairs not signed by the homeserver.
|
/// Additional key-value pairs not signed by the homeserver.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub unsigned: Option<::serde_json::Value>,
|
pub unsigned: Option<::serde_json::Value>,
|
||||||
|
|
||||||
/// The unique identifier for the user who sent this event.
|
/// The unique identifier for the user who sent this event.
|
||||||
@ -162,14 +162,14 @@ macro_rules! state_event {
|
|||||||
pub event_id: ::ruma_identifiers::EventId,
|
pub event_id: ::ruma_identifiers::EventId,
|
||||||
|
|
||||||
/// The type of the event.
|
/// The type of the event.
|
||||||
#[serde(rename="type")]
|
#[serde(rename = "type")]
|
||||||
pub event_type: $crate::EventType,
|
pub event_type: $crate::EventType,
|
||||||
|
|
||||||
/// Timestamp in milliseconds on originating homeserver when this event was sent.
|
/// Timestamp in milliseconds on originating homeserver when this event was sent.
|
||||||
pub origin_server_ts: u64,
|
pub origin_server_ts: u64,
|
||||||
|
|
||||||
/// The previous content for this state key, if any.
|
/// The previous content for this state key, if any.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub prev_content: Option<$content_type>,
|
pub prev_content: Option<$content_type>,
|
||||||
|
|
||||||
/// The unique identifier for the room associated with this event.
|
/// The unique identifier for the room associated with this event.
|
||||||
@ -180,7 +180,7 @@ macro_rules! state_event {
|
|||||||
pub state_key: String,
|
pub state_key: String,
|
||||||
|
|
||||||
/// Additional key-value pairs not signed by the homeserver.
|
/// Additional key-value pairs not signed by the homeserver.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub unsigned: Option<::serde_json::Value>,
|
pub unsigned: Option<::serde_json::Value>,
|
||||||
|
|
||||||
/// The unique identifier for the user associated with this event.
|
/// The unique identifier for the user associated with this event.
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
//! Types for the *m.presence* event.
|
//! Types for the *m.presence* event.
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
use ruma_identifiers::UserId;
|
use ruma_identifiers::UserId;
|
||||||
|
|
||||||
event! {
|
event! {
|
||||||
@ -59,12 +61,13 @@ impl_enum! {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use serde_json::{from_str, to_string};
|
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use ruma_identifiers::UserId;
|
use ruma_identifiers::UserId;
|
||||||
|
use serde_json::{from_str, to_string};
|
||||||
|
|
||||||
use super::{PresenceEvent, PresenceEventContent, PresenceState};
|
use super::{PresenceEvent, PresenceEventContent, PresenceState};
|
||||||
use super::super::{EventType};
|
use crate::EventType;
|
||||||
|
|
||||||
/// Test serialization and deserialization of example m.presence event from the spec
|
/// Test serialization and deserialization of example m.presence event from the spec
|
||||||
/// https://github.com/turt2live/matrix-doc/blob/master/event-schemas/examples/m.presence
|
/// https://github.com/turt2live/matrix-doc/blob/master/event-schemas/examples/m.presence
|
||||||
@ -84,18 +87,9 @@ mod tests {
|
|||||||
let serialized_event =
|
let serialized_event =
|
||||||
r#"{"content":{"avatar_url":"mxc://localhost:wefuiwegh8742w","currently_active":false,"last_active_ago":2478593,"presence":"online"},"type":"m.presence","sender":"@example:localhost"}"#;
|
r#"{"content":{"avatar_url":"mxc://localhost:wefuiwegh8742w","currently_active":false,"last_active_ago":2478593,"presence":"online"},"type":"m.presence","sender":"@example:localhost"}"#;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(to_string(&event).unwrap(), serialized_event);
|
||||||
to_string(&event).unwrap(),
|
|
||||||
serialized_event
|
|
||||||
);
|
|
||||||
let deserialized_event = from_str::<PresenceEvent>(serialized_event).unwrap();
|
let deserialized_event = from_str::<PresenceEvent>(serialized_event).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(deserialized_event.content, event.content);
|
||||||
deserialized_event.content,
|
assert_eq!(deserialized_event.sender, event.sender);
|
||||||
event.content
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
deserialized_event.sender,
|
|
||||||
event.sender
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
event! {
|
event! {
|
||||||
/// Informs the client of new receipts.
|
/// Informs the client of new receipts.
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
//! Types for the *m.room.aliases* event.
|
//! Types for the *m.room.aliases* event.
|
||||||
|
|
||||||
use ruma_identifiers::RoomAliasId;
|
use ruma_identifiers::RoomAliasId;
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
state_event! {
|
state_event! {
|
||||||
/// Informs the room about what room aliases it has been given.
|
/// Informs the room about what room aliases it has been given.
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
//! Types for the *m.room.avatar* event.
|
//! Types for the *m.room.avatar* event.
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::ImageInfo;
|
use super::ImageInfo;
|
||||||
|
|
||||||
state_event! {
|
state_event! {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
//! Types for the *m.room.canonical_alias* event.
|
//! Types for the *m.room.canonical_alias* event.
|
||||||
|
|
||||||
use ruma_identifiers::RoomAliasId;
|
use ruma_identifiers::RoomAliasId;
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
state_event! {
|
state_event! {
|
||||||
/// Informs the room as to which alias is the canonical one.
|
/// Informs the room as to which alias is the canonical one.
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
//! Types for the *m.room.create* event.
|
//! Types for the *m.room.create* event.
|
||||||
|
|
||||||
use ruma_identifiers::UserId;
|
use ruma_identifiers::UserId;
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
state_event! {
|
state_event! {
|
||||||
/// This is the first event in a room and cannot be changed. It acts as the root of all other
|
/// This is the first event in a room and cannot be changed. It acts as the root of all other
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
//! Types for the *m.room.guest_access* event.
|
//! Types for the *m.room.guest_access* event.
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
state_event! {
|
state_event! {
|
||||||
/// Controls whether guest users are allowed to join rooms.
|
/// Controls whether guest users are allowed to join rooms.
|
||||||
///
|
///
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
//! Types for the *m.room.history_visibility* event.
|
//! Types for the *m.room.history_visibility* event.
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
state_event! {
|
state_event! {
|
||||||
/// This event controls whether a member of a room can see the events that happened in a room
|
/// This event controls whether a member of a room can see the events that happened in a room
|
||||||
/// from before they joined.
|
/// from before they joined.
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
//! Types for the *m.room.join_rules* event.
|
//! Types for the *m.room.join_rules* event.
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
state_event! {
|
state_event! {
|
||||||
/// Describes how users are allowed to join the room.
|
/// Describes how users are allowed to join the room.
|
||||||
pub struct JoinRulesEvent(JoinRulesEventContent) {}
|
pub struct JoinRulesEvent(JoinRulesEventContent) {}
|
||||||
|
@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
use ruma_identifiers::UserId;
|
use ruma_identifiers::UserId;
|
||||||
use ruma_signatures::Signatures;
|
use ruma_signatures::Signatures;
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
use stripped::StrippedState;
|
use crate::stripped::StrippedState;
|
||||||
|
|
||||||
state_event! {
|
state_event! {
|
||||||
/// The current membership state of a user in the room.
|
/// The current membership state of a user in the room.
|
||||||
@ -22,7 +23,7 @@ state_event! {
|
|||||||
/// on a few select state events such as the room name.
|
/// on a few select state events such as the room name.
|
||||||
pub struct MemberEvent(MemberEventContent) {
|
pub struct MemberEvent(MemberEventContent) {
|
||||||
/// A subset of the state of the room at the time of the invite.
|
/// A subset of the state of the room at the time of the invite.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub invite_room_state: Option<Vec<StrippedState>>
|
pub invite_room_state: Option<Vec<StrippedState>>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! Types for the *m.room.message* event.
|
//! Types for the *m.room.message* event.
|
||||||
|
|
||||||
use serde::de::Error;
|
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use serde_json::{from_value, Value};
|
use serde_json::{from_value, Value};
|
||||||
|
|
||||||
use super::{ImageInfo, ThumbnailInfo};
|
use super::{ImageInfo, ThumbnailInfo};
|
||||||
@ -396,17 +396,17 @@ mod tests {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
from_str::<MessageEventContent>(
|
from_str::<MessageEventContent>(
|
||||||
r#"{"body":"test","msgtype":"m.audio","url":"http://example.com/audio.mp3"}"#
|
r#"{"body":"test","msgtype":"m.audio","url":"http://example.com/audio.mp3"}"#
|
||||||
).unwrap(),
|
)
|
||||||
|
.unwrap(),
|
||||||
message_event_content
|
message_event_content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialization_failure() {
|
fn deserialization_failure() {
|
||||||
assert!(
|
assert!(from_str::<MessageEventContent>(
|
||||||
from_str::<MessageEventContent>(
|
r#"{"body":"test","msgtype":"m.location","url":"http://example.com/audio.mp3"}"#
|
||||||
r#"{"body":"test","msgtype":"m.location","url":"http://example.com/audio.mp3"}"#
|
)
|
||||||
).is_err()
|
.is_err());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
//!
|
//!
|
||||||
//! This module also contains types shared by events in its child namespaces.
|
//! This module also contains types shared by events in its child namespaces.
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub mod aliases;
|
pub mod aliases;
|
||||||
pub mod avatar;
|
pub mod avatar;
|
||||||
pub mod canonical_alias;
|
pub mod canonical_alias;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
//! Types for the *m.room.name* event.
|
//! Types for the *m.room.name* event.
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
state_event! {
|
state_event! {
|
||||||
/// A human-friendly room name designed to be displayed to the end-user.
|
/// A human-friendly room name designed to be displayed to the end-user.
|
||||||
pub struct NameEvent(NameEventContent) {}
|
pub struct NameEvent(NameEventContent) {}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
//! Types for the *m.room.pinned_events* event.
|
//! Types for the *m.room.pinned_events* event.
|
||||||
|
|
||||||
use ruma_identifiers::EventId;
|
use ruma_identifiers::EventId;
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
state_event! {
|
state_event! {
|
||||||
/// Used to "pin" particular events in a room for other participants to review later.
|
/// Used to "pin" particular events in a room for other participants to review later.
|
||||||
@ -19,11 +20,10 @@ mod tests {
|
|||||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||||
use serde_json::{from_str, to_string};
|
use serde_json::{from_str, to_string};
|
||||||
|
|
||||||
use room::pinned_events::{PinnedEventsContent, PinnedEventsEvent};
|
use crate::{
|
||||||
use Event;
|
room::pinned_events::{PinnedEventsContent, PinnedEventsEvent},
|
||||||
use EventType;
|
Event, EventType, RoomEvent, StateEvent,
|
||||||
use RoomEvent;
|
};
|
||||||
use StateEvent;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialization_deserialization() {
|
fn serialization_deserialization() {
|
||||||
|
@ -3,8 +3,9 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use ruma_identifiers::UserId;
|
use ruma_identifiers::UserId;
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
use EventType;
|
use crate::EventType;
|
||||||
|
|
||||||
state_event! {
|
state_event! {
|
||||||
/// Defines the power levels (privileges) of users in the room.
|
/// Defines the power levels (privileges) of users in the room.
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
//! Types for the *m.room.redaction* event.
|
//! Types for the *m.room.redaction* event.
|
||||||
|
|
||||||
use ruma_identifiers::EventId;
|
use ruma_identifiers::EventId;
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
room_event! {
|
room_event! {
|
||||||
/// A redaction of an event.
|
/// A redaction of an event.
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
//! Types for the *m.room.third_party_invite* event.
|
//! Types for the *m.room.third_party_invite* event.
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
state_event! {
|
state_event! {
|
||||||
/// An invitation to a room issued to a third party identifier, rather than a matrix user ID.
|
/// An invitation to a room issued to a third party identifier, rather than a matrix user ID.
|
||||||
///
|
///
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
//! Types for the *m.room.topic* event.
|
//! Types for the *m.room.topic* event.
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
state_event! {
|
state_event! {
|
||||||
/// A topic is a short message detailing what is currently being discussed in the room.
|
/// A topic is a short message detailing what is currently being discussed in the room.
|
||||||
pub struct TopicEvent(TopicEventContent) {}
|
pub struct TopicEvent(TopicEventContent) {}
|
||||||
|
@ -6,23 +6,21 @@
|
|||||||
//! the other fields are otherwise inapplicable.
|
//! the other fields are otherwise inapplicable.
|
||||||
|
|
||||||
use ruma_identifiers::UserId;
|
use ruma_identifiers::UserId;
|
||||||
use serde::de::Error;
|
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use serde_json::{from_value, Value};
|
use serde_json::{from_value, Value};
|
||||||
|
|
||||||
use room::aliases::AliasesEventContent;
|
use crate::{
|
||||||
use room::avatar::AvatarEventContent;
|
room::{
|
||||||
use room::canonical_alias::CanonicalAliasEventContent;
|
aliases::AliasesEventContent, avatar::AvatarEventContent,
|
||||||
use room::create::CreateEventContent;
|
canonical_alias::CanonicalAliasEventContent, create::CreateEventContent,
|
||||||
use room::guest_access::GuestAccessEventContent;
|
guest_access::GuestAccessEventContent, history_visibility::HistoryVisibilityEventContent,
|
||||||
use room::history_visibility::HistoryVisibilityEventContent;
|
join_rules::JoinRulesEventContent, member::MemberEventContent, name::NameEventContent,
|
||||||
use room::join_rules::JoinRulesEventContent;
|
power_levels::PowerLevelsEventContent, third_party_invite::ThirdPartyInviteEventContent,
|
||||||
use room::member::MemberEventContent;
|
topic::TopicEventContent,
|
||||||
use room::name::NameEventContent;
|
},
|
||||||
use room::power_levels::PowerLevelsEventContent;
|
EventType,
|
||||||
use room::third_party_invite::ThirdPartyInviteEventContent;
|
};
|
||||||
use room::topic::TopicEventContent;
|
|
||||||
use EventType;
|
|
||||||
|
|
||||||
/// A stripped-down version of a state event that is included along with some other events.
|
/// A stripped-down version of a state event that is included along with some other events.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@ -265,9 +263,10 @@ mod tests {
|
|||||||
use serde_json::{from_str, to_string};
|
use serde_json::{from_str, to_string};
|
||||||
|
|
||||||
use super::{StrippedRoomTopic, StrippedState};
|
use super::{StrippedRoomTopic, StrippedState};
|
||||||
use room::join_rules::JoinRule;
|
use crate::{
|
||||||
use room::topic::TopicEventContent;
|
room::{join_rules::JoinRule, topic::TopicEventContent},
|
||||||
use EventType;
|
EventType,
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialize_stripped_state_event() {
|
fn serialize_stripped_state_event() {
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
event! {
|
event! {
|
||||||
/// Informs the client of tags on a room.
|
/// Informs the client of tags on a room.
|
||||||
pub struct TagEvent(TagEventContent) {}
|
pub struct TagEvent(TagEventContent) {}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
//! Types for the *m.typing* event.
|
//! Types for the *m.typing* event.
|
||||||
|
|
||||||
use ruma_identifiers::{RoomId, UserId};
|
use ruma_identifiers::{RoomId, UserId};
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
event! {
|
event! {
|
||||||
/// Informs the client of the list of users currently typing.
|
/// Informs the client of the list of users currently typing.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user