Run rustfmt.
This commit is contained in:
parent
601f00e820
commit
3acc5c3a93
@ -11,7 +11,7 @@ pub mod invite;
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct SessionDescription {
|
pub struct SessionDescription {
|
||||||
/// The type of session description.
|
/// The type of session description.
|
||||||
#[serde(rename="type")]
|
#[serde(rename = "type")]
|
||||||
pub session_type: SessionDescriptionType,
|
pub session_type: SessionDescriptionType,
|
||||||
/// The SDP text of the session description.
|
/// The SDP text of the session description.
|
||||||
pub sdp: String,
|
pub sdp: String,
|
||||||
@ -21,10 +21,10 @@ pub struct SessionDescription {
|
|||||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
|
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
|
||||||
pub enum SessionDescriptionType {
|
pub enum SessionDescriptionType {
|
||||||
/// An answer.
|
/// An answer.
|
||||||
#[serde(rename="answer")]
|
#[serde(rename = "answer")]
|
||||||
Answer,
|
Answer,
|
||||||
/// An offer.
|
/// An offer.
|
||||||
#[serde(rename="offer")]
|
#[serde(rename = "offer")]
|
||||||
Offer,
|
Offer,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
//! 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 {CustomEvent, CustomRoomEvent, CustomStateEvent, EventType};
|
|
||||||
use call::answer::AnswerEvent;
|
use call::answer::AnswerEvent;
|
||||||
use call::candidates::CandidatesEvent;
|
use call::candidates::CandidatesEvent;
|
||||||
use call::hangup::HangupEvent;
|
use call::hangup::HangupEvent;
|
||||||
@ -26,10 +25,11 @@ use room::third_party_invite::ThirdPartyInviteEvent;
|
|||||||
use room::topic::TopicEvent;
|
use room::topic::TopicEvent;
|
||||||
use tag::TagEvent;
|
use tag::TagEvent;
|
||||||
use typing::TypingEvent;
|
use typing::TypingEvent;
|
||||||
|
use {CustomEvent, CustomRoomEvent, CustomStateEvent, EventType};
|
||||||
|
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
|
||||||
use serde::de::Error;
|
use serde::de::Error;
|
||||||
use serde_json::{Value, from_value};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
use serde_json::{from_value, Value};
|
||||||
|
|
||||||
/// A basic event, room event, or state event.
|
/// A basic event, room event, or state event.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@ -171,7 +171,10 @@ pub enum StateEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Serialize for Event {
|
impl Serialize for Event {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
match *self {
|
match *self {
|
||||||
Event::CallAnswer(ref event) => event.serialize(serializer),
|
Event::CallAnswer(ref event) => event.serialize(serializer),
|
||||||
Event::CallCandidates(ref event) => event.serialize(serializer),
|
Event::CallCandidates(ref event) => event.serialize(serializer),
|
||||||
@ -205,7 +208,10 @@ impl Serialize for Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for Event {
|
impl<'de> Deserialize<'de> for Event {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<'de> {
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
let value: Value = Deserialize::deserialize(deserializer)?;
|
let value: Value = Deserialize::deserialize(deserializer)?;
|
||||||
|
|
||||||
let event_type_value = match value.get("type") {
|
let event_type_value = match value.get("type") {
|
||||||
@ -419,8 +425,9 @@ 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) {
|
||||||
Ok(event) => event,
|
Ok(event) => event,
|
||||||
Err(error) => return Err(D::Error::custom(error.to_string())),
|
Err(error) => return Err(D::Error::custom(error.to_string())),
|
||||||
@ -441,7 +448,10 @@ impl<'de> Deserialize<'de> for Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Serialize for RoomEvent {
|
impl Serialize for RoomEvent {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
match *self {
|
match *self {
|
||||||
RoomEvent::CallAnswer(ref event) => event.serialize(serializer),
|
RoomEvent::CallAnswer(ref event) => event.serialize(serializer),
|
||||||
RoomEvent::CallCandidates(ref event) => event.serialize(serializer),
|
RoomEvent::CallCandidates(ref event) => event.serialize(serializer),
|
||||||
@ -469,7 +479,10 @@ impl Serialize for RoomEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for RoomEvent {
|
impl<'de> Deserialize<'de> for RoomEvent {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<'de> {
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
let value: Value = Deserialize::deserialize(deserializer)?;
|
let value: Value = Deserialize::deserialize(deserializer)?;
|
||||||
|
|
||||||
let event_type_value = match value.get("type") {
|
let event_type_value = match value.get("type") {
|
||||||
@ -652,11 +665,11 @@ impl<'de> Deserialize<'de> for RoomEvent {
|
|||||||
Ok(RoomEvent::CustomRoom(event))
|
Ok(RoomEvent::CustomRoom(event))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EventType::Direct |
|
EventType::Direct
|
||||||
EventType::Presence |
|
| EventType::Presence
|
||||||
EventType::Receipt |
|
| EventType::Receipt
|
||||||
EventType::Tag |
|
| EventType::Tag
|
||||||
EventType::Typing => {
|
| EventType::Typing => {
|
||||||
return Err(D::Error::custom("not a room event".to_string()));
|
return Err(D::Error::custom("not a room event".to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -664,7 +677,10 @@ impl<'de> Deserialize<'de> for RoomEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Serialize for StateEvent {
|
impl Serialize for StateEvent {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
match *self {
|
match *self {
|
||||||
StateEvent::RoomAliases(ref event) => event.serialize(serializer),
|
StateEvent::RoomAliases(ref event) => event.serialize(serializer),
|
||||||
StateEvent::RoomAvatar(ref event) => event.serialize(serializer),
|
StateEvent::RoomAvatar(ref event) => event.serialize(serializer),
|
||||||
@ -685,7 +701,10 @@ impl Serialize for StateEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for StateEvent {
|
impl<'de> Deserialize<'de> for StateEvent {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<'de> {
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
let value: Value = Deserialize::deserialize(deserializer)?;
|
let value: Value = Deserialize::deserialize(deserializer)?;
|
||||||
|
|
||||||
let event_type_value = match value.get("type") {
|
let event_type_value = match value.get("type") {
|
||||||
@ -811,17 +830,17 @@ impl<'de> Deserialize<'de> for StateEvent {
|
|||||||
|
|
||||||
Ok(StateEvent::CustomState(event))
|
Ok(StateEvent::CustomState(event))
|
||||||
}
|
}
|
||||||
EventType::CallAnswer |
|
EventType::CallAnswer
|
||||||
EventType::CallCandidates |
|
| EventType::CallCandidates
|
||||||
EventType::CallHangup |
|
| EventType::CallHangup
|
||||||
EventType::CallInvite |
|
| EventType::CallInvite
|
||||||
EventType::Direct |
|
| EventType::Direct
|
||||||
EventType::Presence |
|
| EventType::Presence
|
||||||
EventType::Receipt |
|
| EventType::Receipt
|
||||||
EventType::RoomMessage |
|
| EventType::RoomMessage
|
||||||
EventType::RoomRedaction |
|
| EventType::RoomRedaction
|
||||||
EventType::Tag |
|
| EventType::Tag
|
||||||
EventType::Typing => {
|
| EventType::Typing => {
|
||||||
return Err(D::Error::custom("not a state event".to_string()));
|
return Err(D::Error::custom("not a state event".to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
//! 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 {CustomEvent, CustomRoomEvent, EventType};
|
|
||||||
use call::answer::AnswerEvent;
|
use call::answer::AnswerEvent;
|
||||||
use call::candidates::CandidatesEvent;
|
use call::candidates::CandidatesEvent;
|
||||||
use call::hangup::HangupEvent;
|
use call::hangup::HangupEvent;
|
||||||
@ -13,10 +12,11 @@ use room::message::MessageEvent;
|
|||||||
use room::redaction::RedactionEvent;
|
use room::redaction::RedactionEvent;
|
||||||
use tag::TagEvent;
|
use tag::TagEvent;
|
||||||
use typing::TypingEvent;
|
use typing::TypingEvent;
|
||||||
|
use {CustomEvent, CustomRoomEvent, EventType};
|
||||||
|
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
|
||||||
use serde::de::Error;
|
use serde::de::Error;
|
||||||
use serde_json::{Value, from_value};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
use serde_json::{from_value, Value};
|
||||||
|
|
||||||
pub use super::all::StateEvent;
|
pub use super::all::StateEvent;
|
||||||
|
|
||||||
@ -57,7 +57,10 @@ pub enum RoomEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Serialize for Event {
|
impl Serialize for Event {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
match *self {
|
match *self {
|
||||||
Event::Direct(ref event) => event.serialize(serializer),
|
Event::Direct(ref event) => event.serialize(serializer),
|
||||||
Event::Presence(ref event) => event.serialize(serializer),
|
Event::Presence(ref event) => event.serialize(serializer),
|
||||||
@ -70,7 +73,10 @@ impl Serialize for Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for Event {
|
impl<'de> Deserialize<'de> for Event {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<'de> {
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
let value: Value = Deserialize::deserialize(deserializer)?;
|
let value: Value = Deserialize::deserialize(deserializer)?;
|
||||||
|
|
||||||
let event_type_value = match value.get("type") {
|
let event_type_value = match value.get("type") {
|
||||||
@ -132,21 +138,38 @@ impl<'de> Deserialize<'de> for Event {
|
|||||||
|
|
||||||
Ok(Event::Custom(event))
|
Ok(Event::Custom(event))
|
||||||
}
|
}
|
||||||
EventType::CallAnswer | EventType::CallCandidates | EventType::CallHangup |
|
EventType::CallAnswer
|
||||||
EventType::CallInvite | EventType::RoomAliases | EventType::RoomAvatar |
|
| EventType::CallCandidates
|
||||||
EventType::RoomCanonicalAlias | EventType::RoomCreate | EventType::RoomGuestAccess |
|
| EventType::CallHangup
|
||||||
EventType::RoomHistoryVisibility | EventType::RoomJoinRules | EventType::RoomMember |
|
| EventType::CallInvite
|
||||||
EventType::RoomMessage | EventType::RoomName | EventType::RoomPinnedEvents |
|
| EventType::RoomAliases
|
||||||
EventType::RoomPowerLevels | EventType::RoomRedaction | EventType::RoomThirdPartyInvite |
|
| EventType::RoomAvatar
|
||||||
EventType::RoomTopic => {
|
| EventType::RoomCanonicalAlias
|
||||||
return Err(D::Error::custom("not exclusively a basic event".to_string()));
|
| EventType::RoomCreate
|
||||||
|
| EventType::RoomGuestAccess
|
||||||
|
| EventType::RoomHistoryVisibility
|
||||||
|
| EventType::RoomJoinRules
|
||||||
|
| EventType::RoomMember
|
||||||
|
| EventType::RoomMessage
|
||||||
|
| EventType::RoomName
|
||||||
|
| EventType::RoomPinnedEvents
|
||||||
|
| EventType::RoomPowerLevels
|
||||||
|
| EventType::RoomRedaction
|
||||||
|
| EventType::RoomThirdPartyInvite
|
||||||
|
| EventType::RoomTopic => {
|
||||||
|
return Err(D::Error::custom(
|
||||||
|
"not exclusively a basic event".to_string(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Serialize for RoomEvent {
|
impl Serialize for RoomEvent {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
match *self {
|
match *self {
|
||||||
RoomEvent::CallAnswer(ref event) => event.serialize(serializer),
|
RoomEvent::CallAnswer(ref event) => event.serialize(serializer),
|
||||||
RoomEvent::CallCandidates(ref event) => event.serialize(serializer),
|
RoomEvent::CallCandidates(ref event) => event.serialize(serializer),
|
||||||
@ -160,7 +183,10 @@ impl Serialize for RoomEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for RoomEvent {
|
impl<'de> Deserialize<'de> for RoomEvent {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<'de> {
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
let value: Value = Deserialize::deserialize(deserializer)?;
|
let value: Value = Deserialize::deserialize(deserializer)?;
|
||||||
|
|
||||||
let event_type_value = match value.get("type") {
|
let event_type_value = match value.get("type") {
|
||||||
@ -230,24 +256,24 @@ impl<'de> Deserialize<'de> for RoomEvent {
|
|||||||
|
|
||||||
Ok(RoomEvent::CustomRoom(event))
|
Ok(RoomEvent::CustomRoom(event))
|
||||||
}
|
}
|
||||||
EventType::Direct |
|
EventType::Direct
|
||||||
EventType::Presence |
|
| EventType::Presence
|
||||||
EventType::Receipt |
|
| EventType::Receipt
|
||||||
EventType::RoomAliases |
|
| EventType::RoomAliases
|
||||||
EventType::RoomAvatar |
|
| EventType::RoomAvatar
|
||||||
EventType::RoomCanonicalAlias |
|
| EventType::RoomCanonicalAlias
|
||||||
EventType::RoomCreate |
|
| EventType::RoomCreate
|
||||||
EventType::RoomGuestAccess |
|
| EventType::RoomGuestAccess
|
||||||
EventType::RoomHistoryVisibility |
|
| EventType::RoomHistoryVisibility
|
||||||
EventType::RoomJoinRules |
|
| EventType::RoomJoinRules
|
||||||
EventType::RoomMember |
|
| EventType::RoomMember
|
||||||
EventType::RoomName |
|
| EventType::RoomName
|
||||||
EventType::RoomPinnedEvents |
|
| EventType::RoomPinnedEvents
|
||||||
EventType::RoomPowerLevels |
|
| EventType::RoomPowerLevels
|
||||||
EventType::RoomThirdPartyInvite |
|
| EventType::RoomThirdPartyInvite
|
||||||
EventType::RoomTopic |
|
| EventType::RoomTopic
|
||||||
EventType::Tag |
|
| EventType::Tag
|
||||||
EventType::Typing => {
|
| EventType::Typing => {
|
||||||
return Err(D::Error::custom("not exclusively a room event".to_string()));
|
return Err(D::Error::custom("not exclusively a room event".to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use ruma_identifiers::{UserId, RoomId};
|
use ruma_identifiers::{RoomId, UserId};
|
||||||
|
|
||||||
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.
|
||||||
@ -19,12 +19,12 @@ pub type DirectEventContent = HashMap<UserId, Vec<RoomId>>;
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use ruma_identifiers::{UserId, RoomId};
|
use ruma_identifiers::{RoomId, UserId};
|
||||||
use serde_json::{from_str, to_string};
|
use serde_json::{from_str, to_string};
|
||||||
|
|
||||||
|
use super::super::EventType;
|
||||||
use collections;
|
use collections;
|
||||||
use direct::{DirectEvent, DirectEventContent};
|
use direct::{DirectEvent, DirectEventContent};
|
||||||
use super::super::EventType;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialization() {
|
fn serialization() {
|
||||||
@ -43,7 +43,8 @@ mod tests {
|
|||||||
to_string(&event).unwrap(),
|
to_string(&event).unwrap(),
|
||||||
format!(
|
format!(
|
||||||
r#"{{"content":{{"{}":["{}"]}},"type":"m.direct"}}"#,
|
r#"{{"content":{{"{}":["{}"]}},"type":"m.direct"}}"#,
|
||||||
alice.to_string(), room[0].to_string()
|
alice.to_string(),
|
||||||
|
room[0].to_string()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -53,13 +54,18 @@ mod tests {
|
|||||||
let alice = UserId::new("ruma.io").unwrap();
|
let alice = UserId::new("ruma.io").unwrap();
|
||||||
let rooms = vec![
|
let rooms = vec![
|
||||||
RoomId::new("ruma.io").unwrap(),
|
RoomId::new("ruma.io").unwrap(),
|
||||||
RoomId::new("ruma.io").unwrap()
|
RoomId::new("ruma.io").unwrap(),
|
||||||
];
|
];
|
||||||
|
|
||||||
let json_data = format!(r#"{{
|
let json_data = format!(
|
||||||
|
r#"{{
|
||||||
"content": {{ "{}": ["{}", "{}"] }},
|
"content": {{ "{}": ["{}", "{}"] }},
|
||||||
"type": "m.direct"
|
"type": "m.direct"
|
||||||
}}"#, alice.to_string(), rooms[0].to_string(), rooms[1].to_string());
|
}}"#,
|
||||||
|
alice.to_string(),
|
||||||
|
rooms[0].to_string(),
|
||||||
|
rooms[1].to_string()
|
||||||
|
);
|
||||||
|
|
||||||
let event = from_str::<DirectEvent>(&json_data).unwrap();
|
let event = from_str::<DirectEvent>(&json_data).unwrap();
|
||||||
assert_eq!(event.event_type, EventType::Direct);
|
assert_eq!(event.event_type, EventType::Direct);
|
||||||
@ -75,8 +81,8 @@ mod tests {
|
|||||||
let direct_rooms = event.content.get(&alice).unwrap();
|
let direct_rooms = event.content.get(&alice).unwrap();
|
||||||
assert!(direct_rooms.contains(&rooms[0]));
|
assert!(direct_rooms.contains(&rooms[0]));
|
||||||
assert!(direct_rooms.contains(&rooms[1]));
|
assert!(direct_rooms.contains(&rooms[1]));
|
||||||
},
|
}
|
||||||
_ => assert!(false)
|
_ => assert!(false),
|
||||||
};
|
};
|
||||||
|
|
||||||
match from_str::<collections::only::Event>(&json_data).unwrap() {
|
match from_str::<collections::only::Event>(&json_data).unwrap() {
|
||||||
@ -86,8 +92,8 @@ mod tests {
|
|||||||
let direct_rooms = event.content.get(&alice).unwrap();
|
let direct_rooms = event.content.get(&alice).unwrap();
|
||||||
assert!(direct_rooms.contains(&rooms[0]));
|
assert!(direct_rooms.contains(&rooms[0]));
|
||||||
assert!(direct_rooms.contains(&rooms[1]));
|
assert!(direct_rooms.contains(&rooms[1]));
|
||||||
},
|
}
|
||||||
_ => assert!(false)
|
_ => assert!(false),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
32
src/lib.rs
32
src/lib.rs
@ -102,17 +102,19 @@
|
|||||||
extern crate ruma_identifiers;
|
extern crate ruma_identifiers;
|
||||||
extern crate ruma_signatures;
|
extern crate ruma_signatures;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
#[macro_use] extern crate serde_derive;
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
use std::fmt::{Debug, Display, Formatter, Error as FmtError, 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::{Deserialize, Deserializer, Serialize, Serializer};
|
|
||||||
use serde::de::{Error as SerdeError, Visitor};
|
use serde::de::{Error as SerdeError, Visitor};
|
||||||
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
#[macro_use] mod macros;
|
#[macro_use]
|
||||||
|
mod macros;
|
||||||
|
|
||||||
pub mod call;
|
pub mod call;
|
||||||
/// Enums for heterogeneous collections of events.
|
/// Enums for heterogeneous collections of events.
|
||||||
@ -188,7 +190,10 @@ pub enum EventType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A basic event.
|
/// A basic event.
|
||||||
pub trait Event where Self: Debug + for<'a> Deserialize<'a> + Serialize {
|
pub trait Event
|
||||||
|
where
|
||||||
|
Self: Debug + for<'a> Deserialize<'a> + Serialize,
|
||||||
|
{
|
||||||
/// The event-type-specific payload this event carries.
|
/// The event-type-specific payload this event carries.
|
||||||
type Content: Debug + for<'a> Deserialize<'a> + Serialize;
|
type Content: Debug + for<'a> Deserialize<'a> + Serialize;
|
||||||
|
|
||||||
@ -261,7 +266,7 @@ impl Display for EventType {
|
|||||||
EventType::RoomMember => "m.room.member",
|
EventType::RoomMember => "m.room.member",
|
||||||
EventType::RoomMessage => "m.room.message",
|
EventType::RoomMessage => "m.room.message",
|
||||||
EventType::RoomName => "m.room.name",
|
EventType::RoomName => "m.room.name",
|
||||||
EventType::RoomPinnedEvents=> "m.room.pinned_events",
|
EventType::RoomPinnedEvents => "m.room.pinned_events",
|
||||||
EventType::RoomPowerLevels => "m.room.power_levels",
|
EventType::RoomPowerLevels => "m.room.power_levels",
|
||||||
EventType::RoomRedaction => "m.room.redaction",
|
EventType::RoomRedaction => "m.room.redaction",
|
||||||
EventType::RoomThirdPartyInvite => "m.room.third_party_invite",
|
EventType::RoomThirdPartyInvite => "m.room.third_party_invite",
|
||||||
@ -308,13 +313,19 @@ impl<'a> From<&'a str> for EventType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Serialize for EventType {
|
impl Serialize for EventType {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
serializer.serialize_str(&self.to_string())
|
serializer.serialize_str(&self.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for EventType {
|
impl<'de> Deserialize<'de> for EventType {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<'de> {
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
struct EventTypeVisitor;
|
struct EventTypeVisitor;
|
||||||
|
|
||||||
impl<'de> Visitor<'de> for EventTypeVisitor {
|
impl<'de> Visitor<'de> for EventTypeVisitor {
|
||||||
@ -324,7 +335,10 @@ impl<'de> Deserialize<'de> for EventType {
|
|||||||
write!(formatter, "a Matrix event type as a string")
|
write!(formatter, "a Matrix event type as a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: SerdeError {
|
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||||
|
where
|
||||||
|
E: SerdeError,
|
||||||
|
{
|
||||||
Ok(EventType::from(v))
|
Ok(EventType::from(v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ macro_rules! impl_event {
|
|||||||
&self.event_type
|
&self.event_type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! room_event {
|
macro_rules! room_event {
|
||||||
@ -138,7 +138,7 @@ macro_rules! impl_room_event {
|
|||||||
&self.sender
|
&self.sender
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! state_event {
|
macro_rules! state_event {
|
||||||
@ -207,5 +207,5 @@ macro_rules! impl_state_event {
|
|||||||
&self.state_key
|
&self.state_key
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
@ -14,19 +14,19 @@ event! {
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct PresenceEventContent {
|
pub struct PresenceEventContent {
|
||||||
/// The current avatar URL for this user.
|
/// The current avatar URL for this user.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub avatar_url: Option<String>,
|
pub avatar_url: Option<String>,
|
||||||
|
|
||||||
/// Whether or not the user is currently active.
|
/// Whether or not the user is currently active.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub currently_active: Option<bool>,
|
pub currently_active: Option<bool>,
|
||||||
|
|
||||||
/// The current display name for this user.
|
/// The current display name for this user.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub displayname: Option<String>,
|
pub displayname: Option<String>,
|
||||||
|
|
||||||
/// The last time since this user performed some action, in milliseconds.
|
/// The last time since this user performed some action, in milliseconds.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub last_active_ago: Option<u64>,
|
pub last_active_ago: Option<u64>,
|
||||||
|
|
||||||
/// The presence state for this user.
|
/// The presence state for this user.
|
||||||
@ -40,15 +40,15 @@ pub struct PresenceEventContent {
|
|||||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
|
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
|
||||||
pub enum PresenceState {
|
pub enum PresenceState {
|
||||||
/// Disconnected from the service.
|
/// Disconnected from the service.
|
||||||
#[serde(rename="offline")]
|
#[serde(rename = "offline")]
|
||||||
Offline,
|
Offline,
|
||||||
|
|
||||||
/// Connected to the service.
|
/// Connected to the service.
|
||||||
#[serde(rename="online")]
|
#[serde(rename = "online")]
|
||||||
Online,
|
Online,
|
||||||
|
|
||||||
/// Connected to the service but not available for chat.
|
/// Connected to the service but not available for chat.
|
||||||
#[serde(rename="unavailable")]
|
#[serde(rename = "unavailable")]
|
||||||
Unavailable,
|
Unavailable,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ pub type ReceiptEventContent = HashMap<EventId, Receipts>;
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct Receipts {
|
pub struct Receipts {
|
||||||
/// A collection of users who have sent *m.read* receipts for this event.
|
/// A collection of users who have sent *m.read* receipts for this event.
|
||||||
#[serde(rename="m.read")]
|
#[serde(rename = "m.read")]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub m_read: UserReceipts,
|
pub m_read: UserReceipts,
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,13 @@ state_event! {
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct AvatarEventContent {
|
pub struct AvatarEventContent {
|
||||||
/// Information about the avatar image.
|
/// Information about the avatar image.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub info: Option<ImageInfo>,
|
pub info: Option<ImageInfo>,
|
||||||
/// Information about the avatar thumbnail image.
|
/// Information about the avatar thumbnail image.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub thumbnail_info: Option<ImageInfo>,
|
pub thumbnail_info: Option<ImageInfo>,
|
||||||
/// URL of the avatar thumbnail image.
|
/// URL of the avatar thumbnail image.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub thumbnail_url: Option<String>,
|
pub thumbnail_url: Option<String>,
|
||||||
/// URL of the avatar image.
|
/// URL of the avatar image.
|
||||||
pub url: String,
|
pub url: String,
|
||||||
|
@ -14,6 +14,6 @@ pub struct CreateEventContent {
|
|||||||
/// The `user_id` of the room creator. This is set by the homeserver.
|
/// The `user_id` of the room creator. This is set by the homeserver.
|
||||||
pub creator: UserId,
|
pub creator: UserId,
|
||||||
/// Whether or not this room's data should be transferred to other homeservers.
|
/// Whether or not this room's data should be transferred to other homeservers.
|
||||||
#[serde(rename="m.federate")]
|
#[serde(rename = "m.federate")]
|
||||||
pub federate: Option<bool>,
|
pub federate: Option<bool>,
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,11 @@ pub struct GuestAccessEventContent {
|
|||||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
|
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
|
||||||
pub enum GuestAccess {
|
pub enum GuestAccess {
|
||||||
/// Guests are allowed to join the room.
|
/// Guests are allowed to join the room.
|
||||||
#[serde(rename="can_join")]
|
#[serde(rename = "can_join")]
|
||||||
CanJoin,
|
CanJoin,
|
||||||
|
|
||||||
/// Guests are not allowed to join the room.
|
/// Guests are not allowed to join the room.
|
||||||
#[serde(rename="forbidden")]
|
#[serde(rename = "forbidden")]
|
||||||
Forbidden,
|
Forbidden,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,23 +19,23 @@ pub enum HistoryVisibility {
|
|||||||
/// Previous events are accessible to newly joined members from the point they were invited
|
/// 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
|
/// onwards. Events stop being accessible when the member's state changes to something other
|
||||||
/// than *invite* or *join*.
|
/// than *invite* or *join*.
|
||||||
#[serde(rename="invited")]
|
#[serde(rename = "invited")]
|
||||||
Invited,
|
Invited,
|
||||||
|
|
||||||
/// Previous events are accessible to newly joined members from the point they joined the room
|
/// Previous events are accessible to newly joined members from the point they joined the room
|
||||||
/// onwards. Events stop being accessible when the member's state changes to something other
|
/// onwards. Events stop being accessible when the member's state changes to something other
|
||||||
/// than *join*.
|
/// than *join*.
|
||||||
#[serde(rename="joined")]
|
#[serde(rename = "joined")]
|
||||||
Joined,
|
Joined,
|
||||||
|
|
||||||
/// Previous events are always accessible to newly joined members. All events in the room are
|
/// Previous events are always accessible to newly joined members. All events in the room are
|
||||||
/// accessible, even those sent when the member was not a part of the room.
|
/// accessible, even those sent when the member was not a part of the room.
|
||||||
#[serde(rename="shared")]
|
#[serde(rename = "shared")]
|
||||||
Shared,
|
Shared,
|
||||||
|
|
||||||
/// All events while this is the `HistoryVisibility` value may be shared by any
|
/// All events while this is the `HistoryVisibility` value may be shared by any
|
||||||
/// participating homeserver with anyone, regardless of whether they have ever joined the room.
|
/// participating homeserver with anyone, regardless of whether they have ever joined the room.
|
||||||
#[serde(rename="world_readable")]
|
#[serde(rename = "world_readable")]
|
||||||
WorldReadable,
|
WorldReadable,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,19 +17,19 @@ pub struct JoinRulesEventContent {
|
|||||||
pub enum JoinRule {
|
pub enum JoinRule {
|
||||||
/// A user who wishes to join the room must first receive an invite to the room from someone
|
/// A user who wishes to join the room must first receive an invite to the room from someone
|
||||||
/// already inside of the room.
|
/// already inside of the room.
|
||||||
#[serde(rename="invite")]
|
#[serde(rename = "invite")]
|
||||||
Invite,
|
Invite,
|
||||||
|
|
||||||
/// Reserved but not yet implemented by the Matrix specification.
|
/// Reserved but not yet implemented by the Matrix specification.
|
||||||
#[serde(rename="knock")]
|
#[serde(rename = "knock")]
|
||||||
Knock,
|
Knock,
|
||||||
|
|
||||||
/// Reserved but not yet implemented by the Matrix specification.
|
/// Reserved but not yet implemented by the Matrix specification.
|
||||||
#[serde(rename="private")]
|
#[serde(rename = "private")]
|
||||||
Private,
|
Private,
|
||||||
|
|
||||||
/// Anyone can join the room without any prior action.
|
/// Anyone can join the room without any prior action.
|
||||||
#[serde(rename="public")]
|
#[serde(rename = "public")]
|
||||||
Public,
|
Public,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,16 +31,16 @@ state_event! {
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct MemberEventContent {
|
pub struct MemberEventContent {
|
||||||
/// The avatar URL for this user.
|
/// The avatar URL for this user.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub avatar_url: Option<String>,
|
pub avatar_url: Option<String>,
|
||||||
|
|
||||||
/// The display name for this user.
|
/// The display name for this user.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub displayname: Option<String>,
|
pub displayname: Option<String>,
|
||||||
|
|
||||||
/// Flag indicating if the room containing this event was created
|
/// Flag indicating if the room containing this event was created
|
||||||
/// with the intention of being a direct chat.
|
/// with the intention of being a direct chat.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub is_direct: Option<bool>,
|
pub is_direct: Option<bool>,
|
||||||
|
|
||||||
/// The membership state of this user.
|
/// The membership state of this user.
|
||||||
@ -48,7 +48,7 @@ pub struct MemberEventContent {
|
|||||||
|
|
||||||
/// If this member event is the successor to a third party invitation, this field will contain
|
/// If this member event is the successor to a third party invitation, this field will contain
|
||||||
/// information about that invitation.
|
/// information about that invitation.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub third_party_invite: Option<ThirdPartyInvite>,
|
pub third_party_invite: Option<ThirdPartyInvite>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,23 +56,23 @@ pub struct MemberEventContent {
|
|||||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
|
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
|
||||||
pub enum MembershipState {
|
pub enum MembershipState {
|
||||||
/// The user is banned.
|
/// The user is banned.
|
||||||
#[serde(rename="ban")]
|
#[serde(rename = "ban")]
|
||||||
Ban,
|
Ban,
|
||||||
|
|
||||||
/// The user has been invited.
|
/// The user has been invited.
|
||||||
#[serde(rename="invite")]
|
#[serde(rename = "invite")]
|
||||||
Invite,
|
Invite,
|
||||||
|
|
||||||
/// The user has joined.
|
/// The user has joined.
|
||||||
#[serde(rename="join")]
|
#[serde(rename = "join")]
|
||||||
Join,
|
Join,
|
||||||
|
|
||||||
/// The user has requested to join.
|
/// The user has requested to join.
|
||||||
#[serde(rename="knock")]
|
#[serde(rename = "knock")]
|
||||||
Knock,
|
Knock,
|
||||||
|
|
||||||
/// The user has left.
|
/// The user has left.
|
||||||
#[serde(rename="leave")]
|
#[serde(rename = "leave")]
|
||||||
Leave,
|
Leave,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
//! Types for the *m.room.message* event.
|
//! Types for the *m.room.message* event.
|
||||||
|
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
|
||||||
use serde::de::Error;
|
use serde::de::Error;
|
||||||
use serde_json::{Value, from_value};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
use serde_json::{from_value, Value};
|
||||||
|
|
||||||
use super::{ImageInfo, ThumbnailInfo};
|
use super::{ImageInfo, ThumbnailInfo};
|
||||||
|
|
||||||
@ -15,35 +15,35 @@ room_event! {
|
|||||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
|
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
|
||||||
pub enum MessageType {
|
pub enum MessageType {
|
||||||
/// An audio message.
|
/// An audio message.
|
||||||
#[serde(rename="m.audio")]
|
#[serde(rename = "m.audio")]
|
||||||
Audio,
|
Audio,
|
||||||
|
|
||||||
/// An emote message.
|
/// An emote message.
|
||||||
#[serde(rename="m.emote")]
|
#[serde(rename = "m.emote")]
|
||||||
Emote,
|
Emote,
|
||||||
|
|
||||||
/// A file message.
|
/// A file message.
|
||||||
#[serde(rename="m.file")]
|
#[serde(rename = "m.file")]
|
||||||
File,
|
File,
|
||||||
|
|
||||||
/// An image message.
|
/// An image message.
|
||||||
#[serde(rename="m.image")]
|
#[serde(rename = "m.image")]
|
||||||
Image,
|
Image,
|
||||||
|
|
||||||
/// A location message.
|
/// A location message.
|
||||||
#[serde(rename="m.location")]
|
#[serde(rename = "m.location")]
|
||||||
Location,
|
Location,
|
||||||
|
|
||||||
/// A notice message.
|
/// A notice message.
|
||||||
#[serde(rename="m.notice")]
|
#[serde(rename = "m.notice")]
|
||||||
Notice,
|
Notice,
|
||||||
|
|
||||||
/// A text message.
|
/// A text message.
|
||||||
#[serde(rename="m.text")]
|
#[serde(rename = "m.text")]
|
||||||
Text,
|
Text,
|
||||||
|
|
||||||
/// A video message.
|
/// A video message.
|
||||||
#[serde(rename="m.video")]
|
#[serde(rename = "m.video")]
|
||||||
Video,
|
Video,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ pub struct AudioMessageEventContent {
|
|||||||
/// The textual representation of this message.
|
/// The textual representation of this message.
|
||||||
pub body: String,
|
pub body: String,
|
||||||
/// Metadata for the audio clip referred to in `url`.
|
/// Metadata for the audio clip referred to in `url`.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub info: Option<AudioInfo>,
|
pub info: Option<AudioInfo>,
|
||||||
/// The message type. Always *m.audio*.
|
/// The message type. Always *m.audio*.
|
||||||
pub msgtype: MessageType,
|
pub msgtype: MessageType,
|
||||||
@ -93,13 +93,13 @@ pub struct AudioMessageEventContent {
|
|||||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||||
pub struct AudioInfo {
|
pub struct AudioInfo {
|
||||||
/// The duration of the audio in milliseconds.
|
/// The duration of the audio in milliseconds.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub duration: Option<u64>,
|
pub duration: Option<u64>,
|
||||||
/// The mimetype of the audio, e.g. "audio/aac."
|
/// The mimetype of the audio, e.g. "audio/aac."
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub mimetype: Option<String>,
|
pub mimetype: Option<String>,
|
||||||
/// The size of the audio clip in bytes.
|
/// The size of the audio clip in bytes.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub size: Option<u64>,
|
pub size: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ pub struct FileMessageEventContent {
|
|||||||
/// The original filename of the uploaded file.
|
/// The original filename of the uploaded file.
|
||||||
pub filename: String,
|
pub filename: String,
|
||||||
/// Metadata about the file referred to in `url`.
|
/// Metadata about the file referred to in `url`.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub info: Option<FileInfo>,
|
pub info: Option<FileInfo>,
|
||||||
/// The message type. Always *m.file*.
|
/// The message type. Always *m.file*.
|
||||||
pub msgtype: MessageType,
|
pub msgtype: MessageType,
|
||||||
@ -137,10 +137,10 @@ pub struct FileInfo {
|
|||||||
/// The size of the file in bytes.
|
/// The size of the file in bytes.
|
||||||
pub size: u64,
|
pub size: u64,
|
||||||
/// Metadata about the image referred to in `thumbnail_url`.
|
/// Metadata about the image referred to in `thumbnail_url`.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub thumbnail_info: Option<ThumbnailInfo>,
|
pub thumbnail_info: Option<ThumbnailInfo>,
|
||||||
/// The URL to the thumbnail of the file.
|
/// The URL to the thumbnail of the file.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub thumbnail_url: Option<String>,
|
pub thumbnail_url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ pub struct ImageMessageEventContent {
|
|||||||
/// of the image, or some kind of content description for accessibility e.g. "image attachment."
|
/// of the image, or some kind of content description for accessibility e.g. "image attachment."
|
||||||
pub body: String,
|
pub body: String,
|
||||||
/// Metadata about the image referred to in `url`.
|
/// Metadata about the image referred to in `url`.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub info: Option<ImageInfo>,
|
pub info: Option<ImageInfo>,
|
||||||
/// The message type. Always *m.image*.
|
/// The message type. Always *m.image*.
|
||||||
pub msgtype: MessageType,
|
pub msgtype: MessageType,
|
||||||
@ -170,7 +170,7 @@ pub struct LocationMessageEventContent {
|
|||||||
/// The message type. Always *m.location*.
|
/// The message type. Always *m.location*.
|
||||||
pub msgtype: MessageType,
|
pub msgtype: MessageType,
|
||||||
/// Info about the location being represented.
|
/// Info about the location being represented.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub info: Option<LocationInfo>,
|
pub info: Option<LocationInfo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,10 +178,10 @@ pub struct LocationMessageEventContent {
|
|||||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||||
pub struct LocationInfo {
|
pub struct LocationInfo {
|
||||||
/// Metadata about the image referred to in `thumbnail_url`.
|
/// Metadata about the image referred to in `thumbnail_url`.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub thumbnail_info: Option<ThumbnailInfo>,
|
pub thumbnail_info: Option<ThumbnailInfo>,
|
||||||
/// The URL to a thumbnail of the location being represented.
|
/// The URL to a thumbnail of the location being represented.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub thumbnail_url: Option<String>,
|
pub thumbnail_url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ pub struct VideoMessageEventContent {
|
|||||||
/// accessibility, e.g. "video attachment."
|
/// accessibility, e.g. "video attachment."
|
||||||
pub body: String,
|
pub body: String,
|
||||||
/// Metadata about the video clip referred to in `url`.
|
/// Metadata about the video clip referred to in `url`.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub info: Option<VideoInfo>,
|
pub info: Option<VideoInfo>,
|
||||||
/// The message type. Always *m.video*.
|
/// The message type. Always *m.video*.
|
||||||
pub msgtype: MessageType,
|
pub msgtype: MessageType,
|
||||||
@ -222,27 +222,27 @@ pub struct VideoMessageEventContent {
|
|||||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||||
pub struct VideoInfo {
|
pub struct VideoInfo {
|
||||||
/// The duration of the video in milliseconds.
|
/// The duration of the video in milliseconds.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub duration: Option<u64>,
|
pub duration: Option<u64>,
|
||||||
/// The height of the video in pixels.
|
/// The height of the video in pixels.
|
||||||
#[serde(rename = "h")]
|
#[serde(rename = "h")]
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub height: Option<u64>,
|
pub height: Option<u64>,
|
||||||
/// The mimetype of the video, e.g. "video/mp4."
|
/// The mimetype of the video, e.g. "video/mp4."
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub mimetype: Option<String>,
|
pub mimetype: Option<String>,
|
||||||
/// The size of the video in bytes.
|
/// The size of the video in bytes.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub size: Option<u64>,
|
pub size: Option<u64>,
|
||||||
/// Metadata about an image.
|
/// Metadata about an image.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub thumbnail_info: Option<ThumbnailInfo>,
|
pub thumbnail_info: Option<ThumbnailInfo>,
|
||||||
/// The URL to a thumbnail of the video clip.
|
/// The URL to a thumbnail of the video clip.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub thumbnail_url: Option<String>,
|
pub thumbnail_url: Option<String>,
|
||||||
/// The width of the video in pixels.
|
/// The width of the video in pixels.
|
||||||
#[serde(rename = "w")]
|
#[serde(rename = "w")]
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub width: Option<u64>,
|
pub width: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,7 +260,10 @@ impl_enum! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Serialize for MessageEventContent {
|
impl Serialize for MessageEventContent {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
match *self {
|
match *self {
|
||||||
MessageEventContent::Audio(ref content) => content.serialize(serializer),
|
MessageEventContent::Audio(ref content) => content.serialize(serializer),
|
||||||
MessageEventContent::Emote(ref content) => content.serialize(serializer),
|
MessageEventContent::Emote(ref content) => content.serialize(serializer),
|
||||||
@ -275,7 +278,10 @@ impl Serialize for MessageEventContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for MessageEventContent {
|
impl<'de> Deserialize<'de> for MessageEventContent {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<'de> {
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
let value: Value = Deserialize::deserialize(deserializer)?;
|
let value: Value = Deserialize::deserialize(deserializer)?;
|
||||||
|
|
||||||
let message_type_value = match value.get("msgtype") {
|
let message_type_value = match value.get("msgtype") {
|
||||||
@ -361,18 +367,16 @@ impl<'de> Deserialize<'de> for MessageEventContent {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use serde_json::{from_str, to_string};
|
use serde_json::{from_str, to_string};
|
||||||
|
|
||||||
use super::{AudioMessageEventContent, MessageType, MessageEventContent};
|
use super::{AudioMessageEventContent, MessageEventContent, MessageType};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialization() {
|
fn serialization() {
|
||||||
let message_event_content = MessageEventContent::Audio(
|
let message_event_content = MessageEventContent::Audio(AudioMessageEventContent {
|
||||||
AudioMessageEventContent {
|
body: "test".to_string(),
|
||||||
body: "test".to_string(),
|
info: None,
|
||||||
info: None,
|
msgtype: MessageType::Audio,
|
||||||
msgtype: MessageType::Audio,
|
url: "http://example.com/audio.mp3".to_string(),
|
||||||
url: "http://example.com/audio.mp3".to_string(),
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
to_string(&message_event_content).unwrap(),
|
to_string(&message_event_content).unwrap(),
|
||||||
@ -382,14 +386,12 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialization() {
|
fn deserialization() {
|
||||||
let message_event_content = MessageEventContent::Audio(
|
let message_event_content = MessageEventContent::Audio(AudioMessageEventContent {
|
||||||
AudioMessageEventContent {
|
body: "test".to_string(),
|
||||||
body: "test".to_string(),
|
info: None,
|
||||||
info: None,
|
msgtype: MessageType::Audio,
|
||||||
msgtype: MessageType::Audio,
|
url: "http://example.com/audio.mp3".to_string(),
|
||||||
url: "http://example.com/audio.mp3".to_string(),
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
from_str::<MessageEventContent>(
|
from_str::<MessageEventContent>(
|
||||||
|
@ -22,20 +22,20 @@ pub mod topic;
|
|||||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||||
pub struct ImageInfo {
|
pub struct ImageInfo {
|
||||||
/// The height of the image in pixels.
|
/// The height of the image in pixels.
|
||||||
#[serde(rename="h")]
|
#[serde(rename = "h")]
|
||||||
pub height: u64,
|
pub height: u64,
|
||||||
/// The MIME type of the image, e.g. "image/png."
|
/// The MIME type of the image, e.g. "image/png."
|
||||||
pub mimetype: String,
|
pub mimetype: String,
|
||||||
/// The file size of the image in bytes.
|
/// The file size of the image in bytes.
|
||||||
pub size: u64,
|
pub size: u64,
|
||||||
/// Metadata about the image referred to in `thumbnail_url`.
|
/// Metadata about the image referred to in `thumbnail_url`.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub thumbnail_info: Option<ThumbnailInfo>,
|
pub thumbnail_info: Option<ThumbnailInfo>,
|
||||||
/// The URL to the thumbnail of the image.
|
/// The URL to the thumbnail of the image.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub thumbnail_url: Option<String>,
|
pub thumbnail_url: Option<String>,
|
||||||
/// The width of the image in pixels.
|
/// The width of the image in pixels.
|
||||||
#[serde(rename="w")]
|
#[serde(rename = "w")]
|
||||||
pub width: u64,
|
pub width: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,13 +43,13 @@ pub struct ImageInfo {
|
|||||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||||
pub struct ThumbnailInfo {
|
pub struct ThumbnailInfo {
|
||||||
/// The height of the thumbnail in pixels.
|
/// The height of the thumbnail in pixels.
|
||||||
#[serde(rename="h")]
|
#[serde(rename = "h")]
|
||||||
pub height: u64,
|
pub height: u64,
|
||||||
/// The MIME type of the thumbnail, e.g. "image/png."
|
/// The MIME type of the thumbnail, e.g. "image/png."
|
||||||
pub mimetype: String,
|
pub mimetype: String,
|
||||||
/// The file size of the thumbnail in bytes.
|
/// The file size of the thumbnail in bytes.
|
||||||
pub size: u64,
|
pub size: u64,
|
||||||
/// The width of the thumbnail in pixels.
|
/// The width of the thumbnail in pixels.
|
||||||
#[serde(rename="w")]
|
#[serde(rename = "w")]
|
||||||
pub width: u64,
|
pub width: u64,
|
||||||
}
|
}
|
||||||
|
@ -19,17 +19,15 @@ 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 Event;
|
use Event;
|
||||||
use EventType;
|
use EventType;
|
||||||
use RoomEvent;
|
use RoomEvent;
|
||||||
use StateEvent;
|
use StateEvent;
|
||||||
use room::pinned_events::{PinnedEventsEvent, PinnedEventsContent};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialization_deserialization() {
|
fn serialization_deserialization() {
|
||||||
let mut content: PinnedEventsContent = PinnedEventsContent {
|
let mut content: PinnedEventsContent = PinnedEventsContent { pinned: Vec::new() };
|
||||||
pinned: Vec::new()
|
|
||||||
};
|
|
||||||
|
|
||||||
content.pinned.push(EventId::new("example.com").unwrap());
|
content.pinned.push(EventId::new("example.com").unwrap());
|
||||||
content.pinned.push(EventId::new("example.com").unwrap());
|
content.pinned.push(EventId::new("example.com").unwrap());
|
||||||
|
@ -15,7 +15,7 @@ state_event! {
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct PowerLevelsEventContent {
|
pub struct PowerLevelsEventContent {
|
||||||
/// The level required to ban a user.
|
/// The level required to ban a user.
|
||||||
#[serde(default="default_power_level")]
|
#[serde(default = "default_power_level")]
|
||||||
pub ban: u64,
|
pub ban: u64,
|
||||||
|
|
||||||
/// The level required to send specific event types.
|
/// The level required to send specific event types.
|
||||||
@ -28,19 +28,19 @@ pub struct PowerLevelsEventContent {
|
|||||||
pub events_default: u64,
|
pub events_default: u64,
|
||||||
|
|
||||||
/// The level required to invite a user.
|
/// The level required to invite a user.
|
||||||
#[serde(default="default_power_level")]
|
#[serde(default = "default_power_level")]
|
||||||
pub invite: u64,
|
pub invite: u64,
|
||||||
|
|
||||||
/// The level required to kick a user.
|
/// The level required to kick a user.
|
||||||
#[serde(default="default_power_level")]
|
#[serde(default = "default_power_level")]
|
||||||
pub kick: u64,
|
pub kick: u64,
|
||||||
|
|
||||||
/// The level required to redact an event.
|
/// The level required to redact an event.
|
||||||
#[serde(default="default_power_level")]
|
#[serde(default = "default_power_level")]
|
||||||
pub redact: u64,
|
pub redact: u64,
|
||||||
|
|
||||||
/// The default level required to send state events.
|
/// The default level required to send state events.
|
||||||
#[serde(default="default_power_level")]
|
#[serde(default = "default_power_level")]
|
||||||
pub state_default: u64,
|
pub state_default: u64,
|
||||||
|
|
||||||
/// The power levels for specific users.
|
/// The power levels for specific users.
|
||||||
|
@ -14,6 +14,6 @@ room_event! {
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct RedactionEventContent {
|
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>,
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ pub struct ThirdPartyInviteEventContent {
|
|||||||
pub public_key: String,
|
pub public_key: String,
|
||||||
|
|
||||||
/// Keys with which the token may be signed.
|
/// Keys with which the token may be signed.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub public_keys: Option<Vec<PublicKey>>,
|
pub public_keys: Option<Vec<PublicKey>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ pub struct PublicKey {
|
|||||||
///
|
///
|
||||||
/// The URL must return a JSON object containing a boolean property named 'valid'.
|
/// The URL must return a JSON object containing a boolean property named 'valid'.
|
||||||
/// If this URL is absent, the key must be considered valid indefinitely.
|
/// If this URL is absent, the key must be considered valid indefinitely.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub key_validity_url: Option<String>,
|
pub key_validity_url: Option<String>,
|
||||||
|
|
||||||
/// A Base64-encoded Ed25519 key with which the token must be signed.
|
/// A Base64-encoded Ed25519 key with which the token must be signed.
|
||||||
|
@ -5,11 +5,10 @@
|
|||||||
//! state event to be created, when the other fields can be inferred from a larger context, or where
|
//! state event to be created, when the other fields can be inferred from a larger context, or where
|
||||||
//! the other fields are otherwise inapplicable.
|
//! the other fields are otherwise inapplicable.
|
||||||
|
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
|
||||||
use serde::de::Error;
|
use serde::de::Error;
|
||||||
use serde_json::{Value, from_value};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
use serde_json::{from_value, Value};
|
||||||
|
|
||||||
use EventType;
|
|
||||||
use room::aliases::AliasesEventContent;
|
use room::aliases::AliasesEventContent;
|
||||||
use room::avatar::AvatarEventContent;
|
use room::avatar::AvatarEventContent;
|
||||||
use room::canonical_alias::CanonicalAliasEventContent;
|
use room::canonical_alias::CanonicalAliasEventContent;
|
||||||
@ -22,6 +21,7 @@ use room::name::NameEventContent;
|
|||||||
use room::power_levels::PowerLevelsEventContent;
|
use room::power_levels::PowerLevelsEventContent;
|
||||||
use room::third_party_invite::ThirdPartyInviteEventContent;
|
use room::third_party_invite::ThirdPartyInviteEventContent;
|
||||||
use room::topic::TopicEventContent;
|
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)]
|
||||||
@ -69,14 +69,17 @@ pub struct StrippedStateContent<C> {
|
|||||||
/// Data specific to the event type.
|
/// Data specific to the event type.
|
||||||
pub content: C,
|
pub content: C,
|
||||||
/// The type of the event.
|
/// The type of the event.
|
||||||
#[serde(rename="type")]
|
#[serde(rename = "type")]
|
||||||
pub event_type: EventType,
|
pub event_type: EventType,
|
||||||
/// A key that determines which piece of room state the event represents.
|
/// A key that determines which piece of room state the event represents.
|
||||||
pub state_key: String,
|
pub state_key: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Serialize for StrippedState {
|
impl Serialize for StrippedState {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
match *self {
|
match *self {
|
||||||
StrippedState::RoomAliases(ref event) => event.serialize(serializer),
|
StrippedState::RoomAliases(ref event) => event.serialize(serializer),
|
||||||
StrippedState::RoomAvatar(ref event) => event.serialize(serializer),
|
StrippedState::RoomAvatar(ref event) => event.serialize(serializer),
|
||||||
@ -95,7 +98,10 @@ impl Serialize for StrippedState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for StrippedState {
|
impl<'de> Deserialize<'de> for StrippedState {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<'de> {
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
let value: Value = Deserialize::deserialize(deserializer)?;
|
let value: Value = Deserialize::deserialize(deserializer)?;
|
||||||
|
|
||||||
let event_type_value = match value.get("type") {
|
let event_type_value = match value.get("type") {
|
||||||
@ -116,7 +122,7 @@ impl<'de> Deserialize<'de> for StrippedState {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(StrippedState::RoomAliases(event))
|
Ok(StrippedState::RoomAliases(event))
|
||||||
},
|
}
|
||||||
EventType::RoomAvatar => {
|
EventType::RoomAvatar => {
|
||||||
let event = match from_value::<StrippedRoomAvatar>(value) {
|
let event = match from_value::<StrippedRoomAvatar>(value) {
|
||||||
Ok(event) => event,
|
Ok(event) => event,
|
||||||
@ -124,7 +130,7 @@ impl<'de> Deserialize<'de> for StrippedState {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(StrippedState::RoomAvatar(event))
|
Ok(StrippedState::RoomAvatar(event))
|
||||||
},
|
}
|
||||||
EventType::RoomCanonicalAlias => {
|
EventType::RoomCanonicalAlias => {
|
||||||
let event = match from_value::<StrippedRoomCanonicalAlias>(value) {
|
let event = match from_value::<StrippedRoomCanonicalAlias>(value) {
|
||||||
Ok(event) => event,
|
Ok(event) => event,
|
||||||
@ -132,7 +138,7 @@ impl<'de> Deserialize<'de> for StrippedState {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(StrippedState::RoomCanonicalAlias(event))
|
Ok(StrippedState::RoomCanonicalAlias(event))
|
||||||
},
|
}
|
||||||
EventType::RoomCreate => {
|
EventType::RoomCreate => {
|
||||||
let event = match from_value::<StrippedRoomCreate>(value) {
|
let event = match from_value::<StrippedRoomCreate>(value) {
|
||||||
Ok(event) => event,
|
Ok(event) => event,
|
||||||
@ -140,7 +146,7 @@ impl<'de> Deserialize<'de> for StrippedState {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(StrippedState::RoomCreate(event))
|
Ok(StrippedState::RoomCreate(event))
|
||||||
},
|
}
|
||||||
EventType::RoomGuestAccess => {
|
EventType::RoomGuestAccess => {
|
||||||
let event = match from_value::<StrippedRoomGuestAccess>(value) {
|
let event = match from_value::<StrippedRoomGuestAccess>(value) {
|
||||||
Ok(event) => event,
|
Ok(event) => event,
|
||||||
@ -148,7 +154,7 @@ impl<'de> Deserialize<'de> for StrippedState {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(StrippedState::RoomGuestAccess(event))
|
Ok(StrippedState::RoomGuestAccess(event))
|
||||||
},
|
}
|
||||||
EventType::RoomHistoryVisibility => {
|
EventType::RoomHistoryVisibility => {
|
||||||
let event = match from_value::<StrippedRoomHistoryVisibility>(value) {
|
let event = match from_value::<StrippedRoomHistoryVisibility>(value) {
|
||||||
Ok(event) => event,
|
Ok(event) => event,
|
||||||
@ -156,7 +162,7 @@ impl<'de> Deserialize<'de> for StrippedState {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(StrippedState::RoomHistoryVisibility(event))
|
Ok(StrippedState::RoomHistoryVisibility(event))
|
||||||
},
|
}
|
||||||
EventType::RoomJoinRules => {
|
EventType::RoomJoinRules => {
|
||||||
let event = match from_value::<StrippedRoomJoinRules>(value) {
|
let event = match from_value::<StrippedRoomJoinRules>(value) {
|
||||||
Ok(event) => event,
|
Ok(event) => event,
|
||||||
@ -164,7 +170,7 @@ impl<'de> Deserialize<'de> for StrippedState {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(StrippedState::RoomJoinRules(event))
|
Ok(StrippedState::RoomJoinRules(event))
|
||||||
},
|
}
|
||||||
EventType::RoomMember => {
|
EventType::RoomMember => {
|
||||||
let event = match from_value::<StrippedRoomMember>(value) {
|
let event = match from_value::<StrippedRoomMember>(value) {
|
||||||
Ok(event) => event,
|
Ok(event) => event,
|
||||||
@ -172,7 +178,7 @@ impl<'de> Deserialize<'de> for StrippedState {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(StrippedState::RoomMember(event))
|
Ok(StrippedState::RoomMember(event))
|
||||||
},
|
}
|
||||||
EventType::RoomName => {
|
EventType::RoomName => {
|
||||||
let event = match from_value::<StrippedRoomName>(value) {
|
let event = match from_value::<StrippedRoomName>(value) {
|
||||||
Ok(event) => event,
|
Ok(event) => event,
|
||||||
@ -180,7 +186,7 @@ impl<'de> Deserialize<'de> for StrippedState {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(StrippedState::RoomName(event))
|
Ok(StrippedState::RoomName(event))
|
||||||
},
|
}
|
||||||
EventType::RoomPowerLevels => {
|
EventType::RoomPowerLevels => {
|
||||||
let event = match from_value::<StrippedRoomPowerLevels>(value) {
|
let event = match from_value::<StrippedRoomPowerLevels>(value) {
|
||||||
Ok(event) => event,
|
Ok(event) => event,
|
||||||
@ -188,7 +194,7 @@ impl<'de> Deserialize<'de> for StrippedState {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(StrippedState::RoomPowerLevels(event))
|
Ok(StrippedState::RoomPowerLevels(event))
|
||||||
},
|
}
|
||||||
EventType::RoomThirdPartyInvite => {
|
EventType::RoomThirdPartyInvite => {
|
||||||
let event = match from_value::<StrippedRoomThirdPartyInvite>(value) {
|
let event = match from_value::<StrippedRoomThirdPartyInvite>(value) {
|
||||||
Ok(event) => event,
|
Ok(event) => event,
|
||||||
@ -196,7 +202,7 @@ impl<'de> Deserialize<'de> for StrippedState {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(StrippedState::RoomThirdPartyInvite(event))
|
Ok(StrippedState::RoomThirdPartyInvite(event))
|
||||||
},
|
}
|
||||||
EventType::RoomTopic => {
|
EventType::RoomTopic => {
|
||||||
let event = match from_value::<StrippedRoomTopic>(value) {
|
let event = match from_value::<StrippedRoomTopic>(value) {
|
||||||
Ok(event) => event,
|
Ok(event) => event,
|
||||||
@ -204,7 +210,7 @@ impl<'de> Deserialize<'de> for StrippedState {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(StrippedState::RoomTopic(event))
|
Ok(StrippedState::RoomTopic(event))
|
||||||
},
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(D::Error::custom("not a state event".to_string()));
|
return Err(D::Error::custom("not a state event".to_string()));
|
||||||
}
|
}
|
||||||
@ -250,18 +256,20 @@ pub type StrippedRoomTopic = StrippedStateContent<TopicEventContent>;
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use EventType;
|
use super::{StrippedRoomTopic, StrippedState};
|
||||||
use room::join_rules::JoinRule;
|
use room::join_rules::JoinRule;
|
||||||
use room::topic::TopicEventContent;
|
use room::topic::TopicEventContent;
|
||||||
use serde_json::{from_str, to_string};
|
use serde_json::{from_str, to_string};
|
||||||
use super::{StrippedRoomTopic, StrippedState};
|
use EventType;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialize_stripped_state_event() {
|
fn serialize_stripped_state_event() {
|
||||||
let content = StrippedRoomTopic {
|
let content = StrippedRoomTopic {
|
||||||
content: TopicEventContent { topic: "Testing room".to_string() },
|
content: TopicEventContent {
|
||||||
|
topic: "Testing room".to_string(),
|
||||||
|
},
|
||||||
state_key: "".to_string(),
|
state_key: "".to_string(),
|
||||||
event_type: EventType::RoomTopic
|
event_type: EventType::RoomTopic,
|
||||||
};
|
};
|
||||||
|
|
||||||
let event = StrippedState::RoomTopic(content);
|
let event = StrippedState::RoomTopic(content);
|
||||||
@ -319,7 +327,7 @@ mod tests {
|
|||||||
assert_eq!(event.content.name, "Ruma");
|
assert_eq!(event.content.name, "Ruma");
|
||||||
assert_eq!(event.event_type, EventType::RoomName);
|
assert_eq!(event.event_type, EventType::RoomName);
|
||||||
assert_eq!(event.state_key, "");
|
assert_eq!(event.state_key, "");
|
||||||
},
|
}
|
||||||
_ => {
|
_ => {
|
||||||
assert!(false);
|
assert!(false);
|
||||||
}
|
}
|
||||||
@ -330,7 +338,7 @@ mod tests {
|
|||||||
assert_eq!(event.content.join_rule, JoinRule::Public);
|
assert_eq!(event.content.join_rule, JoinRule::Public);
|
||||||
assert_eq!(event.event_type, EventType::RoomJoinRules);
|
assert_eq!(event.event_type, EventType::RoomJoinRules);
|
||||||
assert_eq!(event.state_key, "");
|
assert_eq!(event.state_key, "");
|
||||||
},
|
}
|
||||||
_ => {
|
_ => {
|
||||||
assert!(false);
|
assert!(false);
|
||||||
}
|
}
|
||||||
@ -348,7 +356,7 @@ mod tests {
|
|||||||
assert_eq!(event.content.url, "https://domain.com/image.jpg");
|
assert_eq!(event.content.url, "https://domain.com/image.jpg");
|
||||||
assert_eq!(event.event_type, EventType::RoomAvatar);
|
assert_eq!(event.event_type, EventType::RoomAvatar);
|
||||||
assert_eq!(event.state_key, "");
|
assert_eq!(event.state_key, "");
|
||||||
},
|
}
|
||||||
_ => {
|
_ => {
|
||||||
assert!(false);
|
assert!(false);
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,6 @@ pub struct TagEventContent {
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct TagInfo {
|
pub struct TagInfo {
|
||||||
/// Value to use for lexicographically ordering rooms with this tag.
|
/// Value to use for lexicographically ordering rooms with this tag.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub order: Option<String>,
|
pub order: Option<String>,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user