diff options
Diffstat (limited to 'src/lib/client.rs')
| -rw-r--r-- | src/lib/client.rs | 75 |
1 files changed, 34 insertions, 41 deletions
diff --git a/src/lib/client.rs b/src/lib/client.rs index 59e17f2..5f9e996 100644 --- a/src/lib/client.rs +++ b/src/lib/client.rs | |||
| @@ -29,7 +29,7 @@ use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressState, P | |||
| 29 | #[cfg(test)] | 29 | #[cfg(test)] |
| 30 | use mockall::*; | 30 | use mockall::*; |
| 31 | use nostr::{nips::nip01::Coordinate, Event}; | 31 | use nostr::{nips::nip01::Coordinate, Event}; |
| 32 | use nostr_database::{NostrDatabase, Order}; | 32 | use nostr_database::NostrDatabase; |
| 33 | use nostr_sdk::{ | 33 | use nostr_sdk::{ |
| 34 | prelude::RelayLimits, EventBuilder, EventId, Kind, NostrSigner, Options, PublicKey, | 34 | prelude::RelayLimits, EventBuilder, EventId, Kind, NostrSigner, Options, PublicKey, |
| 35 | SingleLetterTag, Timestamp, Url, | 35 | SingleLetterTag, Timestamp, Url, |
| @@ -231,10 +231,10 @@ impl Connect for Client { | |||
| 231 | }); | 231 | }); |
| 232 | } | 232 | } |
| 233 | save_event_in_cache(git_repo_path, &event).await?; | 233 | save_event_in_cache(git_repo_path, &event).await?; |
| 234 | if event.kind().eq(&Kind::GitRepoAnnouncement) { | 234 | if event.kind.eq(&Kind::GitRepoAnnouncement) { |
| 235 | save_event_in_global_cache(git_repo_path, &event).await?; | 235 | save_event_in_global_cache(git_repo_path, &event).await?; |
| 236 | } | 236 | } |
| 237 | Ok(event.id()) | 237 | Ok(event.id) |
| 238 | } | 238 | } |
| 239 | 239 | ||
| 240 | async fn get_events( | 240 | async fn get_events( |
| @@ -758,7 +758,7 @@ pub async fn get_events_from_cache( | |||
| 758 | ) -> Result<Vec<nostr::Event>> { | 758 | ) -> Result<Vec<nostr::Event>> { |
| 759 | get_local_cache_database(git_repo_path) | 759 | get_local_cache_database(git_repo_path) |
| 760 | .await? | 760 | .await? |
| 761 | .query(filters.clone(), Order::Asc) | 761 | .query(filters.clone()) |
| 762 | .await | 762 | .await |
| 763 | .context( | 763 | .context( |
| 764 | "cannot execute query on opened git repo nostr cache database .git/nostr-cache.sqlite", | 764 | "cannot execute query on opened git repo nostr cache database .git/nostr-cache.sqlite", |
| @@ -771,7 +771,7 @@ pub async fn get_event_from_global_cache( | |||
| 771 | ) -> Result<Vec<nostr::Event>> { | 771 | ) -> Result<Vec<nostr::Event>> { |
| 772 | get_global_cache_database(git_repo_path) | 772 | get_global_cache_database(git_repo_path) |
| 773 | .await? | 773 | .await? |
| 774 | .query(filters.clone(), Order::Asc) | 774 | .query(filters.clone()) |
| 775 | .await | 775 | .await |
| 776 | .context("cannot execute query on opened ngit nostr cache database") | 776 | .context("cannot execute query on opened ngit nostr cache database") |
| 777 | } | 777 | } |
| @@ -839,12 +839,12 @@ pub async fn get_repo_ref_from_cache( | |||
| 839 | 839 | ||
| 840 | let mut events: HashMap<Coordinate, nostr::Event> = HashMap::new(); | 840 | let mut events: HashMap<Coordinate, nostr::Event> = HashMap::new(); |
| 841 | for m in &maintainers { | 841 | for m in &maintainers { |
| 842 | if let Some(e) = repo_events.iter().find(|e| e.author().eq(m)) { | 842 | if let Some(e) = repo_events.iter().find(|e| e.pubkey.eq(m)) { |
| 843 | events.insert( | 843 | events.insert( |
| 844 | Coordinate { | 844 | Coordinate { |
| 845 | kind: e.kind, | 845 | kind: e.kind, |
| 846 | identifier: e.identifier().unwrap().to_string(), | 846 | identifier: e.identifier().unwrap().to_string(), |
| 847 | public_key: e.author(), | 847 | public_key: e.pubkey, |
| 848 | relays: vec![], | 848 | relays: vec![], |
| 849 | }, | 849 | }, |
| 850 | e.clone(), | 850 | e.clone(), |
| @@ -938,8 +938,8 @@ async fn create_relays_request( | |||
| 938 | .await? | 938 | .await? |
| 939 | { | 939 | { |
| 940 | if event_is_patch_set_root(event) || event_is_revision_root(event) { | 940 | if event_is_patch_set_root(event) || event_is_revision_root(event) { |
| 941 | proposals.insert(event.id()); | 941 | proposals.insert(event.id); |
| 942 | contributors.insert(event.author()); | 942 | contributors.insert(event.pubkey); |
| 943 | } | 943 | } |
| 944 | } | 944 | } |
| 945 | 945 | ||
| @@ -951,7 +951,7 @@ async fn create_relays_request( | |||
| 951 | for c in &contributors { | 951 | for c in &contributors { |
| 952 | if let Some(event) = profile_events | 952 | if let Some(event) = profile_events |
| 953 | .iter() | 953 | .iter() |
| 954 | .find(|e| e.kind() == Kind::Metadata && e.author().eq(c)) | 954 | .find(|e| e.kind == Kind::Metadata && e.pubkey.eq(c)) |
| 955 | { | 955 | { |
| 956 | save_event_in_cache(git_repo_path, event).await?; | 956 | save_event_in_cache(git_repo_path, event).await?; |
| 957 | } else { | 957 | } else { |
| @@ -1109,7 +1109,7 @@ async fn process_fetched_events( | |||
| 1109 | for event in &events { | 1109 | for event in &events { |
| 1110 | if !request.existing_events.contains(&event.id) { | 1110 | if !request.existing_events.contains(&event.id) { |
| 1111 | save_event_in_cache(git_repo_path, event).await?; | 1111 | save_event_in_cache(git_repo_path, event).await?; |
| 1112 | if event.kind().eq(&Kind::GitRepoAnnouncement) { | 1112 | if event.kind.eq(&Kind::GitRepoAnnouncement) { |
| 1113 | save_event_in_global_cache(git_repo_path, event).await?; | 1113 | save_event_in_global_cache(git_repo_path, event).await?; |
| 1114 | let new_coordinate = !request | 1114 | let new_coordinate = !request |
| 1115 | .repo_coordinates_without_relays | 1115 | .repo_coordinates_without_relays |
| @@ -1135,8 +1135,8 @@ async fn process_fetched_events( | |||
| 1135 | if update_to_existing { | 1135 | if update_to_existing { |
| 1136 | report.updated_repo_announcements.push(( | 1136 | report.updated_repo_announcements.push(( |
| 1137 | Coordinate { | 1137 | Coordinate { |
| 1138 | kind: event.kind(), | 1138 | kind: event.kind, |
| 1139 | public_key: event.author(), | 1139 | public_key: event.pubkey, |
| 1140 | identifier: event.identifier().unwrap().to_owned(), | 1140 | identifier: event.identifier().unwrap().to_owned(), |
| 1141 | relays: vec![], | 1141 | relays: vec![], |
| 1142 | }, | 1142 | }, |
| @@ -1155,7 +1155,7 @@ async fn process_fetched_events( | |||
| 1155 | .any(|c| c.identifier.eq(&repo_ref.identifier) && m.eq(&c.public_key)) | 1155 | .any(|c| c.identifier.eq(&repo_ref.identifier) && m.eq(&c.public_key)) |
| 1156 | { | 1156 | { |
| 1157 | let c = Coordinate { | 1157 | let c = Coordinate { |
| 1158 | kind: event.kind(), | 1158 | kind: event.kind, |
| 1159 | public_key: *m, | 1159 | public_key: *m, |
| 1160 | identifier: repo_ref.identifier.clone(), | 1160 | identifier: repo_ref.identifier.clone(), |
| 1161 | relays: vec![], | 1161 | relays: vec![], |
| @@ -1177,7 +1177,7 @@ async fn process_fetched_events( | |||
| 1177 | } | 1177 | } |
| 1178 | } | 1178 | } |
| 1179 | } | 1179 | } |
| 1180 | } else if event.kind().eq(&STATE_KIND) { | 1180 | } else if event.kind.eq(&STATE_KIND) { |
| 1181 | let existing_state = if report.updated_state.is_some() { | 1181 | let existing_state = if report.updated_state.is_some() { |
| 1182 | report.updated_state | 1182 | report.updated_state |
| 1183 | } else { | 1183 | } else { |
| @@ -1193,27 +1193,23 @@ async fn process_fetched_events( | |||
| 1193 | } else if event_is_patch_set_root(event) { | 1193 | } else if event_is_patch_set_root(event) { |
| 1194 | fresh_proposal_roots.insert(event.id); | 1194 | fresh_proposal_roots.insert(event.id); |
| 1195 | report.proposals.insert(event.id); | 1195 | report.proposals.insert(event.id); |
| 1196 | if !request.contributors.contains(&event.author()) | 1196 | if !request.contributors.contains(&event.pubkey) |
| 1197 | && !fresh_profiles.contains(&event.author()) | 1197 | && !fresh_profiles.contains(&event.pubkey) |
| 1198 | { | 1198 | { |
| 1199 | fresh_profiles.insert(event.author()); | 1199 | fresh_profiles.insert(event.pubkey); |
| 1200 | } | 1200 | } |
| 1201 | } else if [Kind::RelayList, Kind::Metadata].contains(&event.kind()) { | 1201 | } else if [Kind::RelayList, Kind::Metadata].contains(&event.kind) { |
| 1202 | if request | 1202 | if request.missing_contributor_profiles.contains(&event.pubkey) { |
| 1203 | .missing_contributor_profiles | 1203 | report.contributor_profiles.insert(event.pubkey); |
| 1204 | .contains(&event.author()) | ||
| 1205 | { | ||
| 1206 | report.contributor_profiles.insert(event.author()); | ||
| 1207 | } else if let Some((_, (metadata_timestamp, relay_list_timestamp))) = request | 1204 | } else if let Some((_, (metadata_timestamp, relay_list_timestamp))) = request |
| 1208 | .profiles_to_fetch_from_user_relays | 1205 | .profiles_to_fetch_from_user_relays |
| 1209 | .get_key_value(&event.author()) | 1206 | .get_key_value(&event.pubkey) |
| 1210 | { | 1207 | { |
| 1211 | if (Kind::Metadata.eq(&event.kind()) | 1208 | if (Kind::Metadata.eq(&event.kind) && event.created_at.gt(metadata_timestamp)) |
| 1212 | && event.created_at().gt(metadata_timestamp)) | 1209 | || (Kind::RelayList.eq(&event.kind) |
| 1213 | || (Kind::RelayList.eq(&event.kind()) | 1210 | && event.created_at.gt(relay_list_timestamp)) |
| 1214 | && event.created_at().gt(relay_list_timestamp)) | ||
| 1215 | { | 1211 | { |
| 1216 | report.profile_updates.insert(event.author()); | 1212 | report.profile_updates.insert(event.pubkey); |
| 1217 | } | 1213 | } |
| 1218 | } | 1214 | } |
| 1219 | save_event_in_global_cache(git_repo_path, event).await?; | 1215 | save_event_in_global_cache(git_repo_path, event).await?; |
| @@ -1224,9 +1220,9 @@ async fn process_fetched_events( | |||
| 1224 | if !request.existing_events.contains(&event.id) | 1220 | if !request.existing_events.contains(&event.id) |
| 1225 | && !event.event_ids().any(|id| report.proposals.contains(id)) | 1221 | && !event.event_ids().any(|id| report.proposals.contains(id)) |
| 1226 | { | 1222 | { |
| 1227 | if event.kind().eq(&Kind::GitPatch) && !event_is_patch_set_root(event) { | 1223 | if event.kind.eq(&Kind::GitPatch) && !event_is_patch_set_root(event) { |
| 1228 | report.commits.insert(event.id); | 1224 | report.commits.insert(event.id); |
| 1229 | } else if status_kinds().contains(&event.kind()) { | 1225 | } else if status_kinds().contains(&event.kind) { |
| 1230 | report.statuses.insert(event.id); | 1226 | report.statuses.insert(event.id); |
| 1231 | } | 1227 | } |
| 1232 | } | 1228 | } |
| @@ -1549,21 +1545,21 @@ pub async fn get_all_proposal_patch_events_from_cache( | |||
| 1549 | vec![ | 1545 | vec![ |
| 1550 | commit_events | 1546 | commit_events |
| 1551 | .iter() | 1547 | .iter() |
| 1552 | .find(|e| e.id().eq(proposal_id)) | 1548 | .find(|e| e.id.eq(proposal_id)) |
| 1553 | .context("proposal not in cache")? | 1549 | .context("proposal not in cache")? |
| 1554 | .author(), | 1550 | .pubkey, |
| 1555 | ], | 1551 | ], |
| 1556 | ] | 1552 | ] |
| 1557 | .concat() | 1553 | .concat() |
| 1558 | .iter() | 1554 | .iter() |
| 1559 | .copied() | 1555 | .copied() |
| 1560 | .collect(); | 1556 | .collect(); |
| 1561 | commit_events.retain(|e| permissioned_users.contains(&e.author())); | 1557 | commit_events.retain(|e| permissioned_users.contains(&e.pubkey)); |
| 1562 | 1558 | ||
| 1563 | let revision_roots: HashSet<nostr::EventId> = commit_events | 1559 | let revision_roots: HashSet<nostr::EventId> = commit_events |
| 1564 | .iter() | 1560 | .iter() |
| 1565 | .filter(|e| event_is_revision_root(e)) | 1561 | .filter(|e| event_is_revision_root(e)) |
| 1566 | .map(nostr::Event::id) | 1562 | .map(|e| e.id) |
| 1567 | .collect(); | 1563 | .collect(); |
| 1568 | 1564 | ||
| 1569 | if !revision_roots.is_empty() { | 1565 | if !revision_roots.is_empty() { |
| @@ -1584,7 +1580,7 @@ pub async fn get_all_proposal_patch_events_from_cache( | |||
| 1584 | 1580 | ||
| 1585 | Ok(commit_events | 1581 | Ok(commit_events |
| 1586 | .iter() | 1582 | .iter() |
| 1587 | .filter(|e| !event_is_cover_letter(e) && permissioned_users.contains(&e.author())) | 1583 | .filter(|e| !event_is_cover_letter(e) && permissioned_users.contains(&e.pubkey)) |
| 1588 | .cloned() | 1584 | .cloned() |
| 1589 | .collect()) | 1585 | .collect()) |
| 1590 | } | 1586 | } |
| @@ -1614,10 +1610,7 @@ pub async fn send_events( | |||
| 1614 | ) -> Result<()> { | 1610 | ) -> Result<()> { |
| 1615 | let fallback = [ | 1611 | let fallback = [ |
| 1616 | client.get_fallback_relays().clone(), | 1612 | client.get_fallback_relays().clone(), |
| 1617 | if events | 1613 | if events.iter().any(|e| e.kind.eq(&Kind::GitRepoAnnouncement)) { |
| 1618 | .iter() | ||
| 1619 | .any(|e| e.kind().eq(&Kind::GitRepoAnnouncement)) | ||
| 1620 | { | ||
| 1621 | client.get_blaster_relays().clone() | 1614 | client.get_blaster_relays().clone() |
| 1622 | } else { | 1615 | } else { |
| 1623 | vec![] | 1616 | vec![] |