acks
This commit is contained in:
1 parent
10af480218
commit
47b73e6935
11 files changed
+470
-28
No files matched your search
@@ -55,6 +55,22 @@ async fn client(dir: &std::path::Path, name: &str, servers: &[String]) -> MeowCl
|
||||
c
|
||||
}
|
||||
|
||||
fn no_receipts(events: Vec<Event>) -> Vec<Event> {
|
||||
events
|
||||
.into_iter()
|
||||
.filter(|e| !matches!(e, Event::Receipt { .. }))
|
||||
.collect()
|
||||
}
|
||||
|
||||
async fn no_receipt_settings(c: &mut MeowClient) {
|
||||
c.set_settings(meow_client::Settings {
|
||||
delivered_receipts: false,
|
||||
read_receipts: false,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn texts(events: &[Event]) -> Vec<String> {
|
||||
events
|
||||
.iter()
|
||||
@@ -139,16 +155,16 @@ async fn file_and_server_invitations_then_messaging() {
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(who, "bob");
|
||||
let ev = bob.sync(Duration::ZERO).await.unwrap();
|
||||
let ev = no_receipts(bob.sync(Duration::ZERO).await.unwrap());
|
||||
assert_eq!(
|
||||
ev,
|
||||
vec![Event::InvitationAccepted {
|
||||
contact: "remote".into()
|
||||
}]
|
||||
);
|
||||
let ev = remote.sync(Duration::ZERO).await.unwrap();
|
||||
let ev = no_receipts(remote.sync(Duration::ZERO).await.unwrap());
|
||||
assert_eq!(ev, vec![Event::ContactActivated { contact: "bob".into() }]);
|
||||
let ev = bob.sync(Duration::ZERO).await.unwrap();
|
||||
let ev = no_receipts(bob.sync(Duration::ZERO).await.unwrap());
|
||||
assert_eq!(
|
||||
ev,
|
||||
vec![Event::ContactActivated {
|
||||
@@ -311,6 +327,9 @@ async fn no_message_lost_when_the_client_dies() {
|
||||
let servers = vec![url];
|
||||
let mut bob = client(&dir, "bob", &servers).await;
|
||||
let mut alice = client(&dir, "alice", &servers).await;
|
||||
// This test counts what stays on the server: no receipts traffic.
|
||||
no_receipt_settings(&mut bob).await;
|
||||
no_receipt_settings(&mut alice).await;
|
||||
let offer = bob.create_invitation("alice", &[], "", 3600).await.unwrap();
|
||||
let answer = alice.answer_invitation(&offer, None, &[]).await.unwrap();
|
||||
let confirm = bob.accept_answer(&answer).await.unwrap();
|
||||
@@ -350,6 +369,7 @@ async fn no_message_lost_when_the_client_dies() {
|
||||
// 3. Mailboxes that disappear still get their last messages acknowledged:
|
||||
// the temporary answer mailbox of a server invitation...
|
||||
let mut carol = client(&dir, "carol", &servers).await;
|
||||
no_receipt_settings(&mut carol).await;
|
||||
let link = bob.publish_invitation("carol", &[], "", "", 3600).await.unwrap();
|
||||
carol.accept_published_invitation(&link, "", None, &[]).await.unwrap();
|
||||
bob.sync(Duration::ZERO).await.unwrap(); // step 2 → 3, answer mailbox retired
|
||||
@@ -515,3 +535,83 @@ async fn offline_messages_are_queued_and_retried() {
|
||||
assert!(bob.pending_sends().is_empty());
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
// ───────────── receipts (roadmap lot 5.6) ─────────────
|
||||
|
||||
fn statuses(c: &MeowClient, name: &str, outbound: bool) -> Vec<meow_client::Status> {
|
||||
c.history(name)
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter(|h| h.outbound == outbound)
|
||||
.map(|h| h.status)
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn delivery_and_read_receipts() {
|
||||
use meow_client::{ReceiptKind, Settings, Status};
|
||||
let servers = vec![spawn_server().await, spawn_server().await];
|
||||
let dir = tmpdir();
|
||||
let mut alice = client(&dir, "alice", &servers).await;
|
||||
let mut bob = client(&dir, "bob", &servers).await;
|
||||
connect(&mut alice, &mut bob, "bob").await;
|
||||
bob.sync(Duration::ZERO).await.unwrap();
|
||||
|
||||
let m1 = alice.send_text("bob", "one").await.unwrap().message_id;
|
||||
let m2 = alice.send_text("bob", "two").await.unwrap().message_id;
|
||||
assert_eq!(statuses(&alice, "bob", true), vec![Status::Sent, Status::Sent]);
|
||||
|
||||
// Bob receives (from 2 servers, processed once): one delivery receipt.
|
||||
assert_eq!(texts(&bob.sync(Duration::ZERO).await.unwrap()), vec!["one", "two"]);
|
||||
assert_eq!(
|
||||
statuses(&bob, "alice", false),
|
||||
vec![Status::Delivered, Status::Delivered]
|
||||
);
|
||||
let ev = alice.sync(Duration::ZERO).await.unwrap();
|
||||
assert_eq!(
|
||||
ev,
|
||||
vec![Event::Receipt {
|
||||
contact: "bob".into(),
|
||||
kind: ReceiptKind::Delivered,
|
||||
message_ids: vec![m1.clone(), m2.clone()]
|
||||
}]
|
||||
);
|
||||
assert_eq!(
|
||||
statuses(&alice, "bob", true),
|
||||
vec![Status::Delivered, Status::Delivered]
|
||||
);
|
||||
|
||||
// Bob reads.
|
||||
assert_eq!(bob.mark_read("alice").await.unwrap(), 2);
|
||||
assert_eq!(bob.mark_read("alice").await.unwrap(), 0);
|
||||
assert_eq!(statuses(&bob, "alice", false), vec![Status::Read, Status::Read]);
|
||||
let ev = alice.sync(Duration::ZERO).await.unwrap();
|
||||
assert_eq!(
|
||||
ev,
|
||||
vec![Event::Receipt {
|
||||
contact: "bob".into(),
|
||||
kind: ReceiptKind::Read,
|
||||
message_ids: vec![m1, m2]
|
||||
}]
|
||||
);
|
||||
assert_eq!(statuses(&alice, "bob", true), vec![Status::Read, Status::Read]);
|
||||
// Receipts are not acknowledged by receipts.
|
||||
assert!(bob.sync(Duration::ZERO).await.unwrap().is_empty());
|
||||
|
||||
// Receipts can be turned off (persisted with the identity).
|
||||
let off = Settings {
|
||||
delivered_receipts: false,
|
||||
read_receipts: false,
|
||||
};
|
||||
bob.set_settings(off).await.unwrap();
|
||||
let path = dir.join("bob.mwid2");
|
||||
drop(bob);
|
||||
let mut bob = MeowClient::open(&path, "pw").await.unwrap();
|
||||
assert_eq!(bob.settings(), off);
|
||||
alice.send_text("bob", "three").await.unwrap();
|
||||
assert_eq!(texts(&bob.sync(Duration::ZERO).await.unwrap()), vec!["three"]);
|
||||
assert_eq!(bob.mark_read("alice").await.unwrap(), 1);
|
||||
assert!(alice.sync(Duration::ZERO).await.unwrap().is_empty());
|
||||
assert_eq!(statuses(&alice, "bob", true)[2], Status::Sent);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
Reference in new issue
Block a user