chore: Improve maintainers handling

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb
2025-06-14 10:30:11 +00:00
parent a9a2cb2b16
commit ec08a1febc
7 changed files with 59 additions and 69 deletions

View File

@@ -342,6 +342,21 @@ impl NostrClient {
utils::add_read_relays(self.user_relays_list(user).await.ok().flatten().as_ref())
}
/// Returns the read relays of the given users if found, otherwise empty
/// vector
pub async fn read_relays_from_users(&self, users: &[PublicKey]) -> Vec<RelayUrl> {
self.fetch_events(
Filter::new()
.kind(nostr::event::Kind::RelayList)
.authors(utils::dedup(users.iter().copied())),
)
.await
.unwrap_or_default()
.into_iter()
.flat_map(|e| utils::add_read_relays(Some(&e)))
.collect()
}
/// Parse the given content and returns the details that inside it
pub async fn parse_content(&self, content: &str) -> ContentDetails {
let mut write_relays = Vec::new();

View File

@@ -111,18 +111,27 @@ impl EventBuilder {
/// Creates a new [`GitIssue`] event builder with the given
/// issue details.
pub fn new_git_issue(
repository: Coordinate,
coordinates: &[Coordinate],
content: String,
subject: Option<String>,
labels: Vec<String>,
) -> N34Result<EventBuilder> {
let mut coordinates = coordinates.iter();
let first_coordinate = coordinates.next().ok_or(N34Error::EmptyNaddrs)?;
let mut event_builder = EventBuilder::git_issue(GitIssue {
repository,
repository: first_coordinate.clone(),
content,
subject: subject.clone(),
labels: labels.into_iter().map(|l| l.trim().to_owned()).collect(),
})
.map_err(N34Error::from)?;
.map_err(N34Error::from)?
.tags(
coordinates
.clone()
.map(|c| Tag::coordinate(c.clone(), None)),
)
.tags(coordinates.map(|c| Tag::public_key(c.public_key)));
if let Some(issue_subject) = subject {
event_builder =
@@ -196,4 +205,10 @@ impl Vec<GitRepositoryAnnouncement> {
pub fn extract_relays(&self) -> Vec<RelayUrl> {
self.iter().flat_map(|n| n.relays.clone()).collect()
}
/// Extract all the maintainers from these repositories
pub fn extract_maintainers(&self) -> Vec<PublicKey> {
self.iter().flat_map(|r| r.maintainers.clone()).collect()
}
}
}