From 74c6e38a6b9657ea3f60ab0e192b8172e0765587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Fri, 23 Dec 2022 21:37:57 +0100 Subject: [PATCH] client-api: Move Direction to ruma-common::api --- crates/ruma-client-api/CHANGELOG.md | 2 +- crates/ruma-client-api/src/lib.rs | 15 --------------- .../src/message/get_message_events.rs | 11 ++++------- .../src/relations/get_relating_events.rs | 4 +--- .../src/room/get_event_by_timestamp.rs | 8 +++----- crates/ruma-common/src/api.rs | 15 +++++++++++++++ 6 files changed, 24 insertions(+), 31 deletions(-) diff --git a/crates/ruma-client-api/CHANGELOG.md b/crates/ruma-client-api/CHANGELOG.md index d8f95b7e..b4b0c0cd 100644 --- a/crates/ruma-client-api/CHANGELOG.md +++ b/crates/ruma-client-api/CHANGELOG.md @@ -6,7 +6,7 @@ Breaking changes: * Use `sync::sync_events::DeviceLists` instead * `fully_read` field in `read_marker::set_read_marker` is no longer required * Remove the `fully_read` argument from `read_marker::set_read_marker::Request::new` -* Move `message::get_message_events::v3::Direction` to the root of the crate +* Move `message::get_message_events::v3::Direction` to `ruma-common::api` * Make `push::set_pusher::v3::Request` use an enum to differentiate when deleting a pusher * Move `push::get_pushers::v3::Pusher` to `push` and make it use the new `PusherIds` type * Remove `push::set_pusher::v3::Pusher` and use the common type instead diff --git a/crates/ruma-client-api/src/lib.rs b/crates/ruma-client-api/src/lib.rs index 21e08c00..dd432a81 100644 --- a/crates/ruma-client-api/src/lib.rs +++ b/crates/ruma-client-api/src/lib.rs @@ -52,7 +52,6 @@ pub mod voip; use std::fmt; pub use error::Error; -use serde::{Deserialize, Serialize}; // Wrapper around `Box` that cannot be used in a meaningful way outside of // this crate. Used for string enums because their `_Custom` variant can't be @@ -66,17 +65,3 @@ impl fmt::Debug for PrivOwnedStr { self.0.fmt(f) } } - -/// The direction to return events from. -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Deserialize, Serialize)] -#[allow(clippy::exhaustive_enums)] -pub enum Direction { - /// Return events backwards in time from the requested `from` token. - #[default] - #[serde(rename = "b")] - Backward, - - /// Return events forwards in time from the requested `from` token. - #[serde(rename = "f")] - Forward, -} diff --git a/crates/ruma-client-api/src/message/get_message_events.rs b/crates/ruma-client-api/src/message/get_message_events.rs index e4b5d3c6..25ecafa4 100644 --- a/crates/ruma-client-api/src/message/get_message_events.rs +++ b/crates/ruma-client-api/src/message/get_message_events.rs @@ -9,14 +9,14 @@ pub mod v3 { use js_int::{uint, UInt}; use ruma_common::{ - api::{request, response, Metadata}, + api::{request, response, Direction, Metadata}, events::{AnyStateEvent, AnyTimelineEvent}, metadata, serde::Raw, OwnedRoomId, }; - use crate::{filter::RoomEventFilter, Direction}; + use crate::filter::RoomEventFilter; const METADATA: Metadata = metadata! { method: GET, @@ -174,15 +174,12 @@ pub mod v3 { mod tests { use js_int::uint; use ruma_common::{ - api::{MatrixVersion, OutgoingRequest, SendAccessToken}, + api::{Direction, MatrixVersion, OutgoingRequest, SendAccessToken}, room_id, }; use super::Request; - use crate::{ - filter::{LazyLoadOptions, RoomEventFilter}, - Direction, - }; + use crate::filter::{LazyLoadOptions, RoomEventFilter}; #[test] fn serialize_some_room_event_filter() { diff --git a/crates/ruma-client-api/src/relations/get_relating_events.rs b/crates/ruma-client-api/src/relations/get_relating_events.rs index 61a22853..c30aa65d 100644 --- a/crates/ruma-client-api/src/relations/get_relating_events.rs +++ b/crates/ruma-client-api/src/relations/get_relating_events.rs @@ -9,15 +9,13 @@ pub mod v1 { use js_int::UInt; use ruma_common::{ - api::{request, response, Metadata}, + api::{request, response, Direction, Metadata}, events::AnyMessageLikeEvent, metadata, serde::Raw, OwnedEventId, OwnedRoomId, }; - use crate::Direction; - const METADATA: Metadata = metadata! { method: GET, rate_limited: false, diff --git a/crates/ruma-client-api/src/room/get_event_by_timestamp.rs b/crates/ruma-client-api/src/room/get_event_by_timestamp.rs index 9c489427..47f789a9 100644 --- a/crates/ruma-client-api/src/room/get_event_by_timestamp.rs +++ b/crates/ruma-client-api/src/room/get_event_by_timestamp.rs @@ -8,12 +8,10 @@ pub mod unstable { //! [MSC3030]: https://github.com/matrix-org/matrix-spec-proposals/pull/3030 use ruma_common::{ - api::{request, response, Metadata}, + api::{request, response, Direction, Metadata}, metadata, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, }; - use crate::Direction; - const METADATA: Metadata = metadata! { method: GET, rate_limited: true, @@ -23,7 +21,7 @@ pub mod unstable { } }; - /// Request type for the `get_event_for_timestamp` endpoint. + /// Request type for the `get_event_by_timestamp` endpoint. #[request(error = crate::Error)] pub struct Request { /// The ID of the room the event is in. @@ -39,7 +37,7 @@ pub mod unstable { pub dir: Direction, } - /// Response type for the `get_room_event` endpoint. + /// Response type for the `get_event_by_timestamp` endpoint. #[response(error = crate::Error)] pub struct Response { /// The ID of the event found. diff --git a/crates/ruma-common/src/api.rs b/crates/ruma-common/src/api.rs index 977a3575..8584bcf4 100644 --- a/crates/ruma-common/src/api.rs +++ b/crates/ruma-common/src/api.rs @@ -15,6 +15,7 @@ use std::{convert::TryInto as _, error::Error as StdError}; use bytes::BufMut; +use serde::{Deserialize, Serialize}; use crate::UserId; @@ -421,6 +422,20 @@ pub enum AuthScheme { ServerSignatures, } +/// The direction to return events from. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Deserialize, Serialize)] +#[allow(clippy::exhaustive_enums)] +pub enum Direction { + /// Return events backwards in time from the requested `from` token. + #[default] + #[serde(rename = "b")] + Backward, + + /// Return events forwards in time from the requested `from` token. + #[serde(rename = "f")] + Forward, +} + /// Convenient constructor for [`Metadata`] constants. /// /// Usage: