upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/lib/client.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-08-06 12:52:59 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2025-08-07 17:25:50 +0100
commita9b2ebf8216be34950e54dd9a446dbdc0c9c744a (patch)
tree5a103933852fbcfcd42b13716cb92eeca5325d6d /src/lib/client.rs
parent29f61ffdf155ea88b8d9aec23d28cf70baba577e (diff)
feat(send): PR fallback to user / custom grasp
if use is maintainer, push PR to all repo git servers. if user has a fork, push to all git servers it lists, and repo grasp servers. if user hasn't got a fork but has a user grasp list and pushing push to repo grasp servers fails, create a personal-fork automatically at each user grasp server and push there. fallback to prompting user for either grasp servers or git server with write permission. if user provides grasp servers, suggesting adding to user preference list.
Diffstat (limited to 'src/lib/client.rs')
-rw-r--r--src/lib/client.rs54
1 files changed, 25 insertions, 29 deletions
diff --git a/src/lib/client.rs b/src/lib/client.rs
index b27f9b1..9ce3e24 100644
--- a/src/lib/client.rs
+++ b/src/lib/client.rs
@@ -53,7 +53,7 @@ use crate::{
53 get_dirs, 53 get_dirs,
54 git::{Repo, RepoActions, get_git_config_item}, 54 git::{Repo, RepoActions, get_git_config_item},
55 git_events::{ 55 git_events::{
56 KIND_PULL_REQUEST, KIND_PULL_REQUEST_UPDATE, event_is_cover_letter, 56 KIND_PULL_REQUEST, KIND_PULL_REQUEST_UPDATE, KIND_USER_GRASP_LIST, event_is_cover_letter,
57 event_is_patch_set_root, event_is_revision_root, event_is_valid_pr_or_pr_update, 57 event_is_patch_set_root, event_is_revision_root, event_is_valid_pr_or_pr_update,
58 status_kinds, 58 status_kinds,
59 }, 59 },
@@ -233,7 +233,7 @@ impl Connect for Client {
233 if let Some(git_repo_path) = git_repo_path { 233 if let Some(git_repo_path) = git_repo_path {
234 save_event_in_local_cache(git_repo_path, &event).await?; 234 save_event_in_local_cache(git_repo_path, &event).await?;
235 } 235 }
236 if event.kind.eq(&Kind::GitRepoAnnouncement) { 236 if [Kind::GitRepoAnnouncement, KIND_USER_GRASP_LIST].contains(&event.kind) {
237 save_event_in_global_cache(git_repo_path, &event).await?; 237 save_event_in_global_cache(git_repo_path, &event).await?;
238 } 238 }
239 Ok(event.id) 239 Ok(event.id)
@@ -1310,17 +1310,21 @@ async fn create_relays_request(
1310 user_profiles.insert(current_user); 1310 user_profiles.insert(current_user);
1311 } 1311 }
1312 } 1312 }
1313 let mut map: HashMap<PublicKey, (Timestamp, Timestamp)> = HashMap::new(); 1313 let mut map: HashMap<PublicKey, (Timestamp, Timestamp, Timestamp)> = HashMap::new();
1314 for public_key in &user_profiles { 1314 for public_key in &user_profiles {
1315 if let Ok(user_ref) = get_user_ref_from_cache(git_repo_path, public_key).await { 1315 if let Ok(user_ref) = get_user_ref_from_cache(git_repo_path, public_key).await {
1316 map.insert( 1316 map.insert(
1317 public_key.to_owned(), 1317 public_key.to_owned(),
1318 (user_ref.metadata.created_at, user_ref.relays.created_at), 1318 (
1319 user_ref.metadata.created_at,
1320 user_ref.relays.created_at,
1321 user_ref.grasp_list.created_at,
1322 ),
1319 ); 1323 );
1320 } else { 1324 } else {
1321 map.insert( 1325 map.insert(
1322 public_key.to_owned(), 1326 public_key.to_owned(),
1323 (Timestamp::from(0), Timestamp::from(0)), 1327 (Timestamp::from(0), Timestamp::from(0), Timestamp::from(0)),
1324 ); 1328 );
1325 } 1329 }
1326 } 1330 }
@@ -1547,16 +1551,22 @@ async fn process_fetched_events(
1547 { 1551 {
1548 fresh_profiles.insert(event.pubkey); 1552 fresh_profiles.insert(event.pubkey);
1549 } 1553 }
1550 } else if [Kind::RelayList, Kind::Metadata].contains(&event.kind) { 1554 } else if [Kind::RelayList, Kind::Metadata, KIND_USER_GRASP_LIST].contains(&event.kind)
1555 {
1551 if request.missing_contributor_profiles.contains(&event.pubkey) { 1556 if request.missing_contributor_profiles.contains(&event.pubkey) {
1552 report.contributor_profiles.insert(event.pubkey); 1557 report.contributor_profiles.insert(event.pubkey);
1553 } else if let Some((_, (metadata_timestamp, relay_list_timestamp))) = request 1558 } else if let Some((
1559 _,
1560 (metadata_timestamp, relay_list_timestamp, grasp_list_timestamp),
1561 )) = request
1554 .profiles_to_fetch_from_user_relays 1562 .profiles_to_fetch_from_user_relays
1555 .get_key_value(&event.pubkey) 1563 .get_key_value(&event.pubkey)
1556 { 1564 {
1557 if (Kind::Metadata.eq(&event.kind) && event.created_at.gt(metadata_timestamp)) 1565 if (Kind::Metadata.eq(&event.kind) && event.created_at.gt(metadata_timestamp))
1558 || (Kind::RelayList.eq(&event.kind) 1566 || (Kind::RelayList.eq(&event.kind)
1559 && event.created_at.gt(relay_list_timestamp)) 1567 && event.created_at.gt(relay_list_timestamp))
1568 || (KIND_USER_GRASP_LIST.eq(&event.kind)
1569 && event.created_at.gt(grasp_list_timestamp))
1560 { 1570 {
1561 report.profile_updates.insert(event.pubkey); 1571 report.profile_updates.insert(event.pubkey);
1562 } 1572 }
@@ -1718,35 +1728,21 @@ pub fn get_filter_repo_events(repo_coordinates: &HashSet<Nip19Coordinate>) -> no
1718 .map(|c| c.identifier.clone()) 1728 .map(|c| c.identifier.clone())
1719 .collect::<Vec<String>>(), 1729 .collect::<Vec<String>>(),
1720 ) 1730 )
1721 .authors(
1722 repo_coordinates
1723 .iter()
1724 .map(|c| c.public_key)
1725 .collect::<Vec<PublicKey>>(),
1726 )
1727} 1731}
1728 1732
1729pub static STATE_KIND: nostr::Kind = Kind::Custom(30618); 1733pub static STATE_KIND: nostr::Kind = Kind::Custom(30618);
1730pub fn get_filter_state_events(repo_coordinates: &HashSet<Nip19Coordinate>) -> nostr::Filter { 1734pub fn get_filter_state_events(repo_coordinates: &HashSet<Nip19Coordinate>) -> nostr::Filter {
1731 nostr::Filter::default() 1735 nostr::Filter::default().kind(STATE_KIND).identifiers(
1732 .kind(STATE_KIND) 1736 repo_coordinates
1733 .identifiers( 1737 .iter()
1734 repo_coordinates 1738 .map(|c| c.identifier.clone())
1735 .iter() 1739 .collect::<Vec<String>>(),
1736 .map(|c| c.identifier.clone()) 1740 )
1737 .collect::<Vec<String>>(),
1738 )
1739 .authors(
1740 repo_coordinates
1741 .iter()
1742 .map(|c| c.public_key)
1743 .collect::<Vec<PublicKey>>(),
1744 )
1745} 1741}
1746 1742
1747pub fn get_filter_contributor_profiles(contributors: HashSet<PublicKey>) -> nostr::Filter { 1743pub fn get_filter_contributor_profiles(contributors: HashSet<PublicKey>) -> nostr::Filter {
1748 nostr::Filter::default() 1744 nostr::Filter::default()
1749 .kinds(vec![Kind::Metadata, Kind::RelayList]) 1745 .kinds(vec![Kind::Metadata, Kind::RelayList, KIND_USER_GRASP_LIST])
1750 .authors(contributors) 1746 .authors(contributors)
1751} 1747}
1752 1748
@@ -1850,7 +1846,7 @@ pub struct FetchRequest {
1850 contributors: HashSet<PublicKey>, 1846 contributors: HashSet<PublicKey>,
1851 missing_contributor_profiles: HashSet<PublicKey>, 1847 missing_contributor_profiles: HashSet<PublicKey>,
1852 existing_events: HashSet<EventId>, 1848 existing_events: HashSet<EventId>,
1853 profiles_to_fetch_from_user_relays: HashMap<PublicKey, (Timestamp, Timestamp)>, 1849 profiles_to_fetch_from_user_relays: HashMap<PublicKey, (Timestamp, Timestamp, Timestamp)>,
1854 user_relays_for_profiles: HashSet<RelayUrl>, 1850 user_relays_for_profiles: HashSet<RelayUrl>,
1855} 1851}
1856 1852