//! The ids a Cotton conversation's rows are made under, so every one of the //! owner's phones that lands the same message writes the same row, and a //! conversation with one number is one thread on all of them. /// The thread with one number. pub fn thread_id(namespace: &str, number: &str) -> String { cotton_rules::ids::derived_id("cotton_msg_threads", &[namespace, super::CHANNEL, number]) } /// The chat's contact: the number as Messages knows it. pub fn contact_id(namespace: &str, number: &str) -> String { cotton_rules::ids::derived_id("cotton_msg_contacts", &[namespace, super::CHANNEL, number]) } /// Who wrote the owner's own messages, as their ids are made: never a number, /// so another person cannot name an id that lands on one of the owner's rows. pub const ME: &str = "me"; /// One message, by the id its writer gave it and who wrote it: [`ME`], or the /// other person's number. pub fn message_id(namespace: &str, author: &str, id: &str) -> String { cotton_rules::ids::derived_id("cotton_msg_messages", &[namespace, super::CHANNEL, author, id]) } /// The marker that stands for a message of `channel` the person's own timer /// erased (CONTRACT.md "WhatsApp through the Mac"): one per (thread, channel, /// the channel's own id), so every phone that sweeps it writes the same row. pub fn erased_marker_id(thread: &str, channel: &str, external_id: &str) -> String { cotton_rules::ids::derived_id("cotton_msg_messages", &["erased", thread, channel, external_id]) } /// The thread's external key: how a Cotton conversation is found again by its number. pub fn external_key(number: &str) -> String { format!("cotton:{number}") } /// Whether a thread's external key is a Cotton conversation's. pub fn is_cotton_key(key: &str) -> bool { key.starts_with("cotton:+") } /// The number a Cotton conversation's external key names. pub fn number_of_key(key: &str) -> Option<&str> { key.strip_prefix("cotton:").filter(|n| n.starts_with('+')) }