diff --git a/Cargo.toml b/Cargo.toml index 5052e4a0..92561c73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ edition = "2018" [dependencies] js_int = { version = "0.1.2", features = ["serde"] } -ruma-api = "0.11.2" +ruma-api = "0.12.0-alpha.1" ruma-events = "0.15.1" ruma-identifiers = "0.14.0" serde = { version = "1.0.102", features = ["derive"] } diff --git a/src/r0/context/get_context.rs b/src/r0/context/get_context.rs index e518dfd6..566ac742 100644 --- a/src/r0/context/get_context.rs +++ b/src/r0/context/get_context.rs @@ -32,16 +32,20 @@ ruma_api! { /// A token that can be used to paginate forwards with. pub end: String, /// Details of the requested event. - pub event: EventResult, + #[wrap_incoming(with EventResult)] + pub event: only::RoomEvent, /// A list of room events that happened just after the requested event, in chronological /// order. - pub events_after: Vec>, + #[wrap_incoming(only::RoomEvent with EventResult)] + pub events_after: Vec, /// A list of room events that happened just before the requested event, in /// reverse-chronological order. - pub events_before: Vec>, + #[wrap_incoming(only::RoomEvent with EventResult)] + pub events_before: Vec, /// A token that can be used to paginate backwards with. pub start: String, /// The state of the room at the last event returned. - pub state: Vec>, + #[wrap_incoming(only::StateEvent with EventResult)] + pub state: Vec, } } diff --git a/src/r0/presence/get_subscribed_presences.rs b/src/r0/presence/get_subscribed_presences.rs index 656b1c8a..fc581989 100644 --- a/src/r0/presence/get_subscribed_presences.rs +++ b/src/r0/presence/get_subscribed_presences.rs @@ -23,6 +23,7 @@ ruma_api! { response { /// A list of presence events for every user on this list. #[ruma_api(body)] - pub presence_events: Vec>, + #[wrap_incoming(PresenceEvent with EventResult)] + pub presence_events: Vec, } } diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs index c235dee4..e9b74a9f 100644 --- a/src/r0/search/search_events.rs +++ b/src/r0/search/search_events.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use js_int::UInt; -use ruma_api::ruma_api; +use ruma_api::{ruma_api, Outgoing}; use ruma_events::{collections::all::Event, EventResult}; use ruma_identifiers::{EventId, RoomId, UserId}; use serde::{Deserialize, Serialize}; @@ -32,6 +32,7 @@ ruma_api! { response { /// A grouping of search results by category. + #[wrap_incoming] pub search_categories: ResultCategories, } } @@ -84,16 +85,18 @@ pub struct EventContext { } /// Context for search results, if requested. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct EventContextResult { /// Pagination token for the end of the chunk. pub end: String, /// Events just after the result. #[serde(skip_serializing_if = "Option::is_none")] - pub events_after: Option>>, + #[wrap_incoming(Event with EventResult)] + pub events_after: Option>, /// Events just before the result. #[serde(skip_serializing_if = "Option::is_none")] - pub events_before: Option>>, + #[wrap_incoming(Event with EventResult)] + pub events_before: Option>, /// The historic profile information of the users that sent the events returned. // TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773 #[serde(skip_serializing_if = "Option::is_none")] @@ -152,15 +155,16 @@ pub enum OrderBy { } /// Categories of events that can be searched for. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct ResultCategories { /// Room event results. #[serde(skip_serializing_if = "Option::is_none")] + #[wrap_incoming(RoomEventResults)] pub room_events: Option, } /// Categories of events that can be searched for. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct RoomEventResults { /// An approximate count of the total number of results found. pub count: UInt, @@ -172,6 +176,7 @@ pub struct RoomEventResults { #[serde(skip_serializing_if = "Option::is_none")] pub next_batch: Option, /// List of results in the requested order. + #[wrap_incoming(SearchResult)] pub results: Vec, /// The current state for every room in the results. This is included if the request had the /// `include_state` key set with a value of `true`. @@ -195,15 +200,17 @@ pub struct ResultGroup { } /// A search result. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct SearchResult { /// Context for result, if requested. #[serde(skip_serializing_if = "Option::is_none")] + #[wrap_incoming(EventContextResult)] pub context: Option, /// A number that describes how closely this result matches the search. Higher is closer. pub rank: f64, /// The event that matched. - pub result: EventResult, + #[wrap_incoming(with EventResult)] + pub result: Event, } /// A user profile. diff --git a/src/r0/send/send_message_event.rs b/src/r0/send/send_message_event.rs index c97fd0a1..81d5f7ba 100644 --- a/src/r0/send/send_message_event.rs +++ b/src/r0/send/send_message_event.rs @@ -1,7 +1,7 @@ //! [PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid) use ruma_api::ruma_api; -use ruma_events::{room::message::MessageEventContent, EventType}; +use ruma_events::{room::message::MessageEventContent, EventResult, EventType}; use ruma_identifiers::{EventId, RoomId}; ruma_api! { @@ -30,6 +30,7 @@ ruma_api! { pub txn_id: String, /// The event's content. #[ruma_api(body)] + #[wrap_incoming(with EventResult)] pub data: MessageEventContent, } diff --git a/src/r0/sync/get_member_events.rs b/src/r0/sync/get_member_events.rs index aa5c9fcd..c4b589d2 100644 --- a/src/r0/sync/get_member_events.rs +++ b/src/r0/sync/get_member_events.rs @@ -22,6 +22,7 @@ ruma_api! { response { /// A list of member events. - pub chunk: Vec> + #[wrap_incoming(MemberEvent with EventResult)] + pub chunk: Vec } } diff --git a/src/r0/sync/get_message_events.rs b/src/r0/sync/get_message_events.rs index 45f771bd..385478ce 100644 --- a/src/r0/sync/get_message_events.rs +++ b/src/r0/sync/get_message_events.rs @@ -56,7 +56,8 @@ ruma_api! { /// The token the pagination starts from. pub start: String, /// A list of room events. - pub chunk: Vec>, + #[wrap_incoming(only::RoomEvent with EventResult)] + pub chunk: Vec, /// The token the pagination ends at. pub end: String, } diff --git a/src/r0/sync/get_state_events.rs b/src/r0/sync/get_state_events.rs index dd122f65..8e3d8a73 100644 --- a/src/r0/sync/get_state_events.rs +++ b/src/r0/sync/get_state_events.rs @@ -25,6 +25,7 @@ ruma_api! { /// list of events. If the user has left the room then this will be the state of the /// room when they left as a list of events. #[ruma_api(body)] - pub room_state: Vec>, + #[wrap_incoming(only::StateEvent with EventResult)] + pub room_state: Vec, } } diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 21845d9c..b9ccf1ca 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use js_int::UInt; -use ruma_api::ruma_api; +use ruma_api::{ruma_api, Outgoing}; use ruma_events::{ collections::{all, only}, stripped, EventResult, @@ -50,11 +50,12 @@ ruma_api! { /// The batch token to supply in the `since` param of the next `/sync` request. pub next_batch: String, /// Updates to rooms. + #[wrap_incoming] pub rooms: Rooms, /// Updates to the presence status of other users. + #[wrap_incoming] pub presence: Presence, } - } /// Whether to set presence or not during sync. @@ -114,41 +115,50 @@ mod filter_def_serde { } /// Updates to rooms. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct Rooms { /// The rooms that the user has left or been banned from. + #[wrap_incoming(LeftRoom)] pub leave: HashMap, /// The rooms that the user has joined. + #[wrap_incoming(JoinedRoom)] pub join: HashMap, /// The rooms that the user has been invited to. + #[wrap_incoming(InvitedRoom)] pub invite: HashMap, } /// Historical updates to left rooms. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct LeftRoom { /// The timeline of messages and state changes in the room up to the point when the user /// left. + #[wrap_incoming] pub timeline: Timeline, /// The state updates for the room up to the start of the timeline. + #[wrap_incoming] pub state: State, } /// Updates to joined rooms. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct JoinedRoom { /// Counts of unread notifications for this room. pub unread_notifications: UnreadNotificationsCount, /// The timeline of messages and state changes in the room. + #[wrap_incoming] pub timeline: Timeline, /// Updates to the state, between the time indicated by the `since` parameter, and the start /// of the `timeline` (or all state up to the start of the `timeline`, if `since` is not /// given, or `full_state` is true). + #[wrap_incoming] pub state: State, /// The private data that this user has attached to this room. + #[wrap_incoming] pub account_data: AccountData, /// The ephemeral events in the room that aren't recorded in the timeline or state of the /// room. e.g. typing. + #[wrap_incoming] pub ephemeral: Ephemeral, } @@ -164,7 +174,7 @@ pub struct UnreadNotificationsCount { } /// Events in the room. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct Timeline { /// True if the number of events returned was limited by the `limit` on the filter. pub limited: bool, @@ -172,47 +182,54 @@ pub struct Timeline { /// `/rooms/{roomId}/messages` endpoint. pub prev_batch: String, /// A list of events. - pub events: Vec>, + #[wrap_incoming(all::RoomEvent with EventResult)] + pub events: Vec, } /// State events in the room. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct State { /// A list of state events. - pub events: Vec>, + #[wrap_incoming(only::StateEvent with EventResult)] + pub events: Vec, } /// The private data that this user has attached to this room. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct AccountData { /// A list of events. - pub events: Vec>, + #[wrap_incoming(only::Event with EventResult)] + pub events: Vec, } /// Ephemeral events not recorded in the timeline or state of the room. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct Ephemeral { /// A list of events. - pub events: Vec>, + #[wrap_incoming(only::Event with EventResult)] + pub events: Vec, } /// Updates to the rooms that the user has been invited to. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct InvitedRoom { /// The state of a room that the user has been invited to. + #[wrap_incoming] pub invite_state: InviteState, } /// The state of a room that the user has been invited to. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct InviteState { /// A list of state events. - pub events: Vec>, + #[wrap_incoming(stripped::StrippedState with EventResult)] + pub events: Vec, } /// Updates to the presence status of other users. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Outgoing)] pub struct Presence { /// A list of events. - pub events: Vec>, + #[wrap_incoming(only::Event with EventResult)] + pub events: Vec, } diff --git a/src/r0/tag/get_tags.rs b/src/r0/tag/get_tags.rs index 4f0abea0..a9448802 100644 --- a/src/r0/tag/get_tags.rs +++ b/src/r0/tag/get_tags.rs @@ -25,6 +25,7 @@ ruma_api! { response { /// The user's tags for the room. - pub tags: EventResult, + #[wrap_incoming(with EventResult)] + pub tags: TagEventContent, } }