Skip to main content

zulip_api/message/mark_all_as_read/
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 `Mark All as Read` Zulip API endpoint.
7///
8/// See [mark-all-as-read](https://zulip.com/api/mark-all-as-read) for details.
9#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
10pub struct Response {
11    #[serde(flatten)]
12    base: BaseResponse,
13    complete: Option<bool>,
14}
15
16impl Response {
17    /// Creates a new [Response].
18    pub const fn new() -> Self {
19        Self {
20            base: BaseResponse::new(),
21            complete: None,
22        }
23    }
24}
25
26field_access! {
27    Response {
28        /// Whether all unread messages were marked as read.
29        ///
30        /// Will be `false` if the request successfully marked
31        /// some, but not all, messages as read.
32        complete: option { bool },
33    }
34}
35
36impl_default!(Response);
37impl_display!(Response);
38impl_response!(Response, base);
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43
44    #[test]
45    fn test_response() {
46        let complete = true;
47
48        let response = Response::new().with_complete(complete);
49        let response_json = response.to_string();
50
51        assert_eq!(serde_json::to_string(&response).unwrap(), response_json);
52        assert_eq!(
53            serde_json::from_str::<Response>(&response_json).unwrap(),
54            response
55        );
56
57        assert_eq!(response.complete(), Some(complete));
58    }
59}