refactor
This commit is contained in:
@@ -40,27 +40,24 @@ impl Announcement {
|
||||
let mut maintainers: Vec<PublicKey> = Vec::new();
|
||||
|
||||
for tag in event.tags.iter() {
|
||||
let values: &[String] = tag.as_slice();
|
||||
match tag.kind() {
|
||||
"d" => id = tag.content().map(str::to_owned),
|
||||
"name" => name = tag.content().map(str::to_owned),
|
||||
"description" => description = tag.content().map(str::to_owned),
|
||||
"web" => web.extend(values.iter().skip(1).cloned()),
|
||||
"clone" => clone.extend(values.iter().skip(1).cloned()),
|
||||
"relays" => relays.extend(values.iter().skip(1).cloned()),
|
||||
"r" => {
|
||||
if values.get(2).map(String::as_str) == Some("euc") {
|
||||
euc = tag.content().map(str::to_owned);
|
||||
}
|
||||
// The `d` tag isn't part of the NIP-34 tag codec; parse it directly.
|
||||
if tag.kind() == "d" {
|
||||
id = tag.content().map(str::to_owned);
|
||||
continue;
|
||||
}
|
||||
|
||||
match Nip34Tag::parse(tag.as_slice()) {
|
||||
Ok(Nip34Tag::Name(value)) => name = Some(value),
|
||||
Ok(Nip34Tag::Description(value)) => description = Some(value),
|
||||
Ok(Nip34Tag::Web(urls)) => web.extend(urls.into_iter().map(|url| url.to_string())),
|
||||
Ok(Nip34Tag::Clone(urls)) => {
|
||||
clone.extend(urls.into_iter().map(|url| url.to_string()))
|
||||
}
|
||||
"maintainers" => {
|
||||
maintainers.extend(
|
||||
values
|
||||
.iter()
|
||||
.skip(1)
|
||||
.filter_map(|v| PublicKey::from_hex(v).ok()),
|
||||
);
|
||||
Ok(Nip34Tag::Relays(urls)) => {
|
||||
relays.extend(urls.into_iter().map(|url| url.to_string()))
|
||||
}
|
||||
Ok(Nip34Tag::EarliestUniqueCommitId(commit)) => euc = Some(commit.to_string()),
|
||||
Ok(Nip34Tag::Maintainers(keys)) => maintainers.extend(keys),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -81,6 +78,6 @@ impl Announcement {
|
||||
|
||||
/// The repository address of this announcement.
|
||||
pub fn addr(&self) -> crate::RepoAddr {
|
||||
crate::RepoAddr::new(self.owner, self.id.clone())
|
||||
crate::repo_addr(self.owner, self.id.clone())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user