diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-17 17:33:29 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-17 17:34:27 +0100 |
| commit | 0379a7ad4c1c6876c32286adb1cf090e3afdc5ea (patch) | |
| tree | 3ebde10b399214bc6509bb81806088bb7b552383 | |
| parent | 7227db8d2a506912eb5ffd3d25dee1c95544cbf4 (diff) | |
fix(fetch): get profile with nsec cli parameter
only the profile from the saved user was being fetched.
tests are using cli login parameters and expecting to see the
user's name but it was only showing the npub.
fixed by allowing the explicit request of specfic user profiles.
| -rw-r--r-- | src/client.rs | 19 | ||||
| -rw-r--r-- | src/login.rs | 6 | ||||
| -rw-r--r-- | src/repo_ref.rs | 4 | ||||
| -rw-r--r-- | src/sub_commands/fetch.rs | 2 |
4 files changed, 22 insertions, 9 deletions
diff --git a/src/client.rs b/src/client.rs index b6e93d6..7947a02 100644 --- a/src/client.rs +++ b/src/client.rs | |||
| @@ -78,6 +78,7 @@ pub trait Connect { | |||
| 78 | &self, | 78 | &self, |
| 79 | git_repo_path: &Path, | 79 | git_repo_path: &Path, |
| 80 | repo_coordinates: &HashSet<Coordinate>, | 80 | repo_coordinates: &HashSet<Coordinate>, |
| 81 | user_profiles: &HashSet<PublicKey>, | ||
| 81 | ) -> Result<(Vec<Result<FetchReport>>, MultiProgress)>; | 82 | ) -> Result<(Vec<Result<FetchReport>>, MultiProgress)>; |
| 82 | async fn fetch_all_from_relay( | 83 | async fn fetch_all_from_relay( |
| 83 | &self, | 84 | &self, |
| @@ -288,6 +289,7 @@ impl Connect for Client { | |||
| 288 | &self, | 289 | &self, |
| 289 | git_repo_path: &Path, | 290 | git_repo_path: &Path, |
| 290 | repo_coordinates: &HashSet<Coordinate>, | 291 | repo_coordinates: &HashSet<Coordinate>, |
| 292 | user_profiles: &HashSet<PublicKey>, | ||
| 291 | ) -> Result<(Vec<Result<FetchReport>>, MultiProgress)> { | 293 | ) -> Result<(Vec<Result<FetchReport>>, MultiProgress)> { |
| 292 | let fallback_relays = &self | 294 | let fallback_relays = &self |
| 293 | .fallback_relays | 295 | .fallback_relays |
| @@ -295,8 +297,13 @@ impl Connect for Client { | |||
| 295 | .filter_map(|r| Url::parse(r).ok()) | 297 | .filter_map(|r| Url::parse(r).ok()) |
| 296 | .collect::<HashSet<Url>>(); | 298 | .collect::<HashSet<Url>>(); |
| 297 | 299 | ||
| 298 | let mut request = | 300 | let mut request = create_relays_request( |
| 299 | create_relays_request(git_repo_path, repo_coordinates, fallback_relays.clone()).await?; | 301 | git_repo_path, |
| 302 | repo_coordinates, | ||
| 303 | user_profiles, | ||
| 304 | fallback_relays.clone(), | ||
| 305 | ) | ||
| 306 | .await?; | ||
| 300 | 307 | ||
| 301 | let progress_reporter = MultiProgress::new(); | 308 | let progress_reporter = MultiProgress::new(); |
| 302 | 309 | ||
| @@ -666,7 +673,7 @@ async fn get_global_cache_database(git_repo_path: &Path) -> Result<SQLiteDatabas | |||
| 666 | .context("cannot open ngit global nostr cache database") | 673 | .context("cannot open ngit global nostr cache database") |
| 667 | } | 674 | } |
| 668 | 675 | ||
| 669 | pub async fn get_event_from_cache( | 676 | pub async fn get_events_from_cache( |
| 670 | git_repo_path: &Path, | 677 | git_repo_path: &Path, |
| 671 | filters: Vec<nostr::Filter>, | 678 | filters: Vec<nostr::Filter>, |
| 672 | ) -> Result<Vec<nostr::Event>> { | 679 | ) -> Result<Vec<nostr::Event>> { |
| @@ -725,7 +732,7 @@ pub async fn get_repo_ref_from_cache( | |||
| 725 | 732 | ||
| 726 | let events = [ | 733 | let events = [ |
| 727 | get_event_from_global_cache(git_repo_path, vec![filter.clone()]).await?, | 734 | get_event_from_global_cache(git_repo_path, vec![filter.clone()]).await?, |
| 728 | get_event_from_cache(git_repo_path, vec![filter]).await?, | 735 | get_events_from_cache(git_repo_path, vec![filter]).await?, |
| 729 | ] | 736 | ] |
| 730 | .concat(); | 737 | .concat(); |
| 731 | for e in events { | 738 | for e in events { |
| @@ -778,6 +785,7 @@ pub async fn get_repo_ref_from_cache( | |||
| 778 | async fn create_relays_request( | 785 | async fn create_relays_request( |
| 779 | git_repo_path: &Path, | 786 | git_repo_path: &Path, |
| 780 | repo_coordinates: &HashSet<Coordinate>, | 787 | repo_coordinates: &HashSet<Coordinate>, |
| 788 | user_profiles: &HashSet<PublicKey>, | ||
| 781 | fallback_relays: HashSet<Url>, | 789 | fallback_relays: HashSet<Url>, |
| 782 | ) -> Result<FetchRequest> { | 790 | ) -> Result<FetchRequest> { |
| 783 | let repo_ref = get_repo_ref_from_cache(git_repo_path, repo_coordinates).await; | 791 | let repo_ref = get_repo_ref_from_cache(git_repo_path, repo_coordinates).await; |
| @@ -799,7 +807,7 @@ async fn create_relays_request( | |||
| 799 | } | 807 | } |
| 800 | } | 808 | } |
| 801 | 809 | ||
| 802 | for event in &get_event_from_cache( | 810 | for event in &get_events_from_cache( |
| 803 | git_repo_path, | 811 | git_repo_path, |
| 804 | vec![ | 812 | vec![ |
| 805 | nostr::Filter::default() | 813 | nostr::Filter::default() |
| @@ -843,6 +851,7 @@ async fn create_relays_request( | |||
| 843 | if let Some(current_user) = current_user { | 851 | if let Some(current_user) = current_user { |
| 844 | missing_contributor_profiles.insert(current_user); | 852 | missing_contributor_profiles.insert(current_user); |
| 845 | } | 853 | } |
| 854 | missing_contributor_profiles.extend(user_profiles); | ||
| 846 | 855 | ||
| 847 | let existing_events: HashSet<EventId> = { | 856 | let existing_events: HashSet<EventId> = { |
| 848 | let mut existing_events: HashSet<EventId> = HashSet::new(); | 857 | let mut existing_events: HashSet<EventId> = HashSet::new(); |
diff --git a/src/login.rs b/src/login.rs index 0a20a90..6c3acfa 100644 --- a/src/login.rs +++ b/src/login.rs | |||
| @@ -628,7 +628,11 @@ async fn get_user_details( | |||
| 628 | let term = console::Term::stderr(); | 628 | let term = console::Term::stderr(); |
| 629 | term.write_line("searching for profile...")?; | 629 | term.write_line("searching for profile...")?; |
| 630 | let (_, progress_reporter) = client | 630 | let (_, progress_reporter) = client |
| 631 | .fetch_all(git_repo.get_path()?, &HashSet::new()) | 631 | .fetch_all( |
| 632 | git_repo.get_path()?, | ||
| 633 | &HashSet::new(), | ||
| 634 | &HashSet::from_iter(vec![*public_key]), | ||
| 635 | ) | ||
| 632 | .await?; | 636 | .await?; |
| 633 | events = get_event_from_global_cache(git_repo.get_path()?, filters).await?; | 637 | events = get_event_from_global_cache(git_repo.get_path()?, filters).await?; |
| 634 | if !events.is_empty() { | 638 | if !events.is_empty() { |
diff --git a/src/repo_ref.rs b/src/repo_ref.rs index 4952b16..0e91cc4 100644 --- a/src/repo_ref.rs +++ b/src/repo_ref.rs | |||
| @@ -19,7 +19,7 @@ use crate::client::Client; | |||
| 19 | use crate::client::MockConnect; | 19 | use crate::client::MockConnect; |
| 20 | use crate::{ | 20 | use crate::{ |
| 21 | cli_interactor::{Interactor, InteractorPrompt, PromptInputParms}, | 21 | cli_interactor::{Interactor, InteractorPrompt, PromptInputParms}, |
| 22 | client::{get_event_from_cache, get_event_from_global_cache, sign_event, Connect}, | 22 | client::{get_event_from_global_cache, get_events_from_cache, sign_event, Connect}, |
| 23 | git::{Repo, RepoActions}, | 23 | git::{Repo, RepoActions}, |
| 24 | }; | 24 | }; |
| 25 | 25 | ||
| @@ -261,7 +261,7 @@ pub async fn get_repo_coordinates( | |||
| 261 | .reference(git_repo.get_root_commit()?.to_string()) | 261 | .reference(git_repo.get_root_commit()?.to_string()) |
| 262 | .authors(maintainers.clone()); | 262 | .authors(maintainers.clone()); |
| 263 | let mut events = | 263 | let mut events = |
| 264 | get_event_from_cache(git_repo.get_path()?, vec![filter.clone()]).await?; | 264 | get_events_from_cache(git_repo.get_path()?, vec![filter.clone()]).await?; |
| 265 | if events.is_empty() { | 265 | if events.is_empty() { |
| 266 | events = | 266 | events = |
| 267 | get_event_from_global_cache(git_repo.get_path()?, vec![filter.clone()]) | 267 | get_event_from_global_cache(git_repo.get_path()?, vec![filter.clone()]) |
diff --git a/src/sub_commands/fetch.rs b/src/sub_commands/fetch.rs index 5a6850c..28eb960 100644 --- a/src/sub_commands/fetch.rs +++ b/src/sub_commands/fetch.rs | |||
| @@ -40,7 +40,7 @@ pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { | |||
| 40 | }; | 40 | }; |
| 41 | println!("fetching updates..."); | 41 | println!("fetching updates..."); |
| 42 | let (relay_reports, _) = client | 42 | let (relay_reports, _) = client |
| 43 | .fetch_all(git_repo.get_path()?, &repo_coordinates) | 43 | .fetch_all(git_repo.get_path()?, &repo_coordinates, &HashSet::new()) |
| 44 | .await?; | 44 | .await?; |
| 45 | let report = consolidate_fetch_reports(relay_reports); | 45 | let report = consolidate_fetch_reports(relay_reports); |
| 46 | if report.to_string().is_empty() { | 46 | if report.to_string().is_empty() { |