diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-07-16 11:01:44 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-07-16 11:01:44 +0100 |
| commit | 7704178c618f8ac455cd6b0582edb511a9e644c3 (patch) | |
| tree | 775e425f0af2543eb12e4a4b1d4feb022611368f /src/lib/client.rs | |
| parent | 8cea674f58e806c22d2887cff5e6f76bc4dba0db (diff) | |
| parent | ac53bca7e315848864ff9e51703720b5b466bc42 (diff) | |
Merge branch 'upgrade-dependancies'
Diffstat (limited to 'src/lib/client.rs')
| -rw-r--r-- | src/lib/client.rs | 135 |
1 files changed, 76 insertions, 59 deletions
diff --git a/src/lib/client.rs b/src/lib/client.rs index 445bf77..9253022 100644 --- a/src/lib/client.rs +++ b/src/lib/client.rs | |||
| @@ -794,8 +794,7 @@ pub async fn sign_event( | |||
| 794 | if signer.backend() == SignerBackend::NostrConnect { | 794 | if signer.backend() == SignerBackend::NostrConnect { |
| 795 | let term = console::Term::stderr(); | 795 | let term = console::Term::stderr(); |
| 796 | term.write_line(&format!( | 796 | term.write_line(&format!( |
| 797 | "signing event ({}) with remote signer...", | 797 | "signing event ({description}) with remote signer..." |
| 798 | description | ||
| 799 | ))?; | 798 | ))?; |
| 800 | let event = signer | 799 | let event = signer |
| 801 | .sign_event(event_builder.build(signer.get_public_key().await?)) | 800 | .sign_event(event_builder.build(signer.get_public_key().await?)) |
| @@ -1104,16 +1103,18 @@ pub async fn get_state_from_cache( | |||
| 1104 | ) -> Result<RepoState> { | 1103 | ) -> Result<RepoState> { |
| 1105 | if let Some(git_repo_path) = git_repo_path { | 1104 | if let Some(git_repo_path) = git_repo_path { |
| 1106 | RepoState::try_from( | 1105 | RepoState::try_from( |
| 1107 | get_events_from_local_cache(git_repo_path, vec![get_filter_state_events( | 1106 | get_events_from_local_cache( |
| 1108 | &repo_ref.coordinates(), | 1107 | git_repo_path, |
| 1109 | )]) | 1108 | vec![get_filter_state_events(&repo_ref.coordinates())], |
| 1109 | ) | ||
| 1110 | .await?, | 1110 | .await?, |
| 1111 | ) | 1111 | ) |
| 1112 | } else { | 1112 | } else { |
| 1113 | RepoState::try_from( | 1113 | RepoState::try_from( |
| 1114 | get_event_from_global_cache(git_repo_path, vec![get_filter_state_events( | 1114 | get_event_from_global_cache( |
| 1115 | &repo_ref.coordinates(), | 1115 | git_repo_path, |
| 1116 | )]) | 1116 | vec![get_filter_state_events(&repo_ref.coordinates())], |
| 1117 | ) | ||
| 1117 | .await?, | 1118 | .await?, |
| 1118 | ) | 1119 | ) |
| 1119 | } | 1120 | } |
| @@ -1179,17 +1180,20 @@ async fn create_relays_request( | |||
| 1179 | } | 1180 | } |
| 1180 | 1181 | ||
| 1181 | if let Some(git_repo_path) = git_repo_path { | 1182 | if let Some(git_repo_path) = git_repo_path { |
| 1182 | for event in &get_events_from_local_cache(git_repo_path, vec![ | 1183 | for event in &get_events_from_local_cache( |
| 1183 | nostr::Filter::default() | 1184 | git_repo_path, |
| 1184 | .kinds(vec![Kind::GitPatch]) | 1185 | vec![ |
| 1185 | .custom_tags( | 1186 | nostr::Filter::default() |
| 1186 | SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), | 1187 | .kinds(vec![Kind::GitPatch]) |
| 1187 | repo_coordinates_without_relays | 1188 | .custom_tags( |
| 1188 | .iter() | 1189 | SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), |
| 1189 | .map(|c| c.coordinate.to_string()) | 1190 | repo_coordinates_without_relays |
| 1190 | .collect::<Vec<String>>(), | 1191 | .iter() |
| 1191 | ), | 1192 | .map(|c| c.coordinate.to_string()) |
| 1192 | ]) | 1193 | .collect::<Vec<String>>(), |
| 1194 | ), | ||
| 1195 | ], | ||
| 1196 | ) | ||
| 1193 | .await? | 1197 | .await? |
| 1194 | { | 1198 | { |
| 1195 | if event_is_patch_set_root(event) || event_is_revision_root(event) { | 1199 | if event_is_patch_set_root(event) || event_is_revision_root(event) { |
| @@ -1199,11 +1203,11 @@ async fn create_relays_request( | |||
| 1199 | } | 1203 | } |
| 1200 | } | 1204 | } |
| 1201 | 1205 | ||
| 1202 | let profile_events = | 1206 | let profile_events = get_event_from_global_cache( |
| 1203 | get_event_from_global_cache(git_repo_path, vec![get_filter_contributor_profiles( | 1207 | git_repo_path, |
| 1204 | contributors.clone(), | 1208 | vec![get_filter_contributor_profiles(contributors.clone())], |
| 1205 | )]) | 1209 | ) |
| 1206 | .await?; | 1210 | .await?; |
| 1207 | for c in &contributors { | 1211 | for c in &contributors { |
| 1208 | if let Some(event) = profile_events | 1212 | if let Some(event) = profile_events |
| 1209 | .iter() | 1213 | .iter() |
| @@ -1769,17 +1773,20 @@ pub async fn get_proposals_and_revisions_from_cache( | |||
| 1769 | git_repo_path: &Path, | 1773 | git_repo_path: &Path, |
| 1770 | repo_coordinates: HashSet<Nip19Coordinate>, | 1774 | repo_coordinates: HashSet<Nip19Coordinate>, |
| 1771 | ) -> Result<Vec<nostr::Event>> { | 1775 | ) -> Result<Vec<nostr::Event>> { |
| 1772 | let mut proposals = get_events_from_local_cache(git_repo_path, vec![ | 1776 | let mut proposals = get_events_from_local_cache( |
| 1773 | nostr::Filter::default() | 1777 | git_repo_path, |
| 1774 | .kind(nostr::Kind::GitPatch) | 1778 | vec![ |
| 1775 | .custom_tags( | 1779 | nostr::Filter::default() |
| 1776 | nostr::SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), | 1780 | .kind(nostr::Kind::GitPatch) |
| 1777 | repo_coordinates | 1781 | .custom_tags( |
| 1778 | .iter() | 1782 | nostr::SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), |
| 1779 | .map(|c| c.coordinate.to_string()) | 1783 | repo_coordinates |
| 1780 | .collect::<Vec<String>>(), | 1784 | .iter() |
| 1781 | ), | 1785 | .map(|c| c.coordinate.to_string()) |
| 1782 | ]) | 1786 | .collect::<Vec<String>>(), |
| 1787 | ), | ||
| 1788 | ], | ||
| 1789 | ) | ||
| 1783 | .await? | 1790 | .await? |
| 1784 | .iter() | 1791 | .iter() |
| 1785 | .filter(|e| event_is_patch_set_root(e)) | 1792 | .filter(|e| event_is_patch_set_root(e)) |
| @@ -1795,23 +1802,29 @@ pub async fn get_all_proposal_patch_events_from_cache( | |||
| 1795 | repo_ref: &RepoRef, | 1802 | repo_ref: &RepoRef, |
| 1796 | proposal_id: &nostr::EventId, | 1803 | proposal_id: &nostr::EventId, |
| 1797 | ) -> Result<Vec<nostr::Event>> { | 1804 | ) -> Result<Vec<nostr::Event>> { |
| 1798 | let mut commit_events = get_events_from_local_cache(git_repo_path, vec![ | 1805 | let mut commit_events = get_events_from_local_cache( |
| 1799 | nostr::Filter::default() | 1806 | git_repo_path, |
| 1800 | .kind(nostr::Kind::GitPatch) | 1807 | vec![ |
| 1801 | .event(*proposal_id), | 1808 | nostr::Filter::default() |
| 1802 | nostr::Filter::default() | 1809 | .kind(nostr::Kind::GitPatch) |
| 1803 | .kind(nostr::Kind::GitPatch) | 1810 | .event(*proposal_id), |
| 1804 | .id(*proposal_id), | 1811 | nostr::Filter::default() |
| 1805 | ]) | 1812 | .kind(nostr::Kind::GitPatch) |
| 1813 | .id(*proposal_id), | ||
| 1814 | ], | ||
| 1815 | ) | ||
| 1806 | .await?; | 1816 | .await?; |
| 1807 | 1817 | ||
| 1808 | let permissioned_users: HashSet<PublicKey> = [repo_ref.maintainers.clone(), vec![ | 1818 | let permissioned_users: HashSet<PublicKey> = [ |
| 1809 | commit_events | 1819 | repo_ref.maintainers.clone(), |
| 1810 | .iter() | 1820 | vec![ |
| 1811 | .find(|e| e.id.eq(proposal_id)) | 1821 | commit_events |
| 1812 | .context("proposal not in cache")? | 1822 | .iter() |
| 1813 | .pubkey, | 1823 | .find(|e| e.id.eq(proposal_id)) |
| 1814 | ]] | 1824 | .context("proposal not in cache")? |
| 1825 | .pubkey, | ||
| 1826 | ], | ||
| 1827 | ] | ||
| 1815 | .concat() | 1828 | .concat() |
| 1816 | .iter() | 1829 | .iter() |
| 1817 | .copied() | 1830 | .copied() |
| @@ -1825,12 +1838,15 @@ pub async fn get_all_proposal_patch_events_from_cache( | |||
| 1825 | .collect(); | 1838 | .collect(); |
| 1826 | 1839 | ||
| 1827 | if !revision_roots.is_empty() { | 1840 | if !revision_roots.is_empty() { |
| 1828 | for event in get_events_from_local_cache(git_repo_path, vec![ | 1841 | for event in get_events_from_local_cache( |
| 1829 | nostr::Filter::default() | 1842 | git_repo_path, |
| 1830 | .kind(nostr::Kind::GitPatch) | 1843 | vec![ |
| 1831 | .events(revision_roots) | 1844 | nostr::Filter::default() |
| 1832 | .authors(permissioned_users.clone()), | 1845 | .kind(nostr::Kind::GitPatch) |
| 1833 | ]) | 1846 | .events(revision_roots) |
| 1847 | .authors(permissioned_users.clone()), | ||
| 1848 | ], | ||
| 1849 | ) | ||
| 1834 | .await? | 1850 | .await? |
| 1835 | { | 1851 | { |
| 1836 | commit_events.push(event); | 1852 | commit_events.push(event); |
| @@ -1845,9 +1861,10 @@ pub async fn get_all_proposal_patch_events_from_cache( | |||
| 1845 | } | 1861 | } |
| 1846 | 1862 | ||
| 1847 | pub async fn get_event_from_cache_by_id(git_repo: &Repo, event_id: &EventId) -> Result<Event> { | 1863 | pub async fn get_event_from_cache_by_id(git_repo: &Repo, event_id: &EventId) -> Result<Event> { |
| 1848 | Ok(get_events_from_local_cache(git_repo.get_path()?, vec![ | 1864 | Ok(get_events_from_local_cache( |
| 1849 | nostr::Filter::default().id(*event_id), | 1865 | git_repo.get_path()?, |
| 1850 | ]) | 1866 | vec![nostr::Filter::default().id(*event_id)], |
| 1867 | ) | ||
| 1851 | .await? | 1868 | .await? |
| 1852 | .first() | 1869 | .first() |
| 1853 | .context("failed to find event in cache")? | 1870 | .context("failed to find event in cache")? |