zulip_api/message/muted_user.rs
1use serde::{Deserialize, Serialize};
2
3use crate::{field_access, impl_default, impl_display};
4
5/// Represents the user ID and timestamp of a muted user.
6///
7/// Modified from `openapi-generator-cli` output:
8///
9/// ```shell,no_build,no_run
10/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
11/// ```
12///
13/// ```text
14/// /*
15/// * Zulip REST API
16/// *
17/// * Powerful open source group chat
18/// *
19/// * The version of the OpenAPI document: 1.0.0
20/// *
21/// * Generated by: https://openapi-generator.tech
22/// */
23/// ```
24///
25/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
26///
27/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
28#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
29pub struct MutedUser {
30 #[serde(skip_serializing_if = "Option::is_none")]
31 id: Option<u64>,
32 #[serde(skip_serializing_if = "Option::is_none")]
33 timestamp: Option<u64>,
34}
35
36impl MutedUser {
37 /// Creates a new [MutedUser].
38 pub const fn new() -> Self {
39 Self {
40 id: None,
41 timestamp: None,
42 }
43 }
44}
45
46field_access! {
47 MutedUser {
48 /// The ID of the muted user.
49 id: option { u64 },
50 /// An integer UNIX timestamp representing when the user was muted.
51 timestamp: option { u64 },
52 }
53}
54
55impl_default!(MutedUser);
56impl_display!(MutedUser);
57
58#[cfg(test)]
59mod tests {
60 use super::*;
61
62 #[test]
63 fn test_user() {
64 let id = 1;
65 let timestamp = 2;
66
67 let user = MutedUser::new().with_id(id).with_timestamp(timestamp);
68 let user_json = user.to_string();
69
70 assert_eq!(serde_json::to_string(&user).unwrap(), user_json);
71 assert_eq!(serde_json::from_str::<MutedUser>(&user_json).unwrap(), user);
72
73 assert_eq!(user.id(), Some(id));
74 assert_eq!(user.timestamp(), Some(timestamp));
75 }
76}