//! One person across apps (schema v90, owner ruling 7 Oct 2026, Cotton note//! 1e50d25b): every way a person is reached is a row of//! `cotton_person_handles` — a phone, an email, an Instagram, Facebook or//! LinkedIn handle. Identity and row construction come from the store's//! shared protocol so People, imports, message ingest, and explicit schema//! moves cannot disagree; this module adds person lookups.//!//! The rules it carries://!//! - `(workspace, kind, normalised)` is unique, so a handle names at most one//! person and a sender found by it is never ambiguous.//! - A sender is linked to a person by a handle the person already carries —//! never by a name alone; an unknown handle stays unknown, and no person is//! ever made for an unknown sender.//! - Conversations are never merged across channels: a handle links a//! contact to a person, and each channel's chat stays its own row.pubuse cotton_store::protocol::person_handles::{ handle_change, normalise_handle, social_handle, HandleKind, HandleSource, HandleWrite, PERSON_HANDLES,};/// A person's handles of one kind as the JSON list `cotton_people.phones` and/// `.emails` used to be (`'[]'` when there are none), in the page's order —/// an expression a SELECT puts where the column was, so every reader keeps/// its shape. `person_id` is a column expression of the caller's own query/// (`p.id`), never a value from a caller, because it is interpolated.fn handle_list_sql(person_id: &str, kind: HandleKind) -> String { format!("(SELECT json_group_array(value) FROM (SELECT value FROM cotton_person_handles WHERE person_id = {person_id} AND kind = '{}' ORDER BY position, created_at, id))", kind.as_str() )}/// `phones` and `emails` as the two columns a person row used to carry —/// `"<list> AS phones, <list> AS emails"` for a SELECT over `cotton_people`.pubfn phones_and_emails_sql(person_id: &str) -> String { format!("{} AS phones, {} AS emails", handle_list_sql(person_id, HandleKind::Phone), handle_list_sql(person_id, HandleKind::Email) )}#[cfg(test)]#[path = "handles_tests.rs"]mod tests;