lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README | LICENSE

model.rs (1717B)


      1 use radroots_identity::{RadrootsIdentityId, RadrootsIdentityPublic};
      2 use serde::{Deserialize, Serialize};
      3 
      4 pub const RADROOTS_NOSTR_ACCOUNTS_STORE_VERSION: u32 = 2;
      5 
      6 #[derive(Debug, Clone, Serialize, Deserialize)]
      7 pub struct RadrootsNostrAccountRecord {
      8     pub account_id: RadrootsIdentityId,
      9     pub public_identity: RadrootsIdentityPublic,
     10     #[serde(skip_serializing_if = "Option::is_none")]
     11     pub label: Option<String>,
     12     pub created_at_unix: u64,
     13     pub updated_at_unix: u64,
     14 }
     15 
     16 #[derive(Debug, Clone, Serialize, Deserialize)]
     17 pub struct RadrootsNostrAccountStoreState {
     18     pub version: u32,
     19     #[serde(alias = "selected_account_id")]
     20     pub default_account_id: Option<RadrootsIdentityId>,
     21     pub accounts: Vec<RadrootsNostrAccountRecord>,
     22 }
     23 
     24 #[derive(Debug, Clone)]
     25 pub enum RadrootsNostrAccountStatus {
     26     NotConfigured,
     27     PublicOnly { account: RadrootsNostrAccountRecord },
     28     Ready { account: RadrootsNostrAccountRecord },
     29 }
     30 
     31 impl Default for RadrootsNostrAccountStoreState {
     32     fn default() -> Self {
     33         Self {
     34             version: RADROOTS_NOSTR_ACCOUNTS_STORE_VERSION,
     35             default_account_id: None,
     36             accounts: Vec::new(),
     37         }
     38     }
     39 }
     40 
     41 impl RadrootsNostrAccountRecord {
     42     pub fn new(
     43         public_identity: RadrootsIdentityPublic,
     44         label: Option<String>,
     45         created_at_unix: u64,
     46     ) -> Self {
     47         let account_id = public_identity.id.clone();
     48         Self {
     49             account_id,
     50             public_identity,
     51             label,
     52             created_at_unix,
     53             updated_at_unix: created_at_unix,
     54         }
     55     }
     56 
     57     pub fn touch_updated(&mut self, updated_at_unix: u64) {
     58         self.updated_at_unix = updated_at_unix;
     59     }
     60 }