diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-09-04 08:04:48 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-09-04 13:30:59 +0100 |
| commit | 949c6459aa7683453a7160423b689ceadb08954b (patch) | |
| tree | 230c26ecb11b99916e5570e548673eb09ecf0a36 /src/config.rs | |
| parent | a825311f2c55661aaab3a163bda9109295c96044 (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/config.rs')
| -rw-r--r-- | src/config.rs | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/src/config.rs b/src/config.rs deleted file mode 100644 index 547fe7e..0000000 --- a/src/config.rs +++ /dev/null | |||
| @@ -1,47 +0,0 @@ | |||
| 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 | } | ||