ruma_client_api/read_marker/
set_read_marker.rs

1//! `POST /_matrix/client/*/rooms/{roomId}/read_markers`
2//!
3//! Sets the position of the read marker for a given room, and optionally the read receipt's
4//! location.
5
6pub mod v3 {
7    //! `/v3/` ([spec])
8    //!
9    //! This endpoint is equivalent to calling the [`create_receipt`] endpoint,
10    //! but is provided as a way to update several read markers with a single call.
11    //!
12    //! [spec]: https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3roomsroomidread_markers
13    //! [`create_receipt`]: crate::receipt::create_receipt
14
15    use ruma_common::{
16        OwnedEventId, OwnedRoomId,
17        api::{auth_scheme::AccessToken, request, response},
18        metadata,
19    };
20
21    metadata! {
22        method: POST,
23        rate_limited: true,
24        authentication: AccessToken,
25        history: {
26            1.0 => "/_matrix/client/r0/rooms/{room_id}/read_markers",
27            1.1 => "/_matrix/client/v3/rooms/{room_id}/read_markers",
28        }
29    }
30
31    /// Request type for the `set_read_marker` endpoint.
32    #[request(error = crate::Error)]
33    pub struct Request {
34        /// The room ID to set the read marker in for the user.
35        #[ruma_api(path)]
36        pub room_id: OwnedRoomId,
37
38        /// The event ID the fully-read marker should be located at.
39        ///
40        /// The event MUST belong to the room.
41        ///
42        /// This is equivalent to calling the [`create_receipt`] endpoint with a
43        /// [`ReceiptType::FullyRead`].
44        ///
45        /// [`create_receipt`]: crate::receipt::create_receipt
46        /// [`ReceiptType::FullyRead`]: crate::receipt::create_receipt::v3::ReceiptType::FullyRead
47        #[serde(rename = "m.fully_read", skip_serializing_if = "Option::is_none")]
48        pub fully_read: Option<OwnedEventId>,
49
50        /// The event ID to set the public read receipt location at.
51        ///
52        /// This is equivalent to calling the [`create_receipt`] endpoint with a
53        /// [`ReceiptType::Read`].
54        ///
55        /// [`create_receipt`]: crate::receipt::create_receipt
56        /// [`ReceiptType::Read`]: crate::receipt::create_receipt::v3::ReceiptType::Read
57        #[serde(rename = "m.read", skip_serializing_if = "Option::is_none")]
58        pub read_receipt: Option<OwnedEventId>,
59
60        /// The event ID to set the private read receipt location at.
61        ///
62        /// This is equivalent to calling the [`create_receipt`] endpoint with a
63        /// [`ReceiptType::ReadPrivate`].
64        ///
65        /// [`create_receipt`]: crate::receipt::create_receipt
66        /// [`ReceiptType::ReadPrivate`]: crate::receipt::create_receipt::v3::ReceiptType::ReadPrivate
67        #[serde(rename = "m.read.private", skip_serializing_if = "Option::is_none")]
68        pub private_read_receipt: Option<OwnedEventId>,
69    }
70
71    /// Response type for the `set_read_marker` endpoint.
72    #[response(error = crate::Error)]
73    #[derive(Default)]
74    pub struct Response {}
75
76    impl Request {
77        /// Creates a new `Request` with the given room ID.
78        pub fn new(room_id: OwnedRoomId) -> Self {
79            Self { room_id, fully_read: None, read_receipt: None, private_read_receipt: None }
80        }
81    }
82
83    impl Response {
84        /// Creates an empty `Response`.
85        pub fn new() -> Self {
86            Self {}
87        }
88    }
89}