From 38913946ebe243b02640c3f63a52932bf5ebe6ee Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 30 Aug 2020 22:52:44 +0200 Subject: [PATCH] client-api: Update a few more endpoints to the new API standards --- .../src/r0/receipt/create_receipt.rs | 22 +++++++++++++++-- ruma-client-api/src/r0/redact/redact_event.rs | 24 +++++++++++++++---- .../src/r0/typing/create_typing_event.rs | 21 ++++++++++++++-- .../src/r0/voip/get_turn_server_info.rs | 17 +++++++++++++ 4 files changed, 76 insertions(+), 8 deletions(-) diff --git a/ruma-client-api/src/r0/receipt/create_receipt.rs b/ruma-client-api/src/r0/receipt/create_receipt.rs index 8a716d7b..051cc326 100644 --- a/ruma-client-api/src/r0/receipt/create_receipt.rs +++ b/ruma-client-api/src/r0/receipt/create_receipt.rs @@ -16,10 +16,11 @@ ruma_api! { requires_authentication: true, } + #[non_exhaustive] request: { /// The room in which to send the event. #[ruma_api(path)] - pub room_id: RoomId, + pub room_id: &'a RoomId, /// The type of receipt to send. #[ruma_api(path)] @@ -27,16 +28,33 @@ ruma_api! { /// The event ID to acknowledge up to. #[ruma_api(path)] - pub event_id: EventId, + pub event_id: &'a EventId, } + #[derive(Default)] + #[non_exhaustive] response: {} error: crate::Error } +impl<'a> Request<'a> { + /// Creates a new `Request` with the given room ID, receipt type and event ID. + pub fn new(room_id: &'a RoomId, receipt_type: ReceiptType, event_id: &'a EventId) -> Self { + Self { room_id, receipt_type, event_id } + } +} + +impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Self + } +} + /// The type of receipt. #[derive(Clone, Copy, Debug, Display, EnumString)] +#[non_exhaustive] pub enum ReceiptType { /// m.read #[strum(serialize = "m.read")] diff --git a/ruma-client-api/src/r0/redact/redact_event.rs b/ruma-client-api/src/r0/redact/redact_event.rs index 0412231c..0230ac52 100644 --- a/ruma-client-api/src/r0/redact/redact_event.rs +++ b/ruma-client-api/src/r0/redact/redact_event.rs @@ -13,27 +13,29 @@ ruma_api! { requires_authentication: true, } + #[non_exhaustive] request: { /// The ID of the room of the event to redact. #[ruma_api(path)] - pub room_id: RoomId, + pub room_id: &'a RoomId, /// The ID of the event to redact. #[ruma_api(path)] - pub event_id: EventId, + pub event_id: &'a EventId, /// The transaction ID for this event. /// /// Clients should generate a unique ID; it will be used by the server to ensure idempotency /// of requests. #[ruma_api(path)] - pub txn_id: String, + pub txn_id: &'a str, /// The reason for the redaction. #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option, + pub reason: Option<&'a str>, } + #[non_exhaustive] response: { /// The ID of the redacted event. pub event_id: EventId, @@ -41,3 +43,17 @@ ruma_api! { error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given room ID, event ID and transation ID. + pub fn new(room_id: &'a RoomId, event_id: &'a EventId, txn_id: &'a str) -> Self { + Self { room_id, event_id, txn_id, reason: None } + } +} + +impl Response { + /// Creates a new `Response` with the given event ID. + pub fn new(event_id: EventId) -> Self { + Self { event_id } + } +} diff --git a/ruma-client-api/src/r0/typing/create_typing_event.rs b/ruma-client-api/src/r0/typing/create_typing_event.rs index ce800a75..d7528600 100644 --- a/ruma-client-api/src/r0/typing/create_typing_event.rs +++ b/ruma-client-api/src/r0/typing/create_typing_event.rs @@ -16,25 +16,42 @@ ruma_api! { rate_limited: true, } + #[non_exhaustive] request: { /// The user who has started to type. #[ruma_api(path)] - pub user_id: UserId, + pub user_id: &'a UserId, /// The room in which the user is typing. #[ruma_api(path)] - pub room_id: RoomId, + pub room_id: &'a RoomId, /// Whether the user is typing within a length of time or not. #[serde(flatten)] pub state: Typing, } + #[derive(Default)] + #[non_exhaustive] response: {} error: crate::Error } +impl<'a> Request<'a> { + /// Creates a new `Request` with the given user ID, room ID and typing state. + pub fn new(user_id: &'a UserId, room_id: &'a RoomId, state: Typing) -> Self { + Self { user_id, room_id, state } + } +} + +impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Self + } +} + /// A mark for whether the user is typing within a length of time or not. #[derive(Clone, Copy, Debug, Serialize)] #[serde(into = "TypingInner")] diff --git a/ruma-client-api/src/r0/voip/get_turn_server_info.rs b/ruma-client-api/src/r0/voip/get_turn_server_info.rs index 0540b8f3..061b8694 100644 --- a/ruma-client-api/src/r0/voip/get_turn_server_info.rs +++ b/ruma-client-api/src/r0/voip/get_turn_server_info.rs @@ -14,8 +14,11 @@ ruma_api! { requires_authentication: true, } + #[derive(Default)] + #[non_exhaustive] request: {} + #[non_exhaustive] response: { /// The username to use. pub username: String, @@ -33,3 +36,17 @@ ruma_api! { error: crate::Error } + +impl Request { + /// Creates an empty `Request`. + pub fn new() -> Self { + Self + } +} + +impl Response { + /// Creates a new `Response` with the given username, password, TURN URIs and time-to-live. + pub fn new(username: String, password: String, uris: Vec, ttl: Duration) -> Self { + Self { username, password, uris, ttl } + } +}