diff options
Diffstat (limited to 'src/lib/login/user.rs')
| -rw-r--r-- | src/lib/login/user.rs | 47 |
1 files changed, 47 insertions, 0 deletions
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 @@ | |||
| 1 | use anyhow::{anyhow, Result}; | ||
| 2 | use directories::ProjectDirs; | ||
| 3 | use nostr::PublicKey; | ||
| 4 | use nostr_sdk::Timestamp; | ||
| 5 | use serde::{self, Deserialize, Serialize}; | ||
| 6 | |||
| 7 | pub fn get_dirs() -> Result<ProjectDirs> { | ||
| 8 | ProjectDirs::from("", "", "ngit").ok_or(anyhow!( | ||
| 9 | "should find operating system home directories with rust-directories crate" | ||
| 10 | )) | ||
| 11 | } | ||
| 12 | |||
| 13 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] | ||
| 14 | pub struct UserRef { | ||
| 15 | pub public_key: PublicKey, | ||
| 16 | pub metadata: UserMetadata, | ||
| 17 | pub relays: UserRelays, | ||
| 18 | } | ||
| 19 | |||
| 20 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] | ||
| 21 | pub struct UserMetadata { | ||
| 22 | pub name: String, | ||
| 23 | pub created_at: Timestamp, | ||
| 24 | } | ||
| 25 | |||
| 26 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] | ||
| 27 | pub struct UserRelays { | ||
| 28 | pub relays: Vec<UserRelayRef>, | ||
| 29 | pub created_at: Timestamp, | ||
| 30 | } | ||
| 31 | |||
| 32 | impl UserRelays { | ||
| 33 | pub fn write(&self) -> Vec<String> { | ||
| 34 | self.relays | ||
| 35 | .iter() | ||
| 36 | .filter(|r| r.write) | ||
| 37 | .map(|r| r.url.clone()) | ||
| 38 | .collect() | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] | ||
| 43 | pub struct UserRelayRef { | ||
| 44 | pub url: String, | ||
| 45 | pub read: bool, | ||
| 46 | pub write: bool, | ||
| 47 | } | ||