//! WhatsApp from the phone. The linked numbers and a thread's history go//! through the owner routes of `cotton-server/src/routes/whatsapp.rs`, one//! method each.//!//! Sending a text is Comms' (`chat.act send` in a WhatsApp chat: an outbox row//! the Mac drains, `phone/chat_whatsapp.rs`), never a method here.use serde_json::{json, Value};use cotton_client::transport::{ClientRequest, ServerFetch};usecrate::handle::CottonHandle;usecrate::methods::MethodError;usecrate::phone::owner;pubconst METHODS: [&str; 3] = ["whatsapp.accounts","whatsapp.history","whatsapp.unlink",];pubfn call(handle: &CottonHandle, method: &str, request: &Value) -> Result<Value, MethodError> { owner::with_fetch(handle, |fetch| over(fetch, method, request))}pubfn over(fetch: &dynServerFetch, method: &str, request: &Value) -> Result<Value, MethodError> {match method {"whatsapp.accounts" => owner::send(fetch, ClientRequest::get("/v1/whatsapp/accounts")),// `{ threadId, count? }` — ask the linked number's phone for what came// before the oldest message this thread holds from it."whatsapp.history" => {let thread = owner::text(request, "threadId")?;letmut body = json!({ "threadId": thread });ifletSome(count) = request.get("count").and_then(Value::as_u64) { body["count"] = json!(count); } owner::send(fetch, owner::post("/v1/whatsapp/history".to_string(), &body)) }"whatsapp.unlink" => {let account = owner::text(request, "account")?; owner::send( fetch, owner::delete(format!("/v1/whatsapp/accounts/{}", owner::segment(&account) )), ) } other => Err(MethodError::new("unknown_method", format!("{other} is not a WhatsApp method"), )), }}