client-api: Update a few more endpoints to the new API standards

This commit is contained in:
Jonas Platte 2020-08-30 22:52:44 +02:00
parent e2406cc8f0
commit 38913946eb
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
4 changed files with 76 additions and 8 deletions

View File

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

View File

@ -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<String>,
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 }
}
}

View File

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

View File

@ -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<String>, ttl: Duration) -> Self {
Self { username, password, uris, ttl }
}
}