zulip_api/message/update_message_flags_narrow/
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 processed_count: Option<u64>,
14 updated_count: Option<u64>,
15 first_processed_id: Option<u64>,
16 last_processed_id: Option<u64>,
17 found_oldest: Option<bool>,
18 found_newest: Option<bool>,
19 ignored_because_not_subscribed_channels: Option<Vec<u64>>,
20}
21
22impl Response {
23 pub const fn new() -> Self {
25 Self {
26 base: BaseResponse::new(),
27 processed_count: None,
28 updated_count: None,
29 first_processed_id: None,
30 last_processed_id: None,
31 found_oldest: None,
32 found_newest: None,
33 ignored_because_not_subscribed_channels: None,
34 }
35 }
36}
37
38field_access! {
39 Response {
40 processed_count: option { u64 },
43 updated_count: option { u64 },
46 first_processed_id: option { u64 },
49 last_processed_id: option { u64 },
52 found_oldest: option { bool },
59 found_newest: option { bool },
66 }
67}
68
69field_access! {
70 Response {
71 ignored_because_not_subscribed_channels: option_cow_deref { [u64], Vec<u64> },
80 }
81}
82
83impl_default!(Response);
84impl_display!(Response);
85impl_response!(Response, base);
86
87#[cfg(test)]
88mod tests {
89 use super::*;
90
91 #[test]
92 fn test_response() {
93 let processed_count = 1;
94 let updated_count = 2;
95 let first_processed_id = 3;
96 let last_processed_id = 4;
97 let found_oldest = true;
98 let found_newest = false;
99 let ignored_because_not_subscribed_channels = [5];
100
101 let response = Response::new()
102 .with_processed_count(processed_count)
103 .with_updated_count(updated_count)
104 .with_first_processed_id(first_processed_id)
105 .with_last_processed_id(last_processed_id)
106 .with_found_oldest(found_oldest)
107 .with_found_newest(found_newest)
108 .with_ignored_because_not_subscribed_channels(
109 ignored_because_not_subscribed_channels.as_ref(),
110 );
111 let response_json = response.to_string();
112
113 assert_eq!(serde_json::to_string(&response).unwrap(), response_json);
114 assert_eq!(
115 serde_json::from_str::<Response>(&response_json).unwrap(),
116 response
117 );
118
119 assert_eq!(response.processed_count(), Some(processed_count));
120 assert_eq!(response.updated_count(), Some(updated_count));
121 assert_eq!(response.first_processed_id(), Some(first_processed_id));
122 assert_eq!(response.last_processed_id(), Some(last_processed_id));
123 assert_eq!(response.found_oldest(), Some(found_oldest));
124 assert_eq!(response.found_newest(), Some(found_newest));
125 assert_eq!(
126 response.ignored_because_not_subscribed_channels(),
127 Some(ignored_because_not_subscribed_channels.as_ref())
128 );
129 }
130}