client-api: Move Direction to ruma-common::api

This commit is contained in:
Kévin Commaille 2022-12-23 21:37:57 +01:00 committed by Kévin Commaille
parent d0b2ed3609
commit 74c6e38a6b
6 changed files with 24 additions and 31 deletions

View File

@ -6,7 +6,7 @@ Breaking changes:
* Use `sync::sync_events::DeviceLists` instead * Use `sync::sync_events::DeviceLists` instead
* `fully_read` field in `read_marker::set_read_marker` is no longer required * `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` * 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 * 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 * 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 * Remove `push::set_pusher::v3::Pusher` and use the common type instead

View File

@ -52,7 +52,6 @@ pub mod voip;
use std::fmt; use std::fmt;
pub use error::Error; pub use error::Error;
use serde::{Deserialize, Serialize};
// Wrapper around `Box<str>` that cannot be used in a meaningful way outside of // Wrapper around `Box<str>` that cannot be used in a meaningful way outside of
// this crate. Used for string enums because their `_Custom` variant can't be // 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) 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,
}

View File

@ -9,14 +9,14 @@ pub mod v3 {
use js_int::{uint, UInt}; use js_int::{uint, UInt};
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Direction, Metadata},
events::{AnyStateEvent, AnyTimelineEvent}, events::{AnyStateEvent, AnyTimelineEvent},
metadata, metadata,
serde::Raw, serde::Raw,
OwnedRoomId, OwnedRoomId,
}; };
use crate::{filter::RoomEventFilter, Direction}; use crate::filter::RoomEventFilter;
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {
method: GET, method: GET,
@ -174,15 +174,12 @@ pub mod v3 {
mod tests { mod tests {
use js_int::uint; use js_int::uint;
use ruma_common::{ use ruma_common::{
api::{MatrixVersion, OutgoingRequest, SendAccessToken}, api::{Direction, MatrixVersion, OutgoingRequest, SendAccessToken},
room_id, room_id,
}; };
use super::Request; use super::Request;
use crate::{ use crate::filter::{LazyLoadOptions, RoomEventFilter};
filter::{LazyLoadOptions, RoomEventFilter},
Direction,
};
#[test] #[test]
fn serialize_some_room_event_filter() { fn serialize_some_room_event_filter() {

View File

@ -9,15 +9,13 @@ pub mod v1 {
use js_int::UInt; use js_int::UInt;
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Direction, Metadata},
events::AnyMessageLikeEvent, events::AnyMessageLikeEvent,
metadata, metadata,
serde::Raw, serde::Raw,
OwnedEventId, OwnedRoomId, OwnedEventId, OwnedRoomId,
}; };
use crate::Direction;
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {
method: GET, method: GET,
rate_limited: false, rate_limited: false,

View File

@ -8,12 +8,10 @@ pub mod unstable {
//! [MSC3030]: https://github.com/matrix-org/matrix-spec-proposals/pull/3030 //! [MSC3030]: https://github.com/matrix-org/matrix-spec-proposals/pull/3030
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Direction, Metadata},
metadata, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, metadata, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId,
}; };
use crate::Direction;
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {
method: GET, method: GET,
rate_limited: true, 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)] #[request(error = crate::Error)]
pub struct Request { pub struct Request {
/// The ID of the room the event is in. /// The ID of the room the event is in.
@ -39,7 +37,7 @@ pub mod unstable {
pub dir: Direction, pub dir: Direction,
} }
/// Response type for the `get_room_event` endpoint. /// Response type for the `get_event_by_timestamp` endpoint.
#[response(error = crate::Error)] #[response(error = crate::Error)]
pub struct Response { pub struct Response {
/// The ID of the event found. /// The ID of the event found.

View File

@ -15,6 +15,7 @@
use std::{convert::TryInto as _, error::Error as StdError}; use std::{convert::TryInto as _, error::Error as StdError};
use bytes::BufMut; use bytes::BufMut;
use serde::{Deserialize, Serialize};
use crate::UserId; use crate::UserId;
@ -421,6 +422,20 @@ pub enum AuthScheme {
ServerSignatures, 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. /// Convenient constructor for [`Metadata`] constants.
/// ///
/// Usage: /// Usage: