Skip to content

Commit

Permalink
feat: support tag standard for q tag
Browse files Browse the repository at this point in the history
  • Loading branch information
reyamir committed Nov 9, 2024
1 parent 984f7f2 commit 8403246
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
24 changes: 24 additions & 0 deletions bindings/nostr-sdk-ffi/src/protocol/event/tag/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ pub enum TagStandard {
/// Whether the e tag is an uppercase E or not
uppercase: bool,
},
Quote {
event_id: Arc<EventId>,
relay_url: Option<String>,
/// Should be the public key of the author of the referenced event
public_key: Option<Arc<PublicKey>>,
},
/// Git clone (`clone` tag)
///
/// <https://github.com/nostr-protocol/nips/blob/master/34.md>
Expand Down Expand Up @@ -295,6 +301,15 @@ impl From<tag::TagStandard> for TagStandard {
public_key: public_key.map(|p| Arc::new(p.into())),
uppercase,
},
tag::TagStandard::Quote {
event_id,
relay_url,
public_key,
} => Self::Quote {
event_id: Arc::new(event_id.into()),
relay_url: relay_url.map(|u| u.to_string()),
public_key: public_key.map(|p| Arc::new(p.into())),
},
tag::TagStandard::GitClone(urls) => Self::GitClone {
urls: urls.into_iter().map(|r| r.to_string()).collect(),
},
Expand Down Expand Up @@ -502,6 +517,15 @@ impl TryFrom<TagStandard> for tag::TagStandard {
public_key: public_key.map(|p| **p),
uppercase,
}),
TagStandard::Quote {
event_id,
relay_url,
public_key,
} => Ok(Self::Quote {
event_id: **event_id,
relay_url: relay_url.map(UncheckedUrl::from),
public_key: public_key.map(|p| **p),
}),
TagStandard::GitClone { urls } => {
let mut parsed_urls: Vec<Url> = Vec::with_capacity(urls.len());
for url in urls.into_iter() {
Expand Down
8 changes: 8 additions & 0 deletions crates/nostr/src/event/tag/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ impl<'a> TagKind<'a> {
Self::SingleLetter(SingleLetterTag::lowercase(Alphabet::T))
}

/// Construct `q` kind
///
/// Shorthand for `TagKind::SingleLetter(SingleLetterTag::lowercase(Alphabet::Q))`.
#[inline]
pub fn q() -> Self {
Self::SingleLetter(SingleLetterTag::lowercase(Alphabet::Q))
}

/// Construct [`TagKind::Custom`]
///
/// Shorthand for `TagKind::Custom(Cow::from(...))`.
Expand Down
29 changes: 29 additions & 0 deletions crates/nostr/src/event/tag/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ pub enum TagStandard {
/// Whether the e tag is an uppercase E or not
uppercase: bool,
},
/// Quote
///
/// <https://github.com/nostr-protocol/nips/blob/master/18.md>
Quote {
event_id: EventId,
relay_url: Option<UncheckedUrl>,
/// Should be the public key of the author of the referenced event
public_key: Option<PublicKey>,
},
/// Report event
///
/// <https://github.com/nostr-protocol/nips/blob/master/56.md>
Expand Down Expand Up @@ -468,6 +477,10 @@ impl TagStandard {
character: Alphabet::E,
uppercase: *uppercase,
}),
Self::Quote { .. } => TagKind::SingleLetter(SingleLetterTag {
character: Alphabet::E,
uppercase: false,
}),
Self::EventReport(..) => TagKind::SingleLetter(SingleLetterTag::lowercase(Alphabet::E)),
Self::GitClone(..) => TagKind::Clone,
Self::GitCommit(..) => TagKind::Commit,
Expand Down Expand Up @@ -617,6 +630,22 @@ impl From<TagStandard> for Vec<String> {
}
tag
}
TagStandard::Quote {
event_id,
relay_url,
public_key,
..
} => {
let mut tag = vec![tag_kind, event_id.to_hex()];
if let Some(relay_url) = relay_url {
tag.push(relay_url.to_string());
}
if let Some(public_key) = public_key {
tag.resize_with(3, String::new);
tag.push(public_key.to_string());
}
tag
}
TagStandard::PublicKey {
public_key,
relay_url,
Expand Down

0 comments on commit 8403246

Please sign in to comment.