Cotton code
60 lines · 2.3 KB · RustRaw
//! What a source can really do. RULE (owner, 19 Nov 2026): only that is//! offered. Imported WhatsApp and SMS threads are read as they are; a reply//! field appears only where Cotton can really send. Cotton-to-Cotton gets//! everything. A conversation's own organisation (pin, mute, archive, read)//! is the owner's copy and works everywhere; a message's pin and a forward//! into a Cotton chat are the owner's too./// What one conversation offers.#[derive(Debug, Clone, Copy, PartialEq, Eq)]pub struct Can {    pub send: bool,    pub reply: bool,    pub react: bool,    pub edit: bool,    pub delete: bool,    pub voice: bool,    pub attach: bool,    pub typing: bool,}impl Can {    /// Cotton chats, and a source that sends through its bound account    /// (`sendable` on the thread's row): send and reply only.    pub fn of(source: &str, sendable: bool) -> Can {        match source {            "cotton" => Can { send: true, reply: true, react: true, edit: true, delete: true, voice: true, attach: true, typing: true },            _ if sendable => Can { send: true, reply: true, react: false, edit: false, delete: false, voice: false, attach: false, typing: false },            _ => Can { send: false, reply: false, react: false, edit: false, delete: false, voice: false, attach: false, typing: false },        }    }    /// A long press's acts on one message, in the menu's order. `mine`    /// gates edit; `editable` is the edit window still open; a deleted    /// message offers nothing but select.    pub fn message_actions(&self, mine: bool, editable: bool, deleted: bool, pinned: bool, has_text: bool) -> Vec<String> {        if deleted {            return vec!["select".into()];        }        let mut acts: Vec<&str> = Vec::new();        if self.reply {            acts.push("reply");        }        if self.react {            acts.push("react");        }        if has_text {            acts.push("copy");        }        acts.push("forward");        if self.edit && mine && editable && has_text {            acts.push("edit");        }        acts.push(if pinned { "unpin" } else { "pin" });        if self.delete && mine {            acts.push("delete");        }        acts.push("select");        acts.into_iter().map(str::to_string).collect()    }}