diff --git a/src/call/answer.rs b/src/call/answer.rs index a41ba314..7ec22242 100644 --- a/src/call/answer.rs +++ b/src/call/answer.rs @@ -10,7 +10,7 @@ room_event! { /// The payload of an `AnswerEvent`. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct AnswerEventContent { - /// The VoIP session description. + /// The VoIP session description object. The session description type must be *answer*. pub answer: SessionDescription, /// The ID of the call this event relates to. pub call_id: String, diff --git a/src/call/invite.rs b/src/call/invite.rs index e6662c7b..5493a836 100644 --- a/src/call/invite.rs +++ b/src/call/invite.rs @@ -16,7 +16,7 @@ pub struct InviteEventContent { /// value, clients should discard it. They should also no longer show the call as awaiting an /// answer in the UI. pub lifetime: u64, - /// The session description object. + /// The session description object. The session description type must be *offer*. pub offer: SessionDescription, /// The version of the VoIP specification this messages adheres to. pub version: u64, diff --git a/src/lib.rs b/src/lib.rs index 3dbb6501..73261d63 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -192,12 +192,6 @@ pub trait Event where Self: Debug + for<'a> Deserialize<'a> + Serialize { /// The type of the event. fn event_type(&self) -> &EventType; - - /// Extra top-level key-value pairs specific to this event type, but that are not under the - /// `content` field. - fn extra_content(&self) -> Option { - None - } } /// An event within the context of a room. @@ -205,14 +199,17 @@ pub trait RoomEvent: Event { /// The unique identifier for the event. fn event_id(&self) -> &EventId; + /// Timestamp in milliseconds on originating homeserver when this event was sent. + fn origin_server_ts(&self) -> u64; + /// The unique identifier for the room associated with this event. fn room_id(&self) -> &RoomId; + /// The unique identifier for the user who sent this event. + fn sender(&self) -> &UserId; + /// Additional key-value pairs not signed by the homeserver. fn unsigned(&self) -> Option<&Value>; - - /// The unique identifier for the user associated with this event. - fn user_id(&self) -> &UserId; } /// An event that describes persistent state about a room. diff --git a/src/macros.rs b/src/macros.rs index 9c7c9f6a..bf182b3a 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -90,6 +90,9 @@ macro_rules! room_event { #[serde(rename="type")] pub event_type: $crate::EventType, + /// Timestamp in milliseconds on originating homeserver when this event was sent. + pub origin_server_ts: u64, + /// The unique identifier for the room associated with this event. pub room_id: ::ruma_identifiers::RoomId, @@ -97,9 +100,8 @@ macro_rules! room_event { #[serde(skip_serializing_if="Option::is_none")] pub unsigned: Option<::serde_json::Value>, - /// The unique identifier for the user associated with this event. - #[serde(rename="sender")] - pub user_id: ::ruma_identifiers::UserId, + /// The unique identifier for the user who sent this event. + pub sender: ::ruma_identifiers::UserId, $( $(#[$field_attr])* @@ -120,6 +122,10 @@ macro_rules! impl_room_event { &self.event_id } + fn origin_server_ts(&self) -> u64 { + self.origin_server_ts + } + fn room_id(&self) -> &::ruma_identifiers::RoomId { &self.room_id } @@ -128,8 +134,8 @@ macro_rules! impl_room_event { self.unsigned.as_ref() } - fn user_id(&self) -> &::ruma_identifiers::UserId { - &self.user_id + fn sender(&self) -> &::ruma_identifiers::UserId { + &self.sender } } } @@ -158,6 +164,9 @@ macro_rules! state_event { #[serde(rename="type")] pub event_type: $crate::EventType, + /// Timestamp in milliseconds on originating homeserver when this event was sent. + pub origin_server_ts: u64, + /// The previous content for this state key, if any. #[serde(skip_serializing_if="Option::is_none")] pub prev_content: Option<$content_type>, @@ -173,8 +182,7 @@ macro_rules! state_event { pub unsigned: Option<::serde_json::Value>, /// The unique identifier for the user associated with this event. - #[serde(rename="sender")] - pub user_id: ::ruma_identifiers::UserId, + pub sender: ::ruma_identifiers::UserId, $( $(#[$field_attr])* diff --git a/src/presence.rs b/src/presence.rs index 5ed4001f..ac905c8e 100644 --- a/src/presence.rs +++ b/src/presence.rs @@ -25,7 +25,7 @@ pub struct PresenceEventContent { #[serde(skip_serializing_if="Option::is_none")] pub displayname: Option, - /// The last time since this used performed some action, in milliseconds. + /// The last time since this user performed some action, in milliseconds. #[serde(skip_serializing_if="Option::is_none")] pub last_active_ago: Option, diff --git a/src/room/create.rs b/src/room/create.rs index c9fc5fe1..0e073241 100644 --- a/src/room/create.rs +++ b/src/room/create.rs @@ -14,5 +14,6 @@ pub struct CreateEventContent { /// The `user_id` of the room creator. This is set by the homeserver. pub creator: UserId, /// Whether or not this room's data should be transferred to other homeservers. + #[serde(rename="m.federate")] pub federate: Option, } diff --git a/src/room/member.rs b/src/room/member.rs index ff6c0219..95aec702 100644 --- a/src/room/member.rs +++ b/src/room/member.rs @@ -38,6 +38,11 @@ pub struct MemberEventContent { #[serde(skip_serializing_if="Option::is_none")] pub displayname: Option, + /// Flag indicating if the room containing this event was created + /// with the intention of being a direct chat. + #[serde(skip_serializing_if="Option::is_none")] + pub is_direct: Option, + /// The membership state of this user. pub membership: MembershipState, diff --git a/src/room/message.rs b/src/room/message.rs index 487ff2f3..b6ff3d07 100644 --- a/src/room/message.rs +++ b/src/room/message.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde::de::Error; use serde_json::{Value, from_value}; -use super::ImageInfo; +use super::{ImageInfo, ThumbnailInfo}; room_event! { /// A message sent to a room. @@ -118,17 +118,13 @@ pub struct FileMessageEventContent { /// A human-readable description of the file. This is recommended to be the filename of the /// original upload. pub body: String, + /// The original filename of the uploaded file. + pub filename: String, /// Metadata about the file referred to in `url`. #[serde(skip_serializing_if="Option::is_none")] pub info: Option, /// The message type. Always *m.file*. pub msgtype: MessageType, - /// Metadata about the image referred to in `thumbnail_url`. - #[serde(skip_serializing_if="Option::is_none")] - pub thumbnail_info: Option, - /// The URL to the thumbnail of the file. - #[serde(skip_serializing_if="Option::is_none")] - pub thumbnail_url: Option, /// The URL to the file. pub url: String, } @@ -140,6 +136,12 @@ pub struct FileInfo { pub mimetype: String, /// The size of the file in bytes. pub size: u64, + /// Metadata about the image referred to in `thumbnail_url`. + #[serde(skip_serializing_if="Option::is_none")] + pub thumbnail_info: Option, + /// The URL to the thumbnail of the file. + #[serde(skip_serializing_if="Option::is_none")] + pub thumbnail_url: Option, } /// The payload of an image message. @@ -153,12 +155,6 @@ pub struct ImageMessageEventContent { pub info: Option, /// The message type. Always *m.image*. pub msgtype: MessageType, - /// Metadata about the image referred to in `thumbnail_url`. - #[serde(skip_serializing_if="Option::is_none")] - pub thumbnail_info: Option, - /// The URL to the thumbnail of the image. - #[serde(skip_serializing_if="Option::is_none")] - pub thumbnail_url: Option, /// The URL to the image. pub url: String, } @@ -173,9 +169,17 @@ pub struct LocationMessageEventContent { pub geo_uri: String, /// The message type. Always *m.location*. pub msgtype: MessageType, + /// Info about the location being represented. + #[serde(skip_serializing_if="Option::is_none")] + pub info: Option, +} + +/// Thumbnail info associated with a location. +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct LocationInfo { /// Metadata about the image referred to in `thumbnail_url`. #[serde(skip_serializing_if="Option::is_none")] - pub thumbnail_info: Option, + pub thumbnail_info: Option, /// The URL to a thumbnail of the location being represented. #[serde(skip_serializing_if="Option::is_none")] pub thumbnail_url: Option, @@ -232,7 +236,7 @@ pub struct VideoInfo { pub size: Option, /// Metadata about an image. #[serde(skip_serializing_if="Option::is_none")] - pub thumbnail_info: Option, + pub thumbnail_info: Option, /// The URL to a thumbnail of the video clip. #[serde(skip_serializing_if="Option::is_none")] pub thumbnail_url: Option, diff --git a/src/room/mod.rs b/src/room/mod.rs index 232f7556..f54e6436 100644 --- a/src/room/mod.rs +++ b/src/room/mod.rs @@ -21,13 +21,34 @@ pub mod topic; #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] pub struct ImageInfo { /// The height of the image in pixels. - #[serde(rename = "h")] + #[serde(rename="h")] pub height: u64, /// The MIME type of the image, e.g. "image/png." pub mimetype: String, /// The file size of the image in bytes. pub size: u64, + /// Metadata about the image referred to in `thumbnail_url`. + #[serde(skip_serializing_if="Option::is_none")] + pub thumbnail_info: Option, + /// The URL to the thumbnail of the image. + #[serde(skip_serializing_if="Option::is_none")] + pub thumbnail_url: Option, /// The width of the image in pixels. - #[serde(rename = "w")] + #[serde(rename="w")] + pub width: u64, +} + +/// Metadata about a thumbnail. +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct ThumbnailInfo { + /// The height of the thumbnail in pixels. + #[serde(rename="h")] + pub height: u64, + /// The MIME type of the thumbnail, e.g. "image/png." + pub mimetype: String, + /// The file size of the thumbnail in bytes. + pub size: u64, + /// The width of the thumbnail in pixels. + #[serde(rename="w")] pub width: u64, } diff --git a/src/stripped.rs b/src/stripped.rs index 28d50500..60181cf6 100644 --- a/src/stripped.rs +++ b/src/stripped.rs @@ -294,7 +294,14 @@ mod tests { "h": 128, "w": 128, "mimetype": "image/jpeg", - "size": 1024 + "size": 1024, + "thumbnail_info": { + "h": 16, + "w": 16, + "mimetype": "image/jpeg", + "size": 32 + }, + "thumbnail_url": "https://domain.com/image-thumbnail.jpg" }, "thumbnail_info": { "h": 16, diff --git a/src/typing.rs b/src/typing.rs index d5bdd22a..6ba07abd 100644 --- a/src/typing.rs +++ b/src/typing.rs @@ -1,6 +1,6 @@ //! Types for the *m.typing* event. -use ruma_identifiers::{EventId, RoomId}; +use ruma_identifiers::{RoomId, UserId}; event! { /// Informs the client of the list of users currently typing. @@ -14,5 +14,5 @@ event! { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct TypingEventContent { /// The list of user IDs typing in this room, if any. - pub user_ids: Vec, + pub user_ids: Vec, }