diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-18 08:01:21 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-18 08:01:21 +0100 |
| commit | 10d98590ef9317be5b12a6a4830d7394d479c1d5 (patch) | |
| tree | 643bc09cdd7837cbbd743d10e3b3b7a7214f49d6 /src | |
| parent | 0379a7ad4c1c6876c32286adb1cf090e3afdc5ea (diff) | |
fix(fetch): find repo based in naddr relay hint
which will enable the following`list` test to pass once `fetch`
is intergrated into `list`:
finds_based_on_naddr_on_embeded_relay
Diffstat (limited to 'src')
| -rw-r--r-- | src/client.rs | 56 |
1 files changed, 46 insertions, 10 deletions
diff --git a/src/client.rs b/src/client.rs index 7947a02..b50ccf2 100644 --- a/src/client.rs +++ b/src/client.rs | |||
| @@ -790,17 +790,41 @@ async fn create_relays_request( | |||
| 790 | ) -> Result<FetchRequest> { | 790 | ) -> Result<FetchRequest> { |
| 791 | 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; |
| 792 | 792 | ||
| 793 | let repo_coordinates = if let Ok(repo_ref) = &repo_ref { | 793 | let repo_coordinates = { |
| 794 | repo_ref.coordinates() | 794 | // add coordinates of users listed in maintainers to explicitly specified |
| 795 | } else { | 795 | // coodinates |
| 796 | repo_coordinates.clone() | 796 | let mut repo_coordinates = repo_coordinates.clone(); |
| 797 | if let Ok(repo_ref) = &repo_ref { | ||
| 798 | for c in repo_ref.coordinates() { | ||
| 799 | if !repo_coordinates | ||
| 800 | .iter() | ||
| 801 | .any(|e| e.identifier.eq(&c.identifier) && e.public_key.eq(&c.public_key)) | ||
| 802 | { | ||
| 803 | repo_coordinates.insert(c); | ||
| 804 | } | ||
| 805 | } | ||
| 806 | } | ||
| 807 | repo_coordinates | ||
| 808 | }; | ||
| 809 | |||
| 810 | let repo_coordinates_without_relays = { | ||
| 811 | let mut set = HashSet::new(); | ||
| 812 | for c in &repo_coordinates { | ||
| 813 | set.insert(Coordinate { | ||
| 814 | kind: c.kind, | ||
| 815 | identifier: c.identifier.clone(), | ||
| 816 | public_key: c.public_key, | ||
| 817 | relays: vec![], | ||
| 818 | }); | ||
| 819 | } | ||
| 820 | set | ||
| 797 | }; | 821 | }; |
| 798 | 822 | ||
| 799 | let mut proposals: HashSet<EventId> = HashSet::new(); | 823 | let mut proposals: HashSet<EventId> = HashSet::new(); |
| 800 | let mut missing_contributor_profiles: HashSet<PublicKey> = HashSet::new(); | 824 | let mut missing_contributor_profiles: HashSet<PublicKey> = HashSet::new(); |
| 801 | let mut contributors: HashSet<PublicKey> = HashSet::new(); | 825 | let mut contributors: HashSet<PublicKey> = HashSet::new(); |
| 802 | 826 | ||
| 803 | if !repo_coordinates.is_empty() { | 827 | if !repo_coordinates_without_relays.is_empty() { |
| 804 | if let Ok(repo_ref) = &repo_ref { | 828 | if let Ok(repo_ref) = &repo_ref { |
| 805 | for m in &repo_ref.maintainers { | 829 | for m in &repo_ref.maintainers { |
| 806 | contributors.insert(m.to_owned()); | 830 | contributors.insert(m.to_owned()); |
| @@ -814,7 +838,7 @@ async fn create_relays_request( | |||
| 814 | .kinds(vec![Kind::Custom(PATCH_KIND)]) | 838 | .kinds(vec![Kind::Custom(PATCH_KIND)]) |
| 815 | .custom_tag( | 839 | .custom_tag( |
| 816 | SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), | 840 | SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), |
| 817 | repo_coordinates | 841 | repo_coordinates_without_relays |
| 818 | .iter() | 842 | .iter() |
| 819 | .map(std::string::ToString::to_string) | 843 | .map(std::string::ToString::to_string) |
| 820 | .collect::<Vec<String>>(), | 844 | .collect::<Vec<String>>(), |
| @@ -855,9 +879,11 @@ async fn create_relays_request( | |||
| 855 | 879 | ||
| 856 | let existing_events: HashSet<EventId> = { | 880 | let existing_events: HashSet<EventId> = { |
| 857 | let mut existing_events: HashSet<EventId> = HashSet::new(); | 881 | let mut existing_events: HashSet<EventId> = HashSet::new(); |
| 858 | for filter in | 882 | for filter in get_fetch_filters( |
| 859 | get_fetch_filters(&repo_coordinates, &proposals, &missing_contributor_profiles) | 883 | &repo_coordinates_without_relays, |
| 860 | { | 884 | &proposals, |
| 885 | &missing_contributor_profiles, | ||
| 886 | ) { | ||
| 861 | for (id, _) in get_local_cache_database(git_repo_path) | 887 | for (id, _) in get_local_cache_database(git_repo_path) |
| 862 | .await? | 888 | .await? |
| 863 | .negentropy_items(filter) | 889 | .negentropy_items(filter) |
| @@ -878,6 +904,13 @@ async fn create_relays_request( | |||
| 878 | } | 904 | } |
| 879 | } | 905 | } |
| 880 | } | 906 | } |
| 907 | for c in repo_coordinates { | ||
| 908 | for r in &c.relays { | ||
| 909 | if let Ok(url) = Url::parse(r) { | ||
| 910 | relays.insert(url); | ||
| 911 | } | ||
| 912 | } | ||
| 913 | } | ||
| 881 | relays | 914 | relays |
| 882 | }; | 915 | }; |
| 883 | 916 | ||
| @@ -907,7 +940,10 @@ async fn create_relays_request( | |||
| 907 | repo_coordinates: if let Ok(repo_ref) = repo_ref { | 940 | repo_coordinates: if let Ok(repo_ref) = repo_ref { |
| 908 | repo_ref.coordinates_with_timestamps() | 941 | repo_ref.coordinates_with_timestamps() |
| 909 | } else { | 942 | } else { |
| 910 | repo_coordinates.iter().map(|c| (c.clone(), None)).collect() | 943 | repo_coordinates_without_relays |
| 944 | .iter() | ||
| 945 | .map(|c| (c.clone(), None)) | ||
| 946 | .collect() | ||
| 911 | }, | 947 | }, |
| 912 | proposals, | 948 | proposals, |
| 913 | contributors, | 949 | contributors, |