//! Take notes on a GROUP call (owner, 23 Nov 2026; chat CONTRACT.md "Take notes", "Group calls"): the group's own call //! on the SFU, one track per person named from the member, everyone told by the room's mark, and the recording kept as //! the call's, as a one-to-one call's is. Invented people. use super::*; fn dispatch(handle: &CottonHandle, method: &str, request: Value) -> Value { crate::methods::dispatch(handle, method, &request).unwrap_or_else(|error| panic!("{method}: {} {}", error.code, error.message)) } fn effect(answer: &Value, does: &str) -> Value { answer["effects"].as_array().into_iter().flatten().find(|e| e["do"] == does).cloned().unwrap_or_else(|| panic!("no {does}: {answer}")) } #[test] fn a_groups_call_takes_notes_a_track_per_person_named_from_the_member() { let dir = tempfile::tempdir().unwrap(); let handle = crate::phone::chat_app::mail::tests::comms(&dir, cotton_core::flavor::Flavor::Real); let group = family(&handle); with_door(&handle, [Reply::ok(&json!({"room": ROOM, "credential": format!("ccr_{ROOM}_secret"), "mode": "sfu", "group": GROUP, "iceServers": [], "ttl": 3600, "ringFor": 45, "me": "m0"}).to_string())]); let placed = answer(&handle, "chat.call", json!({"thread": group, "video": false, "can": ["notes"]})); assert_eq!(placed["call"]["mode"], "sfu"); let member = |id: &str, number: &str, notes: bool| json!({"id": id, "number": number, "state": "joined", "notes": notes, "can": ["notes"]}); let me = placed["call"]["me"].as_str().unwrap_or("m0").to_string(); calls(&handle, "calls.signal", json!({"in": {"t": "roster", "members": [member(&me, "+15550100000", false), member("m1", ASHA, false), member("m2", RAVI, false)]}})); calls(&handle, "calls.signal", json!({"in": {"t": "state", "state": "connecting"}})); calls(&handle, "calls.media", json!({"state": "connected"})); let screen = answer(&handle, "chat.callScreen", json!({})); assert!(screen["controls"].as_array().unwrap().iter().any(|c| c["id"] == "notes"), "Take notes offered on the group's call: {screen}"); let asked = calls(&handle, "calls.notes", json!({"on": true})); assert_eq!(asked["effects"], json!([{"do": "send", "frame": {"t": "notes", "on": true}}]), "a tap only asks the room"); let told = calls(&handle, "calls.signal", json!({"in": {"t": "member", "member": member(&me, "+15550100000", true)}})); let start = effect(&told, "notes_start"); let tracks: Vec<(String, Option)> = start["tracks"].as_array().unwrap().iter().map(|t| (t["track"].as_str().unwrap().to_string(), t["name"].as_str().map(str::to_string))).collect(); assert_eq!(tracks, [("me".to_string(), None), ("m1".to_string(), Some("Asha Example".to_string())), ("m2".to_string(), Some("Ravi Example".to_string()))], "{start}"); let screen = answer(&handle, "chat.callScreen", json!({})); assert_eq!(screen["notes"]["line"], "You are taking notes", "everyone's mark, his own too: {screen}"); let meeting = start["meeting"].as_str().unwrap().to_string(); let stopped = calls(&handle, "calls.notes", json!({"on": false})); let off = if stopped["effects"].as_array().unwrap().iter().any(|e| e["do"] == "notes_stop") { stopped } else { calls(&handle, "calls.signal", json!({"in": {"t": "member", "member": member(&me, "+15550100000", false)}})) }; let stop = effect(&off, "notes_stop"); let mut files = Vec::new(); for t in stop["tracks"].as_array().unwrap() { let path = std::path::PathBuf::from(t["path"].as_str().unwrap()); std::fs::create_dir_all(path.parent().unwrap()).unwrap(); std::fs::write(&path, [0xFF, 0xF1, 0x60, 0x40, 0x01, 0x7F, 0xFC, 0, 0, 0, 0].repeat(40)).unwrap(); files.push(json!({ "track": t["track"], "path": path.to_string_lossy() })); } assert_eq!(dispatch(&handle, "meetings.record.stop", json!({ "id": meeting, "tracks": files, "duration_ms": 60_000 }))["status"], "waiting"); let window = |start: i64, text: &str| json!([{ "index": 0, "start_ms": 0, "end_ms": 60_000, "lines": [{ "speaker": "S1", "start_ms": start, "end_ms": start + 2_000, "text": text, "language": "en" }] }]); dispatch(&handle, "meetings.transcribed", json!({ "id": meeting, "by": "phone:test", "tracks": [ { "track": "me", "windows": window(1_000, "Who brings the tent?") }, { "track": "m1", "windows": window(3_000, "I will.") }, { "track": "m2", "windows": window(6_000, "And I the stove.") }, ] })); let page = dispatch(&handle, "chat.recording", json!({ "id": meeting })); let said: Vec<(String, String)> = page["lines"].as_array().unwrap().iter().map(|l| (l["name"].as_str().unwrap_or_default().to_string(), l["text"].as_str().unwrap().to_string())).collect(); assert_eq!(said[0], ("You".to_string(), "Who brings the tent?".to_string()), "his own voice is You, never \"Speaker me\": {page}"); assert_eq!(said[1..], [("Asha Example".to_string(), "I will.".to_string()), ("Ravi Example".to_string(), "And I the stove.".to_string())], "{page}"); assert_eq!(page["title"], "Notes on a call in Invented Family", "a group's notes are named by the group: {page}"); calls(&handle, "calls.leave", json!({})); let rows = dispatch(&handle, "chat.calls", json!({})); assert!(rows["rows"].as_array().unwrap().iter().any(|r| r["kind"] == "call" && r["recording"] == json!(meeting)), "the notes stand on the call's row: {rows}"); }