//! What HUD keeps of a person, and its deletion, theirs alone to ask: the //! canvases they own, their place in others' and the tiles they put //! there, their invitations and tabs (`canvas`), the `place.hud.theme` //! records in their own repository and their choice of theme (`theme`). //! Deleting it goes past each failure, all else done; only once nothing //! is left does every session of theirs end (`sign_out_everywhere`), so a //! failure leaves them signed in, to ask again. use crate::Hud; use crate::canvas::{Holding, Who}; use crate::oauth::Account; /// What HUD keeps of a person. #[derive(Debug, PartialEq)] pub struct Kept { pub canvases: Holding, /// Their `place.hud.theme` records. pub themes: usize, /// Whether a choice of theme is kept. pub chosen: bool, } fn who(account: &Account) -> Who<'_> { Who { did: &account.did, handle: account.handle.as_deref(), } } impl Hud { /// What HUD keeps of `account`'s. Their themes are counted as their /// repository lists them: none where it cannot be read, which /// deleting them would then say. pub async fn kept(&self, account: &Account) -> Kept { let themes = match self.own_themes(&account.did).await { Ok(uris) => uris.len(), Err(e) => { tracing::warn!(did = account.did, error = ?e, "a person's themes were not counted"); 0 } }; Kept { canvases: self.canvases.holding(who(account)).await, themes, chosen: self.themes.kept(&account.did), } } /// Delete everything HUD keeps of `account`'s, then end every session /// of theirs: how many canvases, tiles, memberships and records went. /// Else what was not deleted, all else done, every session left on. pub async fn delete_account_data(&self, account: &Account) -> Result { let did = account.did.as_str(); let mut failed: Vec = Vec::new(); let mut deleted = match self.canvases.forget(who(account)).await { Ok(n) => n, Err(e) => { failed.push(e); 0 } }; let (themes, lines) = self.forget_themes(account).await; deleted += themes; failed.extend(lines); if self.themes.kept(did) { match self.themes.set(did, None) { Ok(()) => deleted += 1, Err(e) => failed.push(format!("your theme choice: {e}")), } } if !failed.is_empty() { let failures = failed.len(); tracing::warn!(did, deleted, failures, "a person's data not all deleted"); return Err(format!( "Not everything was deleted; ask again to carry on: {}", failed.join("; ") )); } let sessions = self.sign_out_everywhere(did).await; tracing::info!(did, deleted, sessions, "a person's data deleted"); Ok(deleted) } }