Skip to main content

zulip_api/message/get_read_receipts/
response.rs

1use serde::{Deserialize, Serialize};
2
3use crate::response::BaseResponse;
4use crate::{field_access, impl_default, impl_display, impl_response};
5
6/// Represents the response for the `Get Read Receipts` Zulip API endpoint.
7///
8/// See [get-read-receipts](https://zulip.com/api/get-read-receipts) for details.
9#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
10pub struct Response {
11    #[serde(flatten)]
12    base: BaseResponse,
13    #[serde(skip_serializing_if = "Option::is_none")]
14    user_ids: Option<Vec<u64>>,
15}
16
17impl Response {
18    /// Creates a new [Response].
19    pub const fn new() -> Self {
20        Self {
21            base: BaseResponse::new(),
22            user_ids: None,
23        }
24    }
25}
26
27field_access! {
28    Response {
29        /// An array of IDs of users who have marked the target message as
30        /// read and whose read status is available to the current user.
31        ///
32        /// The IDs of users who have disabled sending read receipts
33        /// (`"send_read_receipts": false`) will never appear in the response,
34        /// nor will the message's sender. Additionally, the IDs of any users
35        /// who have been muted by the current user or who have muted the
36        /// current user will not be included in the response.
37        ///
38        /// The current user's ID will appear if they have marked the target
39        /// message as read.
40        ///
41        /// **Changes**: Prior to Zulip 6.0 (feature level 143), the IDs of
42        /// users who have been muted by or have muted the current user were
43        /// included in the response.
44        user_ids: option_cow_deref { [u64], Vec<u64> },
45    }
46}
47
48impl_default!(Response);
49impl_display!(Response);
50impl_response!(Response, base);
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_response() {
58        let user_ids = [1];
59
60        let response = Response::new().with_user_ids(user_ids.as_ref());
61        let response_json = response.to_string();
62
63        assert_eq!(serde_json::to_string(&response).unwrap(), response_json);
64        assert_eq!(
65            serde_json::from_str::<Response>(&response_json).unwrap(),
66            response
67        );
68
69        assert_eq!(response.user_ids(), Some(user_ids.as_ref()));
70    }
71}