feat: out-of-box experience #2
@@ -4,18 +4,18 @@ use nostr::prelude::*;
|
|||||||
/// Parsed NIP-34 repository announcement (plain data, ready for the UI).
|
/// Parsed NIP-34 repository announcement (plain data, ready for the UI).
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Announcement {
|
pub struct Announcement {
|
||||||
|
/// Repository ID (`d` tag).
|
||||||
|
pub id: String,
|
||||||
/// Author of the announcement event.
|
/// Author of the announcement event.
|
||||||
pub owner: PublicKey,
|
pub owner: PublicKey,
|
||||||
/// When the announcement was published (for latest-wins resolution).
|
/// When the announcement was published (for latest-wins resolution).
|
||||||
pub created_at: Timestamp,
|
pub created_at: Timestamp,
|
||||||
/// Repository ID (`d` tag).
|
|
||||||
pub id: String,
|
|
||||||
pub name: Option<SharedString>,
|
pub name: Option<SharedString>,
|
||||||
pub description: Option<SharedString>,
|
pub description: Option<SharedString>,
|
||||||
/// Webpage URLs for browsing.
|
/// Webpage URLs for browsing.
|
||||||
pub web: Vec<String>,
|
pub web: Vec<Url>,
|
||||||
/// URLs for `git clone`.
|
/// URLs for `git clone`.
|
||||||
pub clone: Vec<String>,
|
pub clone: Vec<Url>,
|
||||||
/// Relays the repository monitors for patches and issues.
|
/// Relays the repository monitors for patches and issues.
|
||||||
pub relays: Vec<RelayUrl>,
|
pub relays: Vec<RelayUrl>,
|
||||||
/// Earliest unique commit ID (`r` tag with `euc` marker).
|
/// Earliest unique commit ID (`r` tag with `euc` marker).
|
||||||
@@ -33,36 +33,25 @@ impl Announcement {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut id: Option<String> = None;
|
let id = event.tags.identifier()?;
|
||||||
|
|
||||||
|
let mut hashtags: Vec<String> = Vec::new();
|
||||||
|
hashtags.extend(event.tags.hashtags().map(|t| t.to_string()));
|
||||||
|
|
||||||
let mut name: Option<SharedString> = None;
|
let mut name: Option<SharedString> = None;
|
||||||
let mut description: Option<SharedString> = None;
|
let mut description: Option<SharedString> = None;
|
||||||
let mut web: Vec<String> = Vec::new();
|
let mut web: Vec<Url> = Vec::new();
|
||||||
let mut clone: Vec<String> = Vec::new();
|
let mut clone: Vec<Url> = Vec::new();
|
||||||
let mut relays: Vec<RelayUrl> = Vec::new();
|
let mut relays: Vec<RelayUrl> = Vec::new();
|
||||||
let mut euc: Option<String> = None;
|
let mut euc: Option<String> = None;
|
||||||
let mut maintainers: Vec<PublicKey> = Vec::new();
|
let mut maintainers: Vec<PublicKey> = Vec::new();
|
||||||
let mut hashtags: Vec<String> = Vec::new();
|
|
||||||
|
|
||||||
for tag in event.tags.iter() {
|
for tag in event.tags.iter() {
|
||||||
// The `d` and `t` tags aren't part of the NIP-34 tag codec; parse them directly.
|
|
||||||
if tag.kind() == "d" {
|
|
||||||
id = tag.content().map(str::to_owned);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if tag.kind() == "t" {
|
|
||||||
if let Some(value) = tag.content() {
|
|
||||||
hashtags.push(value.to_owned());
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
match Nip34Tag::parse(tag.as_slice()) {
|
match Nip34Tag::parse(tag.as_slice()) {
|
||||||
Ok(Nip34Tag::Name(value)) => name = Some(value.into()),
|
Ok(Nip34Tag::Name(value)) => name = Some(value.into()),
|
||||||
Ok(Nip34Tag::Description(value)) => description = Some(value.into()),
|
Ok(Nip34Tag::Description(value)) => description = Some(value.into()),
|
||||||
Ok(Nip34Tag::Web(urls)) => web.extend(urls.into_iter().map(|url| url.to_string())),
|
Ok(Nip34Tag::Web(urls)) => web.extend(urls),
|
||||||
Ok(Nip34Tag::Clone(urls)) => {
|
Ok(Nip34Tag::Clone(urls)) => clone.extend(urls),
|
||||||
clone.extend(urls.into_iter().map(|url| url.to_string()))
|
|
||||||
}
|
|
||||||
Ok(Nip34Tag::Relays(urls)) => relays.extend(urls),
|
Ok(Nip34Tag::Relays(urls)) => relays.extend(urls),
|
||||||
Ok(Nip34Tag::EarliestUniqueCommitId(commit)) => euc = Some(commit.to_string()),
|
Ok(Nip34Tag::EarliestUniqueCommitId(commit)) => euc = Some(commit.to_string()),
|
||||||
Ok(Nip34Tag::Maintainers(keys)) => maintainers.extend(keys),
|
Ok(Nip34Tag::Maintainers(keys)) => maintainers.extend(keys),
|
||||||
@@ -73,7 +62,7 @@ impl Announcement {
|
|||||||
Some(Self {
|
Some(Self {
|
||||||
owner: event.pubkey,
|
owner: event.pubkey,
|
||||||
created_at: event.created_at,
|
created_at: event.created_at,
|
||||||
id: id?,
|
id,
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
web,
|
web,
|
||||||
@@ -141,8 +130,14 @@ mod tests {
|
|||||||
announcement.description.as_deref(),
|
announcement.description.as_deref(),
|
||||||
Some("A test repository")
|
Some("A test repository")
|
||||||
);
|
);
|
||||||
assert_eq!(announcement.web, vec!["https://example.com/repo"]);
|
assert_eq!(
|
||||||
assert_eq!(announcement.clone, vec!["https://example.com/repo.git"]);
|
announcement.web,
|
||||||
|
vec![Url::parse("https://example.com/repo").unwrap()]
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
announcement.clone,
|
||||||
|
vec![Url::parse("https://example.com/repo.git").unwrap()]
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
announcement.relays,
|
announcement.relays,
|
||||||
vec![RelayUrl::parse("wss://relay.example.com").unwrap()]
|
vec![RelayUrl::parse("wss://relay.example.com").unwrap()]
|
||||||
|
|||||||
@@ -60,7 +60,10 @@ impl RepoListView {
|
|||||||
.clone()
|
.clone()
|
||||||
.unwrap_or_else(|| SharedString::from(announcement.id.clone()));
|
.unwrap_or_else(|| SharedString::from(announcement.id.clone()));
|
||||||
|
|
||||||
let description = announcement.description.clone().unwrap_or_default();
|
let description = announcement
|
||||||
|
.description
|
||||||
|
.clone()
|
||||||
|
.unwrap_or(SharedString::from("No description"));
|
||||||
|
|
||||||
let activity = last_activity
|
let activity = last_activity
|
||||||
.map(relative_time)
|
.map(relative_time)
|
||||||
@@ -103,8 +106,7 @@ impl RepoListView {
|
|||||||
Avatar::new()
|
Avatar::new()
|
||||||
.name(owner.name())
|
.name(owner.name())
|
||||||
.when_some(owner.picture(), |this, url| this.src(url))
|
.when_some(owner.picture(), |this, url| this.src(url))
|
||||||
.small()
|
.small(),
|
||||||
.border_0(),
|
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
|
|||||||
Reference in New Issue
Block a user