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        api::{request, response, Metadata},
17        metadata, OwnedEventId, OwnedRoomId,
18    };
19
20    const METADATA: Metadata = metadata! {
21        method: POST,
22        rate_limited: true,
23        authentication: AccessToken,
24        history: {
25            1.0 => "/_matrix/client/r0/rooms/:room_id/read_markers",
26            1.1 => "/_matrix/client/v3/rooms/:room_id/read_markers",
27        }
28    };
29
30    /// Request type for the `set_read_marker` endpoint.
31    #[request(error = crate::Error)]
32    pub struct Request {
33        /// The room ID to set the read marker in for the user.
34        #[ruma_api(path)]
35        pub room_id: OwnedRoomId,
36
37        /// The event ID the fully-read marker should be located at.
38        ///
39        /// The event MUST belong to the room.
40        ///
41        /// This is equivalent to calling the [`create_receipt`] endpoint with a
42        /// [`ReceiptType::FullyRead`].
43        ///
44        /// [`create_receipt`]: crate::receipt::create_receipt
45        /// [`ReceiptType::FullyRead`]: crate::receipt::create_receipt::v3::ReceiptType::FullyRead
46        #[serde(rename = "m.fully_read", skip_serializing_if = "Option::is_none")]
47        pub fully_read: Option<OwnedEventId>,
48
49        /// The event ID to set the public read receipt location at.
50        ///
51        /// This is equivalent to calling the [`create_receipt`] endpoint with a
52        /// [`ReceiptType::Read`].
53        ///
54        /// [`create_receipt`]: crate::receipt::create_receipt
55        /// [`ReceiptType::Read`]: crate::receipt::create_receipt::v3::ReceiptType::Read
56        #[serde(rename = "m.read", skip_serializing_if = "Option::is_none")]
57        pub read_receipt: Option<OwnedEventId>,
58
59        /// The event ID to set the private read receipt location at.
60        ///
61        /// This is equivalent to calling the [`create_receipt`] endpoint with a
62        /// [`ReceiptType::ReadPrivate`].
63        ///
64        /// [`create_receipt`]: crate::receipt::create_receipt
65        /// [`ReceiptType::ReadPrivate`]: crate::receipt::create_receipt::v3::ReceiptType::ReadPrivate
66        #[serde(rename = "m.read.private", skip_serializing_if = "Option::is_none")]
67        pub private_read_receipt: Option<OwnedEventId>,
68    }
69
70    /// Response type for the `set_read_marker` endpoint.
71    #[response(error = crate::Error)]
72    #[derive(Default)]
73    pub struct Response {}
74
75    impl Request {
76        /// Creates a new `Request` with the given room ID.
77        pub fn new(room_id: OwnedRoomId) -> Self {
78            Self { room_id, fully_read: None, read_receipt: None, private_read_receipt: None }
79        }
80    }
81
82    impl Response {
83        /// Creates an empty `Response`.
84        pub fn new() -> Self {
85            Self {}
86        }
87    }
88}