diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-09-04 16:44:43 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-09-04 17:01:07 +0100 |
| commit | c4c262a5e9bfeb30bc0106d9ea51dfce7e4fa1f3 (patch) | |
| tree | d02ba9ab1d461147c6ae2ae5e98e785c553a999f /src/lib | |
| parent | 90c53e2dc859b47615ebaa08199b7460615ce3e4 (diff) | |
refactor(remote): split into modules
to make it easier to read
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/client.rs | 12 | ||||
| -rw-r--r-- | src/lib/git_events.rs | 15 | ||||
| -rw-r--r-- | src/lib/login/mod.rs | 14 |
3 files changed, 40 insertions, 1 deletions
diff --git a/src/lib/client.rs b/src/lib/client.rs index ace880b..c29d4b9 100644 --- a/src/lib/client.rs +++ b/src/lib/client.rs | |||
| @@ -38,6 +38,7 @@ use nostr_sqlite::SQLiteDatabase; | |||
| 38 | 38 | ||
| 39 | use crate::{ | 39 | use crate::{ |
| 40 | get_dirs, | 40 | get_dirs, |
| 41 | git::{Repo, RepoActions}, | ||
| 41 | git_events::{ | 42 | git_events::{ |
| 42 | event_is_cover_letter, event_is_patch_set_root, event_is_revision_root, status_kinds, | 43 | event_is_cover_letter, event_is_patch_set_root, event_is_revision_root, status_kinds, |
| 43 | }, | 44 | }, |
| @@ -1572,6 +1573,17 @@ pub async fn get_all_proposal_patch_events_from_cache( | |||
| 1572 | .collect()) | 1573 | .collect()) |
| 1573 | } | 1574 | } |
| 1574 | 1575 | ||
| 1576 | pub async fn get_event_from_cache_by_id(git_repo: &Repo, event_id: &EventId) -> Result<Event> { | ||
| 1577 | Ok(get_events_from_cache( | ||
| 1578 | git_repo.get_path()?, | ||
| 1579 | vec![nostr::Filter::default().id(*event_id)], | ||
| 1580 | ) | ||
| 1581 | .await? | ||
| 1582 | .first() | ||
| 1583 | .context("cannot find event in cache")? | ||
| 1584 | .clone()) | ||
| 1585 | } | ||
| 1586 | |||
| 1575 | #[allow(clippy::module_name_repetitions)] | 1587 | #[allow(clippy::module_name_repetitions)] |
| 1576 | #[allow(clippy::too_many_lines)] | 1588 | #[allow(clippy::too_many_lines)] |
| 1577 | pub async fn send_events( | 1589 | pub async fn send_events( |
diff --git a/src/lib/git_events.rs b/src/lib/git_events.rs index 8689b33..2e9f797 100644 --- a/src/lib/git_events.rs +++ b/src/lib/git_events.rs | |||
| @@ -3,7 +3,7 @@ use std::str::FromStr; | |||
| 3 | use anyhow::{bail, Context, Result}; | 3 | use anyhow::{bail, Context, Result}; |
| 4 | use nostr::nips::{nip01::Coordinate, nip10::Marker, nip19::Nip19}; | 4 | use nostr::nips::{nip01::Coordinate, nip10::Marker, nip19::Nip19}; |
| 5 | use nostr_sdk::{ | 5 | use nostr_sdk::{ |
| 6 | hashes::sha1::Hash as Sha1Hash, Event, EventBuilder, FromBech32, Kind, Tag, TagKind, | 6 | hashes::sha1::Hash as Sha1Hash, Event, EventBuilder, EventId, FromBech32, Kind, Tag, TagKind, |
| 7 | TagStandard, UncheckedUrl, | 7 | TagStandard, UncheckedUrl, |
| 8 | }; | 8 | }; |
| 9 | use nostr_signer::NostrSigner; | 9 | use nostr_signer::NostrSigner; |
| @@ -37,6 +37,19 @@ pub fn get_commit_id_from_patch(event: &Event) -> Result<String> { | |||
| 37 | } | 37 | } |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | pub fn get_event_root(event: &nostr::Event) -> Result<EventId> { | ||
| 41 | Ok(EventId::parse( | ||
| 42 | event | ||
| 43 | .tags() | ||
| 44 | .iter() | ||
| 45 | .find(|t| t.is_root()) | ||
| 46 | .context("no thread root in event")? | ||
| 47 | .as_vec() | ||
| 48 | .get(1) | ||
| 49 | .unwrap(), | ||
| 50 | )?) | ||
| 51 | } | ||
| 52 | |||
| 40 | pub fn status_kinds() -> Vec<Kind> { | 53 | pub fn status_kinds() -> Vec<Kind> { |
| 41 | vec![ | 54 | vec![ |
| 42 | Kind::GitStatusOpen, | 55 | Kind::GitStatusOpen, |
diff --git a/src/lib/login/mod.rs b/src/lib/login/mod.rs index 7364edf..938a6f1 100644 --- a/src/lib/login/mod.rs +++ b/src/lib/login/mod.rs | |||
| @@ -696,3 +696,17 @@ pub async fn get_user_ref_from_cache( | |||
| 696 | relays: extract_user_relays(public_key, &events), | 696 | relays: extract_user_relays(public_key, &events), |
| 697 | }) | 697 | }) |
| 698 | } | 698 | } |
| 699 | |||
| 700 | pub fn get_curent_user(git_repo: &Repo) -> Result<Option<PublicKey>> { | ||
| 701 | Ok( | ||
| 702 | if let Some(npub) = git_repo.get_git_config_item("nostr.npub", None)? { | ||
| 703 | if let Ok(public_key) = PublicKey::parse(npub) { | ||
| 704 | Some(public_key) | ||
| 705 | } else { | ||
| 706 | None | ||
| 707 | } | ||
| 708 | } else { | ||
| 709 | None | ||
| 710 | }, | ||
| 711 | ) | ||
| 712 | } | ||