Update ruma-api, ruma-events

This commit is contained in:
Jonas Platte 2020-04-22 03:01:33 +02:00
parent 24b9ea7dc9
commit eb4b8e559e
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
15 changed files with 68 additions and 109 deletions

View File

@ -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"] }

View File

@ -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<UserId, BTreeMap<DeviceIdOrAllDevices, MessageEventContent>>
pub messages: BTreeMap<UserId, BTreeMap<DeviceIdOrAllDevices, EventJson<MessageEventContent>>>
}
response {}

View File

@ -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<only::Event>,
}
error: crate::Error

View File

@ -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<only::Event>,
}
error: crate::Error

View File

@ -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<only::RoomEvent>,
/// 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<only::RoomEvent>,
pub events_after: Vec<EventJson<only::RoomEvent>>,
/// 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<only::RoomEvent>,
pub events_before: Vec<EventJson<only::RoomEvent>>,
/// 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<only::StateEvent>,
pub state: Vec<EventJson<only::StateEvent>>,
}
error: crate::Error

View File

@ -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<MemberEvent>
pub chunk: Vec<EventJson<MemberEvent>>
}
error: crate::Error

View File

@ -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<MessageEventContent>,
}
response {

View File

@ -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<RoomEvent>,
pub chunk: Vec<EventJson<RoomEvent>>,
/// The token the pagination ends at.
pub end: String,
}

View File

@ -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<Notification>,
pub notifications: Vec<EventJson<Notification>>,
}
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<Action>,
/// The event that triggered the notification.
#[wrap_incoming(with EventResult)]
pub event: all::Event,
pub event: EventJson<all::Event>,
/// The profile tag of the rule that matched this event.
#[serde(skip_serializing_if = "Option::is_none")]

View File

@ -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<String>,
/// 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<PowerLevelsEventContent>,
pub power_level_content_override: Option<EventJson<PowerLevelsEventContent>>,
/// Convenience parameter for setting various default state events based on a preset.
#[serde(skip_serializing_if = "Option::is_none")]
pub preset: Option<RoomPreset>,

View File

@ -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<all::RoomEvent>,
}
error: crate::Error

View File

@ -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<Vec<Event>>,
pub events_after: Option<Vec<EventJson<Event>>>,
/// Events just before the result.
#[serde(skip_serializing_if = "Option::is_none")]
#[wrap_incoming(Event with EventResult)]
pub events_before: Option<Vec<Event>>,
pub events_before: Option<Vec<EventJson<Event>>>,
/// 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<RoomEventResults>,
pub room_events: Option<RoomEventJsons>,
}
/// 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<String>,
/// List of results in the requested order.
#[wrap_incoming(SearchResult)]
pub results: Vec<SearchResult>,
/// 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<EventContextResult>,
/// 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<Event>,
}
/// A user profile.

View File

@ -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<StateEvent>,
pub room_state: Vec<EventJson<StateEvent>>,
}
error: crate::Error

View File

@ -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<RoomId, LeftRoom>,
/// The rooms that the user has joined.
#[wrap_incoming(JoinedRoom)]
pub join: BTreeMap<RoomId, JoinedRoom>,
/// The rooms that the user has been invited to.
#[wrap_incoming(InvitedRoom)]
pub invite: BTreeMap<RoomId, InvitedRoom>,
}
/// 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<String>,
/// A list of events.
#[wrap_incoming(RoomEvent with EventResult)]
pub events: Vec<RoomEvent>,
pub events: Vec<EventJson<RoomEvent>>,
}
/// 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<StateEvent>,
pub events: Vec<EventJson<StateEvent>>,
}
/// 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<NonRoomEvent>,
pub events: Vec<EventJson<NonRoomEvent>>,
}
/// 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<NonRoomEvent>,
pub events: Vec<EventJson<NonRoomEvent>>,
}
/// 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<AnyStrippedStateEvent>,
pub events: Vec<EventJson<AnyStrippedStateEvent>>,
}
/// 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<PresenceEvent>,
pub events: Vec<EventJson<PresenceEvent>>,
}
/// 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<AnyToDeviceEvent>,
pub events: Vec<EventJson<AnyToDeviceEvent>>,
}
impl ToDevice {
@ -287,7 +266,7 @@ impl ToDevice {
}
}
impl Default for IncomingToDevice {
impl Default for ToDevice {
fn default() -> Self {
Self { events: Vec::new() }
}

View File

@ -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<TagEventContent>,
}
error: crate::Error