zulip_api/message/update_message_flags/
response.rs1use serde::{Deserialize, Serialize};
2
3use crate::response::BaseResponse;
4use crate::{field_access, impl_default, impl_display, impl_response};
5
6#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
10pub struct Response {
11 #[serde(flatten)]
12 base: BaseResponse,
13 messages: Option<Vec<u64>>,
14 ignored_because_not_subscribed_channels: Option<Vec<u64>>,
15}
16
17impl Response {
18 pub const fn new() -> Self {
20 Self {
21 base: BaseResponse::new(),
22 messages: None,
23 ignored_because_not_subscribed_channels: None,
24 }
25 }
26}
27
28field_access! {
29 Response {
30 messages: option_cow_deref { [u64], Vec<u64> },
32 ignored_because_not_subscribed_channels: option_cow_deref { [u64], Vec<u64> },
41 }
42}
43
44impl_default!(Response);
45impl_display!(Response);
46impl_response!(Response, base);
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_response() {
54 let messages = [1u64];
55 let ignored_because_not_subscribed_channels = [2u64];
56
57 let response = Response::new()
58 .with_messages(messages.as_ref())
59 .with_ignored_because_not_subscribed_channels(
60 ignored_because_not_subscribed_channels.as_ref(),
61 );
62 let response_json = response.to_string();
63
64 assert_eq!(serde_json::to_string(&response).unwrap(), response_json);
65 assert_eq!(
66 serde_json::from_str::<Response>(&response_json).unwrap(),
67 response
68 );
69
70 assert_eq!(response.messages(), Some(messages.as_ref()));
71 assert_eq!(
72 response.ignored_because_not_subscribed_channels(),
73 Some(ignored_because_not_subscribed_channels.as_ref())
74 );
75 }
76}