From eb4b8e559ef8fd689e88b66abef9c10596964ebf Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 22 Apr 2020 03:01:33 +0200 Subject: [PATCH] Update ruma-api, ruma-events --- Cargo.toml | 4 +- .../client_exchange/send_event_to_device.rs | 5 +- src/r0/config/get_global_account_data.rs | 5 +- src/r0/config/get_room_account_data.rs | 5 +- src/r0/context/get_context.rs | 17 +++-- src/r0/membership/get_member_events.rs | 5 +- src/r0/message/create_message_event.rs | 5 +- src/r0/message/get_message_events.rs | 5 +- src/r0/push/get_notifications.rs | 14 ++--- src/r0/room/create_room.rs | 5 +- src/r0/room/get_room_event.rs | 5 +- src/r0/search/search_events.rs | 29 ++++----- src/r0/state/get_state_events.rs | 5 +- src/r0/sync/sync_events.rs | 63 +++++++------------ src/r0/tag/get_tags.rs | 5 +- 15 files changed, 68 insertions(+), 109 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 355b4fe0..9343fe78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,8 +15,8 @@ edition = "2018" [dependencies] http = "0.2.1" js_int = { version = "0.1.4", features = ["serde"] } -ruma-api = "0.16.0-rc.2" -ruma-events = "0.20.0" +ruma-api = "0.16.0-rc.3" +ruma-events = "0.21.0-beta.1" ruma-identifiers = "0.16.0" ruma-serde = "0.1.0" serde = { version = "1.0.106", features = ["derive"] } diff --git a/src/r0/client_exchange/send_event_to_device.rs b/src/r0/client_exchange/send_event_to_device.rs index 5dc9c092..f31e9eff 100644 --- a/src/r0/client_exchange/send_event_to_device.rs +++ b/src/r0/client_exchange/send_event_to_device.rs @@ -3,7 +3,7 @@ use std::collections::BTreeMap; use ruma_api::ruma_api; -use ruma_events::{room::message::MessageEventContent, EventResult, EventType}; +use ruma_events::{room::message::MessageEventContent, EventJson, EventType}; use ruma_identifiers::UserId; use super::DeviceIdOrAllDevices; @@ -28,8 +28,7 @@ ruma_api! { /// A map of users to devices to a message event to be sent to the user's /// device. Individual message events can be sent to devices, but all /// events must be of the same type. - #[wrap_incoming(MessageEventContent with EventResult)] - pub messages: BTreeMap> + pub messages: BTreeMap>> } response {} diff --git a/src/r0/config/get_global_account_data.rs b/src/r0/config/get_global_account_data.rs index 611781c8..41cb40f9 100644 --- a/src/r0/config/get_global_account_data.rs +++ b/src/r0/config/get_global_account_data.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/user/{userId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-user-userid-account-data-type) use ruma_api::ruma_api; -use ruma_events::{collections::only, EventResult}; +use ruma_events::{collections::only, EventJson}; use ruma_identifiers::UserId; ruma_api! { @@ -26,8 +26,7 @@ ruma_api! { response { /// Account data content for the given type. #[ruma_api(body)] - #[wrap_incoming(with EventResult)] - pub account_data: only::Event, + pub account_data: EventJson, } error: crate::Error diff --git a/src/r0/config/get_room_account_data.rs b/src/r0/config/get_room_account_data.rs index 7c79bad3..2f7a978e 100644 --- a/src/r0/config/get_room_account_data.rs +++ b/src/r0/config/get_room_account_data.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-user-userid-rooms-roomid-account-data-type) use ruma_api::ruma_api; -use ruma_events::{collections::only, EventResult}; +use ruma_events::{collections::only, EventJson}; use ruma_identifiers::{RoomId, UserId}; ruma_api! { @@ -29,8 +29,7 @@ ruma_api! { response { /// Account data content for the given type. #[ruma_api(body)] - #[wrap_incoming(with EventResult)] - pub account_data: only::Event, + pub account_data: EventJson, } error: crate::Error diff --git a/src/r0/context/get_context.rs b/src/r0/context/get_context.rs index dc6ff9a1..0f39509b 100644 --- a/src/r0/context/get_context.rs +++ b/src/r0/context/get_context.rs @@ -2,7 +2,7 @@ use js_int::UInt; use ruma_api::ruma_api; -use ruma_events::{collections::only, EventResult}; +use ruma_events::{collections::only, EventJson}; use ruma_identifiers::{EventId, RoomId}; use crate::r0::filter::RoomEventFilter; @@ -40,21 +40,20 @@ ruma_api! { /// A token that can be used to paginate forwards with. pub end: String, /// Details of the requested event. - #[wrap_incoming(with EventResult)] - pub event: only::RoomEvent, + pub event: EventJson, /// A list of room events that happened just after the requested event, in chronological /// order. - #[wrap_incoming(only::RoomEvent with EventResult)] - pub events_after: Vec, + + pub events_after: Vec>, /// A list of room events that happened just before the requested event, in /// reverse-chronological order. - #[wrap_incoming(only::RoomEvent with EventResult)] - pub events_before: Vec, + + 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. - #[wrap_incoming(only::StateEvent with EventResult)] - pub state: Vec, + + pub state: Vec>, } error: crate::Error diff --git a/src/r0/membership/get_member_events.rs b/src/r0/membership/get_member_events.rs index f4fb29bd..76d83b65 100644 --- a/src/r0/membership/get_member_events.rs +++ b/src/r0/membership/get_member_events.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/rooms/{roomId}/members](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-members) use ruma_api::ruma_api; -use ruma_events::{room::member::MemberEvent, EventResult}; +use ruma_events::{room::member::MemberEvent, EventJson}; use ruma_identifiers::RoomId; use serde::{Deserialize, Serialize}; @@ -42,8 +42,7 @@ ruma_api! { response { /// A list of member events. - #[wrap_incoming(MemberEvent with EventResult)] - pub chunk: Vec + pub chunk: Vec> } error: crate::Error diff --git a/src/r0/message/create_message_event.rs b/src/r0/message/create_message_event.rs index 4849641d..573dff04 100644 --- a/src/r0/message/create_message_event.rs +++ b/src/r0/message/create_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, EventResult, EventType}; +use ruma_events::{room::message::MessageEventContent, EventJson, EventType}; use ruma_identifiers::{EventId, RoomId}; ruma_api! { @@ -30,8 +30,7 @@ ruma_api! { pub txn_id: String, /// The event's content. #[ruma_api(body)] - #[wrap_incoming(with EventResult)] - pub data: MessageEventContent, + pub data: EventJson, } response { diff --git a/src/r0/message/get_message_events.rs b/src/r0/message/get_message_events.rs index e5220d2a..144ce86f 100644 --- a/src/r0/message/get_message_events.rs +++ b/src/r0/message/get_message_events.rs @@ -2,7 +2,7 @@ use js_int::UInt; use ruma_api::ruma_api; -use ruma_events::{collections::all::RoomEvent, EventResult}; +use ruma_events::{collections::all::RoomEvent, EventJson}; use ruma_identifiers::RoomId; use serde::{Deserialize, Serialize}; @@ -60,8 +60,7 @@ ruma_api! { /// The token the pagination starts from. pub start: String, /// A list of room events. - #[wrap_incoming(RoomEvent with EventResult)] - pub chunk: Vec, + pub chunk: Vec>, /// The token the pagination ends at. pub end: String, } diff --git a/src/r0/push/get_notifications.rs b/src/r0/push/get_notifications.rs index de263b96..43a946c3 100644 --- a/src/r0/push/get_notifications.rs +++ b/src/r0/push/get_notifications.rs @@ -3,10 +3,10 @@ use std::time::SystemTime; use js_int::UInt; -use ruma_api::{ruma_api, Outgoing}; -use ruma_events::{collections::all, EventResult}; +use ruma_api::ruma_api; +use ruma_events::{collections::all, EventJson}; use ruma_identifiers::RoomId; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use super::Action; @@ -46,22 +46,20 @@ ruma_api! { /// The list of events that triggered notifications. - #[wrap_incoming(Notification)] - pub notifications: Vec, + pub notifications: Vec>, } error: crate::Error } /// Represents a notification -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct Notification { /// The actions to perform when the conditions for this rule are met. pub actions: Vec, /// The event that triggered the notification. - #[wrap_incoming(with EventResult)] - pub event: all::Event, + pub event: EventJson, /// The profile tag of the rule that matched this event. #[serde(skip_serializing_if = "Option::is_none")] diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index 7dc1be99..c29cc996 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -1,7 +1,7 @@ //! [POST /_matrix/client/r0/createRoom](https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-createroom) use ruma_api::ruma_api; -use ruma_events::{room::power_levels::PowerLevelsEventContent, EventResult}; +use ruma_events::{room::power_levels::PowerLevelsEventContent, EventJson}; use ruma_identifiers::{RoomId, UserId}; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -46,8 +46,7 @@ ruma_api! { pub name: Option, /// Power level content to override in the default power level event. #[serde(skip_serializing_if = "Option::is_none")] - #[wrap_incoming(PowerLevelsEventContent with EventResult)] - pub power_level_content_override: Option, + pub power_level_content_override: Option>, /// Convenience parameter for setting various default state events based on a preset. #[serde(skip_serializing_if = "Option::is_none")] pub preset: Option, diff --git a/src/r0/room/get_room_event.rs b/src/r0/room/get_room_event.rs index 29450ae4..b38c9e7f 100644 --- a/src/r0/room/get_room_event.rs +++ b/src/r0/room/get_room_event.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/rooms/{roomId}/event/{eventId}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-event-eventid) use ruma_api::ruma_api; -use ruma_events::{collections::all, EventResult}; +use ruma_events::{collections::all, EventJson}; use ruma_identifiers::{EventId, RoomId}; ruma_api! { @@ -25,8 +25,7 @@ ruma_api! { response { /// Arbitrary JSON of the event body. Returns both room and state events. - #[wrap_incoming(with EventResult)] - pub event: all::RoomEvent, + pub event: EventJson, } error: crate::Error diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs index 74cb80ea..525c6bbf 100644 --- a/src/r0/search/search_events.rs +++ b/src/r0/search/search_events.rs @@ -3,8 +3,8 @@ use std::collections::BTreeMap; use js_int::UInt; -use ruma_api::{ruma_api, Outgoing}; -use ruma_events::{collections::all::Event, EventResult}; +use ruma_api::ruma_api; +use ruma_events::{collections::all::Event, EventJson}; use ruma_identifiers::{EventId, RoomId, UserId}; use serde::{Deserialize, Serialize}; @@ -32,7 +32,6 @@ ruma_api! { response { /// A grouping of search results by category. - #[wrap_incoming] pub search_categories: ResultCategories, } @@ -87,18 +86,16 @@ pub struct EventContext { } /// Context for search results, if requested. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] 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")] - #[wrap_incoming(Event with EventResult)] - pub events_after: Option>, + pub events_after: Option>>, /// Events just before the result. #[serde(skip_serializing_if = "Option::is_none")] - #[wrap_incoming(Event with EventResult)] - pub events_before: Option>, + 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")] @@ -157,17 +154,16 @@ pub enum OrderBy { } /// Categories of events that can be searched for. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct ResultCategories { /// Room event results. #[serde(skip_serializing_if = "Option::is_none")] - #[wrap_incoming(RoomEventResults)] - pub room_events: Option, + pub room_events: Option, } /// Categories of events that can be searched for. -#[derive(Clone, Debug, Serialize, Outgoing)] -pub struct RoomEventResults { +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct RoomEventJsons { /// An approximate count of the total number of results found. pub count: UInt, /// Any groups that were requested. @@ -178,7 +174,6 @@ 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`. @@ -202,17 +197,15 @@ pub struct ResultGroup { } /// A search result. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] 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. - #[wrap_incoming(with EventResult)] - pub result: Event, + pub result: EventJson, } /// A user profile. diff --git a/src/r0/state/get_state_events.rs b/src/r0/state/get_state_events.rs index d45ddd43..35968905 100644 --- a/src/r0/state/get_state_events.rs +++ b/src/r0/state/get_state_events.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/rooms/{roomId}/state](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-state) use ruma_api::ruma_api; -use ruma_events::{collections::all::StateEvent, EventResult}; +use ruma_events::{collections::all::StateEvent, EventJson}; use ruma_identifiers::RoomId; ruma_api! { @@ -25,8 +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)] - #[wrap_incoming(StateEvent with EventResult)] - pub room_state: Vec, + pub room_state: Vec>, } error: crate::Error diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 49d47a7e..24fa044f 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -3,7 +3,7 @@ use std::{collections::BTreeMap, time::Duration}; use js_int::UInt; -use ruma_api::{ruma_api, Outgoing}; +use ruma_api::ruma_api; use ruma_events::{ collections::{ all::{RoomEvent, StateEvent}, @@ -12,7 +12,7 @@ use ruma_events::{ presence::PresenceEvent, stripped::AnyStrippedStateEvent, to_device::AnyToDeviceEvent, - EventResult, + EventJson, }; use ruma_identifiers::RoomId; use serde::{Deserialize, Serialize}; @@ -63,14 +63,11 @@ 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, /// Messages sent dirrectly between devices. #[serde(default, skip_serializing_if = "ToDevice::is_empty")] - #[wrap_incoming] pub to_device: ToDevice, /// Information on E2E device updates. /// @@ -127,36 +124,30 @@ pub enum Filter { } /// Updates to rooms. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct Rooms { /// The rooms that the user has left or been banned from. - #[wrap_incoming(LeftRoom)] pub leave: BTreeMap, /// The rooms that the user has joined. - #[wrap_incoming(JoinedRoom)] pub join: BTreeMap, /// The rooms that the user has been invited to. - #[wrap_incoming(InvitedRoom)] pub invite: BTreeMap, } /// Historical updates to left rooms. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] 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, /// The private data that this user has attached to this room. - #[wrap_incoming] pub account_data: AccountData, } /// Updates to joined rooms. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct JoinedRoom { /// Information about the room which clients may need to correctly render it /// to users. @@ -164,19 +155,15 @@ 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, } @@ -192,7 +179,7 @@ pub struct UnreadNotificationsCount { } /// Events in the room. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct Timeline { /// True if the number of events returned was limited by the `limit` on the filter. #[serde(skip_serializing_if = "Option::is_none")] @@ -202,32 +189,28 @@ pub struct Timeline { #[serde(skip_serializing_if = "Option::is_none")] pub prev_batch: Option, /// A list of events. - #[wrap_incoming(RoomEvent with EventResult)] - pub events: Vec, + pub events: Vec>, } /// State events in the room. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct State { /// A list of state events. - #[wrap_incoming(StateEvent with EventResult)] - pub events: Vec, + pub events: Vec>, } /// The private data that this user has attached to this room. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct AccountData { /// A list of events. - #[wrap_incoming(NonRoomEvent with EventResult)] - pub events: Vec, + pub events: Vec>, } /// Ephemeral events not recorded in the timeline or state of the room. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct Ephemeral { /// A list of events. - #[wrap_incoming(NonRoomEvent with EventResult)] - pub events: Vec, + pub events: Vec>, } /// Information about room for rendering to clients. @@ -250,35 +233,31 @@ pub struct RoomSummary { } /// Updates to the rooms that the user has been invited to. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] 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, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct InviteState { /// A list of state events. - #[wrap_incoming(AnyStrippedStateEvent with EventResult)] - pub events: Vec, + pub events: Vec>, } /// Updates to the presence status of other users. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct Presence { /// A list of events. - #[wrap_incoming(PresenceEvent with EventResult)] - pub events: Vec, + pub events: Vec>, } /// Messages sent dirrectly between devices. -#[derive(Clone, Debug, Serialize, Outgoing)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct ToDevice { /// A list of to-device events. - #[wrap_incoming(AnyToDeviceEvent with EventResult)] - pub events: Vec, + pub events: Vec>, } impl ToDevice { @@ -287,7 +266,7 @@ impl ToDevice { } } -impl Default for IncomingToDevice { +impl Default for ToDevice { fn default() -> Self { Self { events: Vec::new() } } diff --git a/src/r0/tag/get_tags.rs b/src/r0/tag/get_tags.rs index 14e30112..d02cbe27 100644 --- a/src/r0/tag/get_tags.rs +++ b/src/r0/tag/get_tags.rs @@ -1,7 +1,7 @@ //! [GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-user-userid-rooms-roomid-tags) use ruma_api::ruma_api; -use ruma_events::{tag::TagEventContent, EventResult}; +use ruma_events::{tag::TagEventContent, EventJson}; use ruma_identifiers::{RoomId, UserId}; ruma_api! { @@ -25,8 +25,7 @@ ruma_api! { response { /// The user's tags for the room. - #[wrap_incoming(with EventResult)] - pub tags: TagEventContent, + pub tags: EventJson, } error: crate::Error