Skip to main content

zulip_api/message/get_message/
request.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{field_access, impl_default, impl_display};
4
5/// Represents the request for the `Get Message` Zulip API endpoint.
6///
7/// See [get-message](https://zulip.com/api/get-message) for details.
8#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
9pub struct Request {
10    #[serde(skip)]
11    message_id: u64,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    apply_markdown: Option<bool>,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    allow_empty_topic_name: Option<bool>,
16}
17
18impl Request {
19    /// Creates a new [Request].
20    pub const fn new() -> Self {
21        Self {
22            message_id: 0,
23            apply_markdown: None,
24            allow_empty_topic_name: None,
25        }
26    }
27}
28
29field_access! {
30    Request {
31        /// The target message's ID.
32        message_id: u64,
33    }
34}
35
36field_access! {
37    Request {
38        /// If `true`, message content is returned in the rendered HTML
39        /// format. If `false`, message content is returned in the raw
40        /// [Zulip-flavored Markdown format](https://zulip.com/help/format-your-message-using-markdown) text that user entered.
41        ///
42        /// **Changes**: New in Zulip 5.0 (feature level 120).
43        apply_markdown: option { bool },
44        /// Whether the client supports processing the empty string as a topic in the
45        /// topic name fields in the returned data, including in returned edit_history data.
46        ///
47        /// If `false`, the server will use the value of `realm_empty_topic_display_name`
48        /// found in the [`POST /register`](https://zulip.com/api/register-queue) response instead of empty string
49        /// to represent the empty string topic in its response.
50        ///
51        /// **Changes**: New in Zulip 10.0 (feature level 334). Previously, the empty string
52        /// was not a valid topic.
53        allow_empty_topic_name: option { bool },
54    }
55}
56
57impl_default!(Request);
58impl_display!(Request);
59
60#[cfg(test)]
61mod tests {
62    use super::*;
63
64    #[test]
65    fn test_request() {
66        let message_id = 1;
67        let apply_markdown = true;
68        let allow_empty_topic_name = false;
69
70        let mut request = Request::new()
71            .with_message_id(message_id)
72            .with_apply_markdown(apply_markdown)
73            .with_allow_empty_topic_name(allow_empty_topic_name);
74        let request_json = request.to_string();
75
76        assert_eq!(request.message_id(), message_id);
77        assert_eq!(request.apply_markdown(), Some(apply_markdown));
78        assert_eq!(
79            request.allow_empty_topic_name(),
80            Some(allow_empty_topic_name)
81        );
82
83        assert_eq!(serde_json::to_string(&request).unwrap(), request_json);
84        request.set_message_id(0);
85        assert_eq!(
86            serde_json::from_str::<Request>(&request_json).unwrap(),
87            request
88        );
89    }
90}