| 1 | use serde_json::{Value, json}; |
| 2 | use session::{Method, Request, Session}; |
| 3 | |
| 4 | use crate::channel_notifications::{ChannelNotifications, PROPERTY_NAME}; |
| 5 | use crate::chat_notifications::{ |
| 6 | self, ChatNotificationMode, ChatNotificationWrite, DesktopNotifications, |
| 7 | }; |
| 8 | use crate::error::{Error, Result}; |
| 9 | use crate::messages::{MessageTransport, SessionMessageTransport, encode, ensure_success}; |
| 10 | use crate::pins::DEFAULT_REGION; |
| 11 | use crate::read_horizon::{self, ReadHorizon}; |
| 12 | |
| 13 | const PAGE_SIZE: usize = 200; |
| 14 | const MAX_PAGES: usize = 100; |
| 15 | const ALERTS_OFF: &str = "false"; |
| 16 | const CLEAR_HISTORY_PROPERTY: &str = "clearHistoryTime"; |
| 17 | |
| 18 | #[derive(Debug, Clone, PartialEq, Eq, Default)] |
| 19 | pub struct ConversationState { |
| 20 | pub id: String, |
| 21 | pub muted: bool, |
| 22 | pub hidden: Option<bool>, |
| 23 | pub read: ReadHorizon, |
| 24 | pub history_cleared_ms: Option<i64>, |
| 25 | pub notification_settings: Option<String>, |
| 26 | } |
| 27 | |
| 28 | impl ConversationState { |
| 29 | pub fn desktop_notifications(&self) -> DesktopNotifications { |
| 30 | chat_notifications::parse_desktop(self.notification_settings.as_deref()) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | pub struct Conversations<T: MessageTransport = SessionMessageTransport> { |
| 35 | transport: T, |
| 36 | base_url: String, |
| 37 | } |
| 38 | |
| 39 | impl Conversations<SessionMessageTransport> { |
| 40 | pub fn new(session: &Session) -> Self { |
| 41 | Self::with_region(session, DEFAULT_REGION) |
| 42 | } |
| 43 | |
| 44 | pub fn with_region(session: &Session, region: &str) -> Self { |
| 45 | Conversations::with_transport(SessionMessageTransport::new(session), region) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | impl<T: MessageTransport> Conversations<T> { |
| 50 | pub fn with_transport(transport: T, region: &str) -> Self { |
| 51 | Conversations { |
| 52 | transport, |
| 53 | base_url: format!( |
| 54 | "https://teams.cloud.microsoft/api/chatsvc/{region}/v1/users/ME/conversations" |
| 55 | ), |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | pub fn alerts_url(&self, conversation_id: &str) -> String { |
| 60 | format!( |
| 61 | "{}/{}/properties?name=alerts", |
| 62 | self.base_url, |
| 63 | encode(conversation_id) |
| 64 | ) |
| 65 | } |
| 66 | |
| 67 | pub async fn conversation_states(&self) -> Result<Vec<ConversationState>> { |
| 68 | let url = format!( |
| 69 | "{}?view=msnp24Equivalent&pageSize={PAGE_SIZE}", |
| 70 | self.base_url |
| 71 | ); |
| 72 | let mut states = Vec::new(); |
| 73 | let mut next_url = Some(url); |
| 74 | for _ in 0..MAX_PAGES { |
| 75 | let Some(url) = next_url.take() else { |
| 76 | break; |
| 77 | }; |
| 78 | let answer = self.transport.send(Request::get(&url)).await?; |
| 79 | ensure_success(&answer)?; |
| 80 | states.extend(states_in_page(&answer.body)?); |
| 81 | next_url = backward_link(&answer.body).filter(|link| *link != url); |
| 82 | } |
| 83 | Ok(states) |
| 84 | } |
| 85 | |
| 86 | pub async fn set_alerts(&self, conversation_id: &str, enabled: bool) -> Result<()> { |
| 87 | let body = json!({"alerts": if enabled { "true" } else { ALERTS_OFF }}); |
| 88 | let answer = self |
| 89 | .transport |
| 90 | .send(Request::with_body( |
| 91 | Method::Put, |
| 92 | self.alerts_url(conversation_id), |
| 93 | body, |
| 94 | )) |
| 95 | .await?; |
| 96 | ensure_success(&answer) |
| 97 | } |
| 98 | |
| 99 | /// Teams writes the merged notification settings first, then `alerts`. |
| 100 | pub async fn set_chat_notifications( |
| 101 | &self, |
| 102 | conversation_id: &str, |
| 103 | current_settings: Option<&str>, |
| 104 | mode: ChatNotificationMode, |
| 105 | desktop: DesktopNotifications, |
| 106 | ) -> Result<ChatNotificationWrite> { |
| 107 | let write = chat_notifications::chat_notification_write(current_settings, mode, desktop); |
| 108 | let url = format!( |
| 109 | "{}/{}/properties?name={}", |
| 110 | self.base_url, |
| 111 | encode(conversation_id), |
| 112 | chat_notifications::PROPERTY_NAME |
| 113 | ); |
| 114 | let body = json!({ chat_notifications::PROPERTY_NAME: write.settings }); |
| 115 | let answer = self |
| 116 | .transport |
| 117 | .send(Request::with_body(Method::Put, url, body)) |
| 118 | .await?; |
| 119 | ensure_success(&answer)?; |
| 120 | self.set_alerts(conversation_id, write.alerts).await?; |
| 121 | Ok(write) |
| 122 | } |
| 123 | |
| 124 | /// Teams' "Remove chat history": everything up to this time disappears for the current user only. |
| 125 | pub async fn clear_history(&self, conversation_id: &str, cleared_until_ms: i64) -> Result<()> { |
| 126 | let answer = self |
| 127 | .transport |
| 128 | .send(clear_history_request( |
| 129 | &self.base_url, |
| 130 | conversation_id, |
| 131 | cleared_until_ms, |
| 132 | )) |
| 133 | .await?; |
| 134 | ensure_success(&answer) |
| 135 | } |
| 136 | |
| 137 | pub async fn set_read_horizon(&self, conversation_id: &str, horizon: &str) -> Result<()> { |
| 138 | let url = format!( |
| 139 | "{}/{}/properties?name={}", |
| 140 | self.base_url, |
| 141 | encode(conversation_id), |
| 142 | read_horizon::PROPERTY_NAME |
| 143 | ); |
| 144 | let body = json!({ read_horizon::PROPERTY_NAME: horizon }); |
| 145 | let answer = self |
| 146 | .transport |
| 147 | .send(Request::with_body(Method::Put, url, body)) |
| 148 | .await?; |
| 149 | ensure_success(&answer) |
| 150 | } |
| 151 | |
| 152 | pub async fn set_channel_notifications( |
| 153 | &self, |
| 154 | channel_id: &str, |
| 155 | notifications: ChannelNotifications, |
| 156 | ) -> Result<()> { |
| 157 | let url = format!( |
| 158 | "{}/{}/properties?name={PROPERTY_NAME}", |
| 159 | self.base_url, |
| 160 | encode(channel_id) |
| 161 | ); |
| 162 | let body = json!({ PROPERTY_NAME: notifications.property_value() }); |
| 163 | let answer = self |
| 164 | .transport |
| 165 | .send(Request::with_body(Method::Put, url, body)) |
| 166 | .await?; |
| 167 | ensure_success(&answer) |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | pub fn clear_history_request( |
| 172 | base_url: &str, |
| 173 | conversation_id: &str, |
| 174 | cleared_until_ms: i64, |
| 175 | ) -> Request { |
| 176 | Request::with_body( |
| 177 | Method::Put, |
| 178 | format!( |
| 179 | "{base_url}/{}/properties?name={CLEAR_HISTORY_PROPERTY}", |
| 180 | encode(conversation_id) |
| 181 | ), |
| 182 | json!({ CLEAR_HISTORY_PROPERTY: cleared_until_ms }), |
| 183 | ) |
| 184 | } |
| 185 | |
| 186 | fn history_cleared_ms(conversation: &Value) -> Option<i64> { |
| 187 | let value = &conversation["properties"][CLEAR_HISTORY_PROPERTY]; |
| 188 | value |
| 189 | .as_i64() |
| 190 | .or_else(|| value.as_str()?.parse().ok()) |
| 191 | .filter(|millis| *millis > 0) |
| 192 | } |
| 193 | |
| 194 | /// One conversation with its thread properties, as Teams reads a meeting or 1:1 thread. |
| 195 | pub fn thread_url(region: &str, thread_id: &str) -> String { |
| 196 | format!( |
| 197 | "https://teams.cloud.microsoft/api/chatsvc/{region}/v1/users/ME/conversations/{}?view=msnp24Equivalent", |
| 198 | thread_id.replace(':', "%3A").replace('@', "%40") |
| 199 | ) |
| 200 | } |
| 201 | |
| 202 | fn backward_link(body: &Value) -> Option<String> { |
| 203 | body.pointer("/_metadata/backwardLink") |
| 204 | .and_then(Value::as_str) |
| 205 | .filter(|link| !link.is_empty()) |
| 206 | .map(str::to_owned) |
| 207 | } |
| 208 | |
| 209 | fn hidden_flag(conversation: &Value) -> Option<bool> { |
| 210 | let flags: Vec<bool> = [ |
| 211 | &conversation["properties"]["hidden"], |
| 212 | &conversation["threadProperties"]["hidden"], |
| 213 | ] |
| 214 | .into_iter() |
| 215 | .filter_map(|value| match value { |
| 216 | Value::Bool(flag) => Some(*flag), |
| 217 | Value::String(text) => text.parse().ok(), |
| 218 | _ => None, |
| 219 | }) |
| 220 | .collect(); |
| 221 | if flags.contains(&true) { |
| 222 | Some(true) |
| 223 | } else { |
| 224 | flags.first().copied() |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | fn states_in_page(body: &Value) -> Result<Vec<ConversationState>> { |
| 229 | let conversations = body |
| 230 | .get("conversations") |
| 231 | .and_then(Value::as_array) |
| 232 | .ok_or_else(|| Error::UnexpectedAnswer("no conversations list".into()))?; |
| 233 | Ok(conversations |
| 234 | .iter() |
| 235 | .filter_map(|conversation| { |
| 236 | let id = conversation["id"].as_str()?; |
| 237 | let muted = conversation["properties"]["alerts"].as_str() == Some(ALERTS_OFF); |
| 238 | Some(ConversationState { |
| 239 | id: id.to_owned(), |
| 240 | muted, |
| 241 | hidden: hidden_flag(conversation), |
| 242 | read: ReadHorizon::from_conversation(conversation), |
| 243 | notification_settings: conversation["properties"] |
| 244 | [chat_notifications::PROPERTY_NAME] |
| 245 | .as_str() |
| 246 | .map(str::to_owned), |
| 247 | history_cleared_ms: history_cleared_ms(conversation), |
| 248 | }) |
| 249 | }) |
| 250 | .collect()) |
| 251 | } |
| 252 | |
| 253 | #[cfg(test)] |
| 254 | mod tests { |
| 255 | use std::collections::VecDeque; |
| 256 | use std::sync::Mutex; |
| 257 | |
| 258 | use session::ApiResponse; |
| 259 | |
| 260 | use super::*; |
| 261 | |
| 262 | struct Canned { |
| 263 | answers: Mutex<VecDeque<(u16, Value)>>, |
| 264 | requests: Mutex<Vec<Request>>, |
| 265 | } |
| 266 | |
| 267 | impl MessageTransport for &Canned { |
| 268 | async fn send(&self, request: Request) -> Result<ApiResponse> { |
| 269 | self.requests.lock().unwrap().push(request); |
| 270 | let (status, body) = self.answers.lock().unwrap().pop_front().expect("exhausted"); |
| 271 | Ok(ApiResponse { |
| 272 | status, |
| 273 | body, |
| 274 | retry_after: None, |
| 275 | }) |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | fn canned(answers: Vec<(u16, Value)>) -> Canned { |
| 280 | Canned { |
| 281 | answers: Mutex::new(answers.into()), |
| 282 | requests: Mutex::new(Vec::new()), |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | fn state(id: &str, muted: bool) -> ConversationState { |
| 287 | ConversationState { |
| 288 | id: id.to_owned(), |
| 289 | muted, |
| 290 | ..Default::default() |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | const BASE: &str = "https://teams.cloud.microsoft/api/chatsvc/emea/v1/users/ME/conversations"; |
| 295 | |
| 296 | #[test] |
| 297 | fn thread_url_escapes_the_thread_id() { |
| 298 | assert_eq!( |
| 299 | thread_url("emea", "19:meeting_a@thread.v2"), |
| 300 | "https://teams.cloud.microsoft/api/chatsvc/emea/v1/users/ME/conversations/19%3Ameeting_a%40thread.v2?view=msnp24Equivalent" |
| 301 | ); |
| 302 | } |
| 303 | |
| 304 | #[tokio::test] |
| 305 | async fn mute_states_pair_every_conversation_with_its_flag() { |
| 306 | let transport = canned(vec![( |
| 307 | 200, |
| 308 | json!({ |
| 309 | "conversations": [ |
| 310 | {"id": "19:a", "properties": {"alerts": "false"}}, |
| 311 | {"id": "19:b", "properties": {"alerts": "true"}}, |
| 312 | {"id": "19:c", "properties": {}}, |
| 313 | {"id": "19:d"}, |
| 314 | ], |
| 315 | }), |
| 316 | )]); |
| 317 | let states = Conversations::with_transport(&transport, "emea") |
| 318 | .conversation_states() |
| 319 | .await |
| 320 | .unwrap(); |
| 321 | assert_eq!( |
| 322 | states, |
| 323 | vec![ |
| 324 | state("19:a", true), |
| 325 | state("19:b", false), |
| 326 | state("19:c", false), |
| 327 | state("19:d", false), |
| 328 | ] |
| 329 | ); |
| 330 | let requests = transport.requests.lock().unwrap(); |
| 331 | assert_eq!(requests.len(), 1); |
| 332 | assert_eq!( |
| 333 | requests[0].url, |
| 334 | format!("{BASE}?view=msnp24Equivalent&pageSize=200") |
| 335 | ); |
| 336 | } |
| 337 | |
| 338 | #[tokio::test] |
| 339 | async fn mute_states_follow_the_backward_link_through_every_page() { |
| 340 | let transport = canned(vec![ |
| 341 | ( |
| 342 | 200, |
| 343 | json!({ |
| 344 | "conversations": [{"id": "19:a", "properties": {"alerts": "true"}}], |
| 345 | "_metadata": {"backwardLink": "https://example.test/page2"}, |
| 346 | }), |
| 347 | ), |
| 348 | ( |
| 349 | 200, |
| 350 | json!({ |
| 351 | "conversations": [{"id": "19:old", "properties": {"alerts": "false"}}], |
| 352 | "_metadata": {"backwardLink": "https://example.test/page3"}, |
| 353 | }), |
| 354 | ), |
| 355 | (200, json!({"conversations": [{"id": "19:oldest"}]})), |
| 356 | ]); |
| 357 | let states = Conversations::with_transport(&transport, "emea") |
| 358 | .conversation_states() |
| 359 | .await |
| 360 | .unwrap(); |
| 361 | assert_eq!( |
| 362 | states, |
| 363 | vec![ |
| 364 | state("19:a", false), |
| 365 | state("19:old", true), |
| 366 | state("19:oldest", false), |
| 367 | ] |
| 368 | ); |
| 369 | let requests = transport.requests.lock().unwrap(); |
| 370 | let urls: Vec<&str> = requests |
| 371 | .iter() |
| 372 | .map(|request| request.url.as_str()) |
| 373 | .collect(); |
| 374 | assert_eq!(urls[1], "https://example.test/page2"); |
| 375 | assert_eq!(urls[2], "https://example.test/page3"); |
| 376 | } |
| 377 | |
| 378 | #[tokio::test] |
| 379 | async fn hidden_flag_is_read_from_the_thread_properties_as_text_or_bool() { |
| 380 | let transport = canned(vec![( |
| 381 | 200, |
| 382 | json!({ |
| 383 | "conversations": [ |
| 384 | {"id": "19:a", "threadProperties": {"hidden": "true"}}, |
| 385 | {"id": "19:b", "threadProperties": {"hidden": "false"}}, |
| 386 | {"id": "19:c", "properties": {"hidden": true}}, |
| 387 | {"id": "19:d", "properties": {}}, |
| 388 | {"id": "19:e", "properties": {"hidden": "false"}, "threadProperties": {"hidden": "true"}}, |
| 389 | {"id": "19:f", "properties": {"hidden": "true"}, "threadProperties": {"hidden": "false"}}, |
| 390 | ], |
| 391 | }), |
| 392 | )]); |
| 393 | let states = Conversations::with_transport(&transport, "emea") |
| 394 | .conversation_states() |
| 395 | .await |
| 396 | .unwrap(); |
| 397 | let hidden: Vec<Option<bool>> = states.iter().map(|state| state.hidden).collect(); |
| 398 | assert_eq!( |
| 399 | hidden, |
| 400 | [ |
| 401 | Some(true), |
| 402 | Some(false), |
| 403 | Some(true), |
| 404 | None, |
| 405 | Some(true), |
| 406 | Some(true) |
| 407 | ] |
| 408 | ); |
| 409 | } |
| 410 | |
| 411 | #[tokio::test] |
| 412 | async fn mute_states_fail_on_an_error_status() { |
| 413 | let transport = canned(vec![(500, Value::Null)]); |
| 414 | let outcome = Conversations::with_transport(&transport, "emea") |
| 415 | .conversation_states() |
| 416 | .await; |
| 417 | assert!(outcome.is_err()); |
| 418 | } |
| 419 | |
| 420 | #[tokio::test] |
| 421 | async fn set_alerts_puts_the_flag_as_text() { |
| 422 | let transport = canned(vec![(200, Value::Null), (200, Value::Null)]); |
| 423 | let conversations = Conversations::with_transport(&transport, "emea"); |
| 424 | conversations |
| 425 | .set_alerts("19:a@thread.v2", false) |
| 426 | .await |
| 427 | .unwrap(); |
| 428 | conversations |
| 429 | .set_alerts("19:a@thread.v2", true) |
| 430 | .await |
| 431 | .unwrap(); |
| 432 | let requests = transport.requests.lock().unwrap(); |
| 433 | assert_eq!(requests[0].method, Method::Put); |
| 434 | assert_eq!( |
| 435 | requests[0].url, |
| 436 | format!("{BASE}/19%3Aa%40thread.v2/properties?name=alerts") |
| 437 | ); |
| 438 | assert_eq!(requests[0].body, Some(json!({"alerts": "false"}))); |
| 439 | assert_eq!(requests[1].body, Some(json!({"alerts": "true"}))); |
| 440 | } |
| 441 | |
| 442 | #[tokio::test] |
| 443 | async fn states_carry_the_read_horizon() { |
| 444 | let transport = canned(vec![( |
| 445 | 200, |
| 446 | json!({ |
| 447 | "conversations": [{ |
| 448 | "id": "19:a", |
| 449 | "properties": {"consumptionhorizon": "5;6;7"}, |
| 450 | "lastMessage": {"originalarrivaltime": "1970-01-01T00:00:00.009Z", "from": "x/contacts/8:orgid:b"}, |
| 451 | }], |
| 452 | }), |
| 453 | )]); |
| 454 | let states = Conversations::with_transport(&transport, "emea") |
| 455 | .conversation_states() |
| 456 | .await |
| 457 | .unwrap(); |
| 458 | assert_eq!(states[0].read.consumed_until_ms, 5); |
| 459 | assert_eq!(states[0].read.last_message_ms, 9); |
| 460 | assert!(states[0].read.is_unread("8:orgid:me")); |
| 461 | } |
| 462 | |
| 463 | #[tokio::test] |
| 464 | async fn clear_history_puts_the_time_as_a_number() { |
| 465 | let transport = canned(vec![(200, Value::Null)]); |
| 466 | Conversations::with_transport(&transport, "emea") |
| 467 | .clear_history("19:a_b@unq.gbl.spaces", 1_792_200_000_001) |
| 468 | .await |
| 469 | .unwrap(); |
| 470 | let requests = transport.requests.lock().unwrap(); |
| 471 | assert_eq!(requests[0].method, Method::Put); |
| 472 | assert_eq!( |
| 473 | requests[0].url, |
| 474 | format!("{BASE}/19%3Aa_b%40unq.gbl.spaces/properties?name=clearHistoryTime") |
| 475 | ); |
| 476 | assert_eq!( |
| 477 | requests[0].body, |
| 478 | Some(json!({"clearHistoryTime": 1_792_200_000_001_i64})) |
| 479 | ); |
| 480 | } |
| 481 | |
| 482 | #[tokio::test] |
| 483 | async fn states_carry_the_clear_history_time_as_text_or_number() { |
| 484 | let transport = canned(vec![( |
| 485 | 200, |
| 486 | json!({ |
| 487 | "conversations": [ |
| 488 | {"id": "19:a", "properties": {"clearHistoryTime": "1792200000001"}}, |
| 489 | {"id": "19:b", "properties": {"clearHistoryTime": 1_792_200_000_002_i64}}, |
| 490 | {"id": "19:c", "properties": {"clearHistoryTime": "0"}}, |
| 491 | {"id": "19:d"}, |
| 492 | ], |
| 493 | }), |
| 494 | )]); |
| 495 | let states = Conversations::with_transport(&transport, "emea") |
| 496 | .conversation_states() |
| 497 | .await |
| 498 | .unwrap(); |
| 499 | let cleared: Vec<Option<i64>> = states |
| 500 | .iter() |
| 501 | .map(|state| state.history_cleared_ms) |
| 502 | .collect(); |
| 503 | assert_eq!( |
| 504 | cleared, |
| 505 | [Some(1_792_200_000_001), Some(1_792_200_000_002), None, None] |
| 506 | ); |
| 507 | } |
| 508 | |
| 509 | #[tokio::test] |
| 510 | async fn set_read_horizon_puts_the_consumption_horizon_property() { |
| 511 | let transport = canned(vec![(200, Value::Null)]); |
| 512 | Conversations::with_transport(&transport, "emea") |
| 513 | .set_read_horizon("19:a@thread.skype", "9;10;0") |
| 514 | .await |
| 515 | .unwrap(); |
| 516 | let requests = transport.requests.lock().unwrap(); |
| 517 | assert_eq!(requests[0].method, Method::Put); |
| 518 | assert_eq!( |
| 519 | requests[0].url, |
| 520 | format!("{BASE}/19%3Aa%40thread.skype/properties?name=consumptionhorizon") |
| 521 | ); |
| 522 | assert_eq!( |
| 523 | requests[0].body, |
| 524 | Some(json!({"consumptionhorizon": "9;10;0"})) |
| 525 | ); |
| 526 | } |
| 527 | |
| 528 | #[tokio::test] |
| 529 | async fn chat_notifications_put_the_settings_then_alerts() { |
| 530 | let transport = canned(vec![(200, Value::Null), (200, Value::Null)]); |
| 531 | let write = Conversations::with_transport(&transport, "emea") |
| 532 | .set_chat_notifications( |
| 533 | "19:a@thread.v2", |
| 534 | Some(r#"{"everyone":"On"}"#), |
| 535 | ChatNotificationMode::Mute, |
| 536 | DesktopNotifications::MatchAllChats, |
| 537 | ) |
| 538 | .await |
| 539 | .unwrap(); |
| 540 | assert!(!write.alerts); |
| 541 | let requests = transport.requests.lock().unwrap(); |
| 542 | assert_eq!( |
| 543 | requests[0].url, |
| 544 | format!("{BASE}/19%3Aa%40thread.v2/properties?name=conversationNotificationSettings") |
| 545 | ); |
| 546 | let sent = requests[0].body.as_ref().unwrap()["conversationNotificationSettings"] |
| 547 | .as_str() |
| 548 | .unwrap(); |
| 549 | assert_eq!( |
| 550 | serde_json::from_str::<Value>(sent).unwrap(), |
| 551 | json!({"everyone": "Off", "dskNotif": null, "allNewPosts": "Off"}) |
| 552 | ); |
| 553 | assert_eq!( |
| 554 | requests[1].url, |
| 555 | format!("{BASE}/19%3Aa%40thread.v2/properties?name=alerts") |
| 556 | ); |
| 557 | assert_eq!(requests[1].body, Some(json!({"alerts": "false"}))); |
| 558 | } |
| 559 | |
| 560 | #[tokio::test] |
| 561 | async fn states_carry_the_chat_notification_settings() { |
| 562 | let transport = canned(vec![( |
| 563 | 200, |
| 564 | json!({"conversations": [{"id": "19:a", "properties": {"conversationNotificationSettings": "{\"dskNotif\":\"Off\"}"}}]}), |
| 565 | )]); |
| 566 | let states = Conversations::with_transport(&transport, "emea") |
| 567 | .conversation_states() |
| 568 | .await |
| 569 | .unwrap(); |
| 570 | assert_eq!(states[0].desktop_notifications(), DesktopNotifications::Off); |
| 571 | } |
| 572 | } |