Cotton code
39 lines · 1.7 KB · RustRaw
//! The two stable WhatsApp identities an import keys a conversation by: the//! thread id a run derives when it has to create a thread, and a group's//! import key. The linked-device reader, statuses and profile pictures all key//! by these, so the same conversation lands in the same thread whichever of//! them reads it first.use cotton_store::file_identity::Namespace;use cotton_store::protocol::derived_id::derived_id;/// The thread id this run would use IF it had to create the thread.////// Derived from the chat's own identity, so the same conversation gets the/// same id on every pass — which is what stops a chat that resolves by nothing/// else (a group whose key changed, a dm whose counterpart is only a label)/// from landing in a fresh thread on each import. The `whatsapp-ios-backup`/// seed is the one every existing thread was derived under; changing it would/// split every conversation in two.pub fn whatsapp_thread_id(namespace: &Namespace, identity: &str) -> String {    derived_id(        "cotton_msg_threads",        &[namespace.as_str(), "whatsapp-ios-backup", identity],    )}/// The stable import identity of a group: its JID, which never changes.////// DELIBERATELY NOT `group_external_key(title)`, the slug the `_chat.txt`/// route derives. A title changes the day somebody renames the group, and the/// whole job of this key is to be the thing a re-import finds the thread by./// A `_chat.txt` export carries no JID, so the import engine joins the two by/// title (`agree_group_key`): a JID-keyed batch takes over the export's thread/// and re-keys it to the JID.pub fn whatsapp_group_key(jid: &str) -> String {    format!("wa:group:{jid}")}#[cfg(test)]#[path = "whatsapp_keys_tests.rs"]mod tests;