Cotton code
37 lines · 2.3 KB · RustRaw
//! `developer.revokeWhatsapp` — COTTON DEV ONLY: a delete for everyone the Mac's link would report, landed on this//! phone's copy by the same changes pass the Mac runs (cotton-rules `plan_message_changes`, through//! `cotton_client::messages_import::apply_message_changes`), for a hand walk of "deleted in WhatsApp means deleted in//! Cotton" on an emulator with no Mac (FEEDBACK-3, 23 Nov 2026). The real Cotton refuses it by name.//!//! ```text//! developer.revokeWhatsapp { externalIds: [<WhatsApp id>, …] } → { revoked, missing }//! ```//!//! The sweep that erases the message runs as the chats are next read (`phone::chat_revoked`).use serde_json::{json, Value};use crate::handle::CottonHandle;use crate::methods::MethodError;pub fn revoke(handle: &CottonHandle, request: &Value) -> Result<Value, MethodError> {    if handle.flavor() != cotton_core::flavor::Flavor::Dev {        return Err(MethodError::new("not_dev", "developer.revokeWhatsapp answers only in Cotton Dev"));    }    let ids: Vec<String> = request["externalIds"].as_array().into_iter().flatten().filter_map(|v| v.as_str().map(str::to_string)).collect();    if ids.is_empty() {        return Err(MethodError::new("bad_request", "externalIds names the WhatsApp ids deleted for everyone"));    }    let client = handle.client();    let workspace = super::cotton_chat::read(&client, "developer.revokeWhatsapp", |ctx| Ok(json!(ctx.workspace_id)))?;    let workspace = workspace.as_str().unwrap_or_default().to_string();    let at = super::cotton_chat::iso(super::cotton_chat::now_ms(&client));    let changes: Vec<cotton_core::import::messages_engine::MessageChange> =        ids.iter().map(|id| cotton_core::import::messages_engine::MessageChange::Revoke { external_id: id.clone(), at: at.clone() }).collect();    client        .import_rows("developer.revokeWhatsapp", &["cotton_msg_threads", "cotton_msg_messages", "cotton_msg_thread_participants", "cotton_msg_contacts", "cotton_msg_reactions", "cotton_workspaces"], &mut |seams| {            let report = cotton_client::messages_import::apply_message_changes(&seams.replica.driver, &workspace, "whatsapp", &changes, seams.clock, seams.ids).map_err(|e| e.to_string())?;            Ok(json!({ "revoked": report.revoked, "missing": report.missing }))        })        .map_err(|why| MethodError::new("not_landed", why))}