Skip to main content

zulip_api/message/mark_topic_as_read/
request.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{field_access, impl_default, impl_display};
4
5/// Represents the response for the `Mark Topic as Read` Zulip API endpoint.
6///
7/// See [mark-topic-as-read](https://zulip.com/api/mark-topic-as-read) for details.
8#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
9pub struct Request {
10    stream_id: u64,
11    topic_name: String,
12}
13
14impl Request {
15    /// Creates a new [Request].
16    pub const fn new() -> Self {
17        Self {
18            stream_id: 0,
19            topic_name: String::new(),
20        }
21    }
22}
23
24field_access! {
25    Request {
26        /// The ID of the channel to access.
27        stream_id: u64,
28    }
29}
30
31field_access! {
32    Request {
33        /// The name of the topic whose messages should be marked as read.
34        ///
35        /// Note: When the value of `realm_empty_topic_display_name` found in
36        /// the [POST /register](https://zulip.com/api/register-queue) response is used for this
37        /// parameter, it is interpreted as an empty string.
38        ///
39        /// **Changes**: Before Zulip 10.0 (feature level 334), empty string
40        /// was not a valid topic name for channel messages.
41        topic_name: cow { str },
42    }
43}
44
45impl_default!(Request);
46impl_display!(Request);
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_request() {
54        let stream_id = 1;
55        let topic_name = "test topic";
56
57        let request = Request::new()
58            .with_stream_id(stream_id)
59            .with_topic_name(topic_name);
60        let request_json = request.to_string();
61
62        assert_eq!(serde_json::to_string(&request).unwrap(), request_json);
63        assert_eq!(
64            serde_json::from_str::<Request>(&request_json).unwrap(),
65            request
66        );
67
68        assert_eq!(request.stream_id(), stream_id);
69        assert_eq!(request.topic_name(), topic_name);
70    }
71}