diff options
Diffstat (limited to 'src/lib/client.rs')
| -rw-r--r-- | src/lib/client.rs | 66 |
1 files changed, 46 insertions, 20 deletions
diff --git a/src/lib/client.rs b/src/lib/client.rs index 0984b19..92bf266 100644 --- a/src/lib/client.rs +++ b/src/lib/client.rs | |||
| @@ -1063,17 +1063,17 @@ pub async fn get_repo_ref_from_cache( | |||
| 1063 | let mut repo_events = vec![]; | 1063 | let mut repo_events = vec![]; |
| 1064 | loop { | 1064 | loop { |
| 1065 | new_coordinate = false; | 1065 | new_coordinate = false; |
| 1066 | let repo_events_filter = | 1066 | let repo_events_filter = get_filter_repo_ann_events( |
| 1067 | get_filter_repo_events(&HashSet::from_iter(maintainers.iter().map(|m| { | 1067 | &HashSet::from_iter(maintainers.iter().map(|m| Nip19Coordinate { |
| 1068 | Nip19Coordinate { | 1068 | coordinate: Coordinate { |
| 1069 | coordinate: Coordinate { | 1069 | kind: Kind::GitRepoAnnouncement, |
| 1070 | kind: Kind::GitRepoAnnouncement, | 1070 | public_key: *m, |
| 1071 | public_key: *m, | 1071 | identifier: repo_coordinate.identifier.to_string(), |
| 1072 | identifier: repo_coordinate.identifier.to_string(), | 1072 | }, |
| 1073 | }, | 1073 | relays: vec![], |
| 1074 | relays: vec![], | 1074 | })), |
| 1075 | } | 1075 | true, |
| 1076 | }))); | 1076 | ); |
| 1077 | 1077 | ||
| 1078 | let events = [ | 1078 | let events = [ |
| 1079 | get_event_from_global_cache(git_repo_path, vec![repo_events_filter.clone()]).await?, | 1079 | get_event_from_global_cache(git_repo_path, vec![repo_events_filter.clone()]).await?, |
| @@ -1184,7 +1184,7 @@ pub async fn get_state_from_cache( | |||
| 1184 | RepoState::try_from( | 1184 | RepoState::try_from( |
| 1185 | get_events_from_local_cache( | 1185 | get_events_from_local_cache( |
| 1186 | git_repo_path, | 1186 | git_repo_path, |
| 1187 | vec![get_filter_state_events(&repo_ref.coordinates())], | 1187 | vec![get_filter_state_events(&repo_ref.coordinates(), true)], |
| 1188 | ) | 1188 | ) |
| 1189 | .await?, | 1189 | .await?, |
| 1190 | ) | 1190 | ) |
| @@ -1192,7 +1192,7 @@ pub async fn get_state_from_cache( | |||
| 1192 | RepoState::try_from( | 1192 | RepoState::try_from( |
| 1193 | get_event_from_global_cache( | 1193 | get_event_from_global_cache( |
| 1194 | git_repo_path, | 1194 | git_repo_path, |
| 1195 | vec![get_filter_state_events(&repo_ref.coordinates())], | 1195 | vec![get_filter_state_events(&repo_ref.coordinates(), true)], |
| 1196 | ) | 1196 | ) |
| 1197 | .await?, | 1197 | .await?, |
| 1198 | ) | 1198 | ) |
| @@ -1666,8 +1666,8 @@ pub fn get_fetch_filters( | |||
| 1666 | vec![] | 1666 | vec![] |
| 1667 | } else { | 1667 | } else { |
| 1668 | vec![ | 1668 | vec![ |
| 1669 | get_filter_state_events(repo_coordinates), | 1669 | get_filter_state_events(repo_coordinates, false), |
| 1670 | get_filter_repo_events(repo_coordinates), | 1670 | get_filter_repo_ann_events(repo_coordinates, false), |
| 1671 | nostr::Filter::default() | 1671 | nostr::Filter::default() |
| 1672 | .kinds(vec![Kind::GitPatch, Kind::EventDeletion, KIND_PULL_REQUEST]) | 1672 | .kinds(vec![Kind::GitPatch, Kind::EventDeletion, KIND_PULL_REQUEST]) |
| 1673 | .custom_tags( | 1673 | .custom_tags( |
| @@ -1717,25 +1717,51 @@ pub fn get_fetch_filters( | |||
| 1717 | .concat() | 1717 | .concat() |
| 1718 | } | 1718 | } |
| 1719 | 1719 | ||
| 1720 | pub fn get_filter_repo_events(repo_coordinates: &HashSet<Nip19Coordinate>) -> nostr::Filter { | 1720 | pub fn get_filter_repo_ann_events( |
| 1721 | nostr::Filter::default() | 1721 | repo_coordinates: &HashSet<Nip19Coordinate>, |
| 1722 | maintainers_only: bool, | ||
| 1723 | ) -> nostr::Filter { | ||
| 1724 | let filter = nostr::Filter::default() | ||
| 1722 | .kind(Kind::GitRepoAnnouncement) | 1725 | .kind(Kind::GitRepoAnnouncement) |
| 1723 | .identifiers( | 1726 | .identifiers( |
| 1724 | repo_coordinates | 1727 | repo_coordinates |
| 1725 | .iter() | 1728 | .iter() |
| 1726 | .map(|c| c.identifier.clone()) | 1729 | .map(|c| c.identifier.clone()) |
| 1727 | .collect::<Vec<String>>(), | 1730 | .collect::<Vec<String>>(), |
| 1731 | ); | ||
| 1732 | if maintainers_only { | ||
| 1733 | filter.authors( | ||
| 1734 | repo_coordinates | ||
| 1735 | .iter() | ||
| 1736 | .map(|c| c.coordinate.public_key) | ||
| 1737 | .collect::<Vec<PublicKey>>(), | ||
| 1728 | ) | 1738 | ) |
| 1739 | } else { | ||
| 1740 | filter | ||
| 1741 | } | ||
| 1729 | } | 1742 | } |
| 1730 | 1743 | ||
| 1731 | pub static STATE_KIND: nostr::Kind = Kind::Custom(30618); | 1744 | pub static STATE_KIND: nostr::Kind = Kind::Custom(30618); |
| 1732 | pub fn get_filter_state_events(repo_coordinates: &HashSet<Nip19Coordinate>) -> nostr::Filter { | 1745 | pub fn get_filter_state_events( |
| 1733 | nostr::Filter::default().kind(STATE_KIND).identifiers( | 1746 | repo_coordinates: &HashSet<Nip19Coordinate>, |
| 1747 | maintainers_only: bool, | ||
| 1748 | ) -> nostr::Filter { | ||
| 1749 | let filter = nostr::Filter::default().kind(STATE_KIND).identifiers( | ||
| 1734 | repo_coordinates | 1750 | repo_coordinates |
| 1735 | .iter() | 1751 | .iter() |
| 1736 | .map(|c| c.identifier.clone()) | 1752 | .map(|c| c.identifier.clone()) |
| 1737 | .collect::<Vec<String>>(), | 1753 | .collect::<Vec<String>>(), |
| 1738 | ) | 1754 | ); |
| 1755 | if maintainers_only { | ||
| 1756 | filter.authors( | ||
| 1757 | repo_coordinates | ||
| 1758 | .iter() | ||
| 1759 | .map(|c| c.coordinate.public_key) | ||
| 1760 | .collect::<Vec<PublicKey>>(), | ||
| 1761 | ) | ||
| 1762 | } else { | ||
| 1763 | filter | ||
| 1764 | } | ||
| 1739 | } | 1765 | } |
| 1740 | 1766 | ||
| 1741 | pub fn get_filter_contributor_profiles(contributors: HashSet<PublicKey>) -> nostr::Filter { | 1767 | pub fn get_filter_contributor_profiles(contributors: HashSet<PublicKey>) -> nostr::Filter { |