//! A Records thread's two acts, run as the thread's definition commands //! (`records.recordAsTransaction`, `records.addToCalendar`): the record and //! its link to the thread are written in ONE write here, by //! `cotton_tools::mcp::handlers::emails::record_acts`, which says what each //! act does and refuses. use serde_json::Value; use crate::handle::CottonHandle; use crate::methods::MethodError; pub const RECORD_AS_TRANSACTION: &str = "records.recordAsTransaction"; pub const ADD_TO_CALENDAR: &str = "records.addToCalendar"; /// The command methods' door: `{threadId}` bound to the thread's id. pub(crate) fn call(handle: &CottonHandle, method: &str, request: &Value) -> Result { use cotton_tools::mcp::handlers::emails::record_acts; let thread = super::owner::text(request, "threadId")?; let act: fn(&mut cotton_tools::mcp::dispatch::Ctx<'_>, &str) -> Result = match method { RECORD_AS_TRANSACTION => record_acts::record_as_transaction, ADD_TO_CALENDAR => record_acts::add_to_calendar, _ => return Err(MethodError::new("write_refused", format!("`{method}` is not a Records act"))), }; let answer = handle .client() .write_rows(method, &mut |ctx| act(ctx, &thread).map_err(|failure| failure.to_string())) .map_err(|error| MethodError::new("write_refused", error))?; Ok(crate::authoring::own_answer(answer)) }