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:
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 3fcfba4..0984b19 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 },
@@ -241,7 +241,7 @@ impl Connect for Client {
241 if let Some(git_repo_path) = git_repo_path { 241 if let Some(git_repo_path) = git_repo_path {
242 save_event_in_local_cache(git_repo_path, &event).await?; 242 save_event_in_local_cache(git_repo_path, &event).await?;
243 } 243 }
244 if event.kind.eq(&Kind::GitRepoAnnouncement) { 244 if [Kind::GitRepoAnnouncement, KIND_USER_GRASP_LIST].contains(&event.kind) {
245 save_event_in_global_cache(git_repo_path, &event).await?; 245 save_event_in_global_cache(git_repo_path, &event).await?;
246 } 246 }
247 Ok(event.id) 247 Ok(event.id)
@@ -1308,17 +1308,21 @@ async fn create_relays_request(
1308 user_profiles.insert(current_user); 1308 user_profiles.insert(current_user);
1309 } 1309 }
1310 } 1310 }
1311 let mut map: HashMap<PublicKey, (Timestamp, Timestamp)> = HashMap::new(); 1311 let mut map: HashMap<PublicKey, (Timestamp, Timestamp, Timestamp)> = HashMap::new();
1312 for public_key in &user_profiles { 1312 for public_key in &user_profiles {
1313 if let Ok(user_ref) = get_user_ref_from_cache(git_repo_path, public_key).await { 1313 if let Ok(user_ref) = get_user_ref_from_cache(git_repo_path, public_key).await {
1314 map.insert( 1314 map.insert(
1315 public_key.to_owned(), 1315 public_key.to_owned(),
1316 (user_ref.metadata.created_at, user_ref.relays.created_at), 1316 (
1317 user_ref.metadata.created_at,
1318 user_ref.relays.created_at,
1319 user_ref.grasp_list.created_at,
1320 ),
1317 ); 1321 );
1318 } else { 1322 } else {
1319 map.insert( 1323 map.insert(
1320 public_key.to_owned(), 1324 public_key.to_owned(),
1321 (Timestamp::from(0), Timestamp::from(0)), 1325 (Timestamp::from(0), Timestamp::from(0), Timestamp::from(0)),
1322 ); 1326 );
1323 } 1327 }
1324 } 1328 }
@@ -1545,16 +1549,22 @@ async fn process_fetched_events(
1545 { 1549 {
1546 fresh_profiles.insert(event.pubkey); 1550 fresh_profiles.insert(event.pubkey);
1547 } 1551 }
1548 } else if [Kind::RelayList, Kind::Metadata].contains(&event.kind) { 1552 } else if [Kind::RelayList, Kind::Metadata, KIND_USER_GRASP_LIST].contains(&event.kind)
1553 {
1549 if request.missing_contributor_profiles.contains(&event.pubkey) { 1554 if request.missing_contributor_profiles.contains(&event.pubkey) {
1550 report.contributor_profiles.insert(event.pubkey); 1555 report.contributor_profiles.insert(event.pubkey);
1551 } else if let Some((_, (metadata_timestamp, relay_list_timestamp))) = request 1556 } else if let Some((
1557 _,
1558 (metadata_timestamp, relay_list_timestamp, grasp_list_timestamp),
1559 )) = request
1552 .profiles_to_fetch_from_user_relays 1560 .profiles_to_fetch_from_user_relays
1553 .get_key_value(&event.pubkey) 1561 .get_key_value(&event.pubkey)
1554 { 1562 {
1555 if (Kind::Metadata.eq(&event.kind) && event.created_at.gt(metadata_timestamp)) 1563 if (Kind::Metadata.eq(&event.kind) && event.created_at.gt(metadata_timestamp))
1556 || (Kind::RelayList.eq(&event.kind) 1564 || (Kind::RelayList.eq(&event.kind)
1557 && event.created_at.gt(relay_list_timestamp)) 1565 && event.created_at.gt(relay_list_timestamp))
1566 || (KIND_USER_GRASP_LIST.eq(&event.kind)
1567 && event.created_at.gt(grasp_list_timestamp))
1558 { 1568 {
1559 report.profile_updates.insert(event.pubkey); 1569 report.profile_updates.insert(event.pubkey);
1560 } 1570 }
@@ -1716,35 +1726,21 @@ pub fn get_filter_repo_events(repo_coordinates: &HashSet<Nip19Coordinate>) -> no
1716 .map(|c| c.identifier.clone()) 1726 .map(|c| c.identifier.clone())
1717 .collect::<Vec<String>>(), 1727 .collect::<Vec<String>>(),
1718 ) 1728 )
1719 .authors(
1720 repo_coordinates
1721 .iter()
1722 .map(|c| c.public_key)
1723 .collect::<Vec<PublicKey>>(),
1724 )
1725} 1729}
1726 1730
1727pub static STATE_KIND: nostr::Kind = Kind::Custom(30618); 1731pub static STATE_KIND: nostr::Kind = Kind::Custom(30618);
1728pub fn get_filter_state_events(repo_coordinates: &HashSet<Nip19Coordinate>) -> nostr::Filter { 1732pub fn get_filter_state_events(repo_coordinates: &HashSet<Nip19Coordinate>) -> nostr::Filter {
1729 nostr::Filter::default() 1733 nostr::Filter::default().kind(STATE_KIND).identifiers(
1730 .kind(STATE_KIND) 1734 repo_coordinates
1731 .identifiers( 1735 .iter()
1732 repo_coordinates 1736 .map(|c| c.identifier.clone())
1733 .iter() 1737 .collect::<Vec<String>>(),
1734 .map(|c| c.identifier.clone()) 1738 )
1735 .collect::<Vec<String>>(),
1736 )
1737 .authors(
1738 repo_coordinates
1739 .iter()
1740 .map(|c| c.public_key)
1741 .collect::<Vec<PublicKey>>(),
1742 )
1743} 1739}
1744 1740
1745pub fn get_filter_contributor_profiles(contributors: HashSet<PublicKey>) -> nostr::Filter { 1741pub fn get_filter_contributor_profiles(contributors: HashSet<PublicKey>) -> nostr::Filter {
1746 nostr::Filter::default() 1742 nostr::Filter::default()
1747 .kinds(vec![Kind::Metadata, Kind::RelayList]) 1743 .kinds(vec![Kind::Metadata, Kind::RelayList, KIND_USER_GRASP_LIST])
1748 .authors(contributors) 1744 .authors(contributors)
1749} 1745}
1750 1746
@@ -1848,7 +1844,7 @@ pub struct FetchRequest {
1848 contributors: HashSet<PublicKey>, 1844 contributors: HashSet<PublicKey>,
1849 missing_contributor_profiles: HashSet<PublicKey>, 1845 missing_contributor_profiles: HashSet<PublicKey>,
1850 existing_events: HashSet<EventId>, 1846 existing_events: HashSet<EventId>,
1851 profiles_to_fetch_from_user_relays: HashMap<PublicKey, (Timestamp, Timestamp)>, 1847 profiles_to_fetch_from_user_relays: HashMap<PublicKey, (Timestamp, Timestamp, Timestamp)>,
1852 user_relays_for_profiles: HashSet<RelayUrl>, 1848 user_relays_for_profiles: HashSet<RelayUrl>,
1853} 1849}
1854 1850