upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/lib/login/user.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-09-04 08:04:48 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2024-09-04 13:30:59 +0100
commit949c6459aa7683453a7160423b689ceadb08954b (patch)
tree230c26ecb11b99916e5570e548673eb09ecf0a36 /src/lib/login/user.rs
parenta825311f2c55661aaab3a163bda9109295c96044 (diff)
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
Diffstat (limited to 'src/lib/login/user.rs')
-rw-r--r--src/lib/login/user.rs47
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 @@
1use anyhow::{anyhow, Result};
2use directories::ProjectDirs;
3use nostr::PublicKey;
4use nostr_sdk::Timestamp;
5use serde::{self, Deserialize, Serialize};
6
7pub 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)]
14pub 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)]
21pub struct UserMetadata {
22 pub name: String,
23 pub created_at: Timestamp,
24}
25
26#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
27pub struct UserRelays {
28 pub relays: Vec<UserRelayRef>,
29 pub created_at: Timestamp,
30}
31
32impl 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)]
43pub struct UserRelayRef {
44 pub url: String,
45 pub read: bool,
46 pub write: bool,
47}