upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/client.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-07-30 14:14:59 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2024-07-30 15:24:29 +0100
commit0848d57c7654d09c3041022c231dfbbbfac17600 (patch)
tree7e1ee05dbc74ec5bbb2ee7a633e211c4fea9f8e8 /src/client.rs
parent6f64c35e57789d5731a51b46eb98a46803f072f4 (diff)
refactor: add struct `RepoState`
to more easily access state details
Diffstat (limited to 'src/client.rs')
-rw-r--r--src/client.rs22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/client.rs b/src/client.rs
index 6fce7a5..db41f99 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -37,6 +37,7 @@ use crate::{
37 config::get_dirs, 37 config::get_dirs,
38 login::{get_logged_in_user, get_user_ref_from_cache}, 38 login::{get_logged_in_user, get_user_ref_from_cache},
39 repo_ref::RepoRef, 39 repo_ref::RepoRef,
40 repo_state::RepoState,
40 sub_commands::{ 41 sub_commands::{
41 list::status_kinds, 42 list::status_kinds,
42 send::{event_is_patch_set_root, event_is_revision_root}, 43 send::{event_is_patch_set_root, event_is_revision_root},
@@ -841,17 +842,14 @@ pub async fn get_repo_ref_from_cache(
841 }) 842 })
842} 843}
843 844
844pub async fn get_state_from_cache( 845pub async fn get_state_from_cache(git_repo_path: &Path, repo_ref: &RepoRef) -> Result<RepoState> {
845 git_repo_path: &Path, 846 RepoState::try_from(
846 repo_ref: &RepoRef, 847 get_events_from_cache(
847) -> Result<Option<nostr::Event>> { 848 git_repo_path,
848 let mut state_events = get_events_from_cache( 849 vec![get_filter_state_events(&repo_ref.coordinates())],
849 git_repo_path, 850 )
850 vec![get_filter_state_events(&repo_ref.coordinates())], 851 .await?,
851 ) 852 )
852 .await?;
853 state_events.sort_by_key(|e| e.created_at);
854 Ok(state_events.first().map(std::borrow::ToOwned::to_owned))
855} 853}
856 854
857#[allow(clippy::too_many_lines)] 855#[allow(clippy::too_many_lines)]
@@ -1062,8 +1060,8 @@ async fn create_relays_request(
1062 .collect() 1060 .collect()
1063 }, 1061 },
1064 state: if let Ok(repo_ref) = &repo_ref { 1062 state: if let Ok(repo_ref) = &repo_ref {
1065 if let Ok(Some(existing_state)) = get_state_from_cache(git_repo_path, repo_ref).await { 1063 if let Ok(existing_state) = get_state_from_cache(git_repo_path, repo_ref).await {
1066 Some((existing_state.created_at, existing_state.id)) 1064 Some((existing_state.event.created_at, existing_state.event.id))
1067 } else { 1065 } else {
1068 None 1066 None
1069 } 1067 }