ruma_client_api/receipt/
create_receipt.rs

1//! `POST /_matrix/client/*/rooms/{roomId}/receipt/{receiptType}/{eventId}`
2//!
3//! Send a receipt event to a room.
4
5pub mod v3 {
6    //! `/v3/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3roomsroomidreceiptreceipttypeeventid
9
10    use ruma_common::{
11        api::{request, response, Metadata},
12        metadata,
13        serde::{OrdAsRefStr, PartialEqAsRefStr, PartialOrdAsRefStr, StringEnum},
14        OwnedEventId, OwnedRoomId,
15    };
16    use ruma_events::receipt::ReceiptThread;
17
18    use crate::PrivOwnedStr;
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/receipt/:receipt_type/:event_id",
26            1.1 => "/_matrix/client/v3/rooms/:room_id/receipt/:receipt_type/:event_id",
27        }
28    };
29
30    /// Request type for the `create_receipt` endpoint.
31    #[request(error = crate::Error)]
32    pub struct Request {
33        /// The room in which to send the event.
34        #[ruma_api(path)]
35        pub room_id: OwnedRoomId,
36
37        /// The type of receipt to send.
38        #[ruma_api(path)]
39        pub receipt_type: ReceiptType,
40
41        /// The event ID to acknowledge up to.
42        #[ruma_api(path)]
43        pub event_id: OwnedEventId,
44
45        /// The thread this receipt applies to.
46        ///
47        /// *Note* that this must be the default value if used with
48        /// [`ReceiptType::FullyRead`].
49        ///
50        /// Defaults to [`ReceiptThread::Unthreaded`].
51        #[serde(
52            rename = "thread_id",
53            default,
54            skip_serializing_if = "ruma_common::serde::is_default"
55        )]
56        pub thread: ReceiptThread,
57    }
58
59    /// Response type for the `create_receipt` endpoint.
60    #[response(error = crate::Error)]
61    #[derive(Default)]
62    pub struct Response {}
63
64    impl Request {
65        /// Creates a new `Request` with the given room ID, receipt type and event ID.
66        pub fn new(
67            room_id: OwnedRoomId,
68            receipt_type: ReceiptType,
69            event_id: OwnedEventId,
70        ) -> Self {
71            Self { room_id, receipt_type, event_id, thread: ReceiptThread::default() }
72        }
73    }
74
75    impl Response {
76        /// Creates an empty `Response`.
77        pub fn new() -> Self {
78            Self {}
79        }
80    }
81
82    /// The type of receipt.
83    #[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
84    #[derive(Clone, PartialOrdAsRefStr, OrdAsRefStr, PartialEqAsRefStr, Eq, StringEnum)]
85    #[non_exhaustive]
86    pub enum ReceiptType {
87        /// A [public read receipt].
88        ///
89        /// Indicates that the given event has been presented to the user.
90        ///
91        /// This receipt is federated to other users.
92        ///
93        /// [public read receipt]: https://spec.matrix.org/latest/client-server-api/#receipts
94        #[ruma_enum(rename = "m.read")]
95        Read,
96
97        /// A [private read receipt].
98        ///
99        /// Indicates that the given event has been presented to the user.
100        ///
101        /// This read receipt is not federated so only the user and their homeserver
102        /// are aware of it.
103        ///
104        /// [private read receipt]: https://spec.matrix.org/latest/client-server-api/#private-read-receipts
105        #[ruma_enum(rename = "m.read.private")]
106        ReadPrivate,
107
108        /// A [fully read marker].
109        ///
110        /// Indicates that the given event has been read by the user.
111        ///
112        /// This is actually not a receipt, but a piece of room account data. It is
113        /// provided here for convenience.
114        ///
115        /// [fully read marker]: https://spec.matrix.org/latest/client-server-api/#fully-read-markers
116        #[ruma_enum(rename = "m.fully_read")]
117        FullyRead,
118
119        #[doc(hidden)]
120        _Custom(PrivOwnedStr),
121    }
122}