From 949c6459aa7683453a7160423b689ceadb08954b Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 4 Sep 2024 08:04:48 +0100 Subject: refactor: organise into lib and bin structure the make the code more readable this commit just moves the files, the next commit should fix the imports --- src/lib/login/user.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/lib/login/user.rs (limited to 'src/lib/login/user.rs') diff --git a/src/lib/login/user.rs b/src/lib/login/user.rs new file mode 100644 index 0000000..547fe7e --- /dev/null +++ b/src/lib/login/user.rs @@ -0,0 +1,47 @@ +use anyhow::{anyhow, Result}; +use directories::ProjectDirs; +use nostr::PublicKey; +use nostr_sdk::Timestamp; +use serde::{self, Deserialize, Serialize}; + +pub fn get_dirs() -> Result { + ProjectDirs::from("", "", "ngit").ok_or(anyhow!( + "should find operating system home directories with rust-directories crate" + )) +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] +pub struct UserRef { + pub public_key: PublicKey, + pub metadata: UserMetadata, + pub relays: UserRelays, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] +pub struct UserMetadata { + pub name: String, + pub created_at: Timestamp, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] +pub struct UserRelays { + pub relays: Vec, + pub created_at: Timestamp, +} + +impl UserRelays { + pub fn write(&self) -> Vec { + self.relays + .iter() + .filter(|r| r.write) + .map(|r| r.url.clone()) + .collect() + } +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] +pub struct UserRelayRef { + pub url: String, + pub read: bool, + pub write: bool, +} -- cgit v1.2.3