()
| 483 | |
| 484 | #[tokio::test(flavor = "multi_thread", worker_threads = 2)] |
| 485 | async fn test_try_load() -> Result<()> { |
| 486 | let mut tcm = TestContextManager::new(); |
| 487 | let bob = &tcm.bob().await; |
| 488 | let chat_id1 = create_group(bob, "a chat").await.unwrap(); |
| 489 | let chat_id2 = create_group(bob, "b chat").await.unwrap(); |
| 490 | let chat_id3 = create_group(bob, "c chat").await.unwrap(); |
| 491 | |
| 492 | // check that the chatlist starts with the most recent message |
| 493 | let chats = Chatlist::try_load(bob, 0, None, None).await.unwrap(); |
| 494 | assert_eq!(chats.len(), 3); |
| 495 | assert_eq!(chats.get_chat_id(0).unwrap(), chat_id3); |
| 496 | assert_eq!(chats.get_chat_id(1).unwrap(), chat_id2); |
| 497 | assert_eq!(chats.get_chat_id(2).unwrap(), chat_id1); |
| 498 | |
| 499 | SystemTime::shift(Duration::from_secs(5)); |
| 500 | |
| 501 | // New drafts are sorted to the top |
| 502 | // We have to set a draft on the other two messages, too, as |
| 503 | // chat timestamps are only exact to the second and sorting by timestamp |
| 504 | // would not work. |
| 505 | // Message timestamps are "smeared" and unique, so we don't have this problem |
| 506 | // if we have any message (can be a draft) in all chats. |
| 507 | // Instead of setting drafts for chat_id1 and chat_id3, we could also sleep |
| 508 | // 2s here. |
| 509 | for chat_id in &[chat_id1, chat_id3, chat_id2] { |
| 510 | let mut msg = Message::new_text("hello".to_string()); |
| 511 | chat_id.set_draft(bob, Some(&mut msg)).await.unwrap(); |
| 512 | } |
| 513 | |
| 514 | let chats = Chatlist::try_load(bob, 0, None, None).await.unwrap(); |
| 515 | assert_eq!(chats.get_chat_id(0).unwrap(), chat_id2); |
| 516 | |
| 517 | // check chatlist query and archive functionality |
| 518 | let chats = Chatlist::try_load(bob, 0, Some("b"), None).await.unwrap(); |
| 519 | assert_eq!(chats.len(), 1); |
| 520 | |
| 521 | // receive a message from alice |
| 522 | let alice = &tcm.alice().await; |
| 523 | let alice_chat_id = create_group(alice, "alice chat").await.unwrap(); |
| 524 | add_contact_to_chat( |
| 525 | alice, |
| 526 | alice_chat_id, |
| 527 | alice.add_or_lookup_contact_id(bob).await, |
| 528 | ) |
| 529 | .await |
| 530 | .unwrap(); |
| 531 | send_text_msg(alice, alice_chat_id, "hi".into()) |
| 532 | .await |
| 533 | .unwrap(); |
| 534 | let sent_msg = alice.pop_sent_msg().await; |
| 535 | |
| 536 | bob.recv_msg(&sent_msg).await; |
| 537 | let chats = Chatlist::try_load(bob, 0, Some("is:unread"), None) |
| 538 | .await |
| 539 | .unwrap(); |
| 540 | assert_eq!(chats.len(), 1); |
| 541 | |
| 542 | let chats = Chatlist::try_load(bob, DC_GCL_ARCHIVED_ONLY, None, None) |
nothing calls this directly
no test coverage detected