Skip to content

Commit

Permalink
feat: support uppercase k
Browse files Browse the repository at this point in the history
  • Loading branch information
reyamir committed Nov 8, 2024
1 parent 623915a commit 14a5bd2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
12 changes: 10 additions & 2 deletions bindings/nostr-sdk-ffi/src/protocol/event/tag/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ pub enum TagStandard {
},
Kind {
kind: KindEnum,
/// Whether the k tag is an uppercase K or not
uppercase: bool,
},
RelayUrl {
relay_url: String,
Expand Down Expand Up @@ -355,7 +357,10 @@ impl From<tag::TagStandard> for TagStandard {
tag::TagStandard::ExternalIdentity(identity) => Self::ExternalIdentity {
identity: identity.into(),
},
tag::TagStandard::Kind(kind) => Self::Kind { kind: kind.into() },
tag::TagStandard::Kind { kind, uppercase } => Self::Kind {
kind: kind.into(),
uppercase,
},
tag::TagStandard::Relay(url) => Self::RelayUrl {
relay_url: url.to_string(),
},
Expand Down Expand Up @@ -550,7 +555,10 @@ impl TryFrom<TagStandard> for tag::TagStandard {
coordinate: coordinate.as_ref().deref().clone(),
relay_url: relay_url.map(UncheckedUrl::from),
}),
TagStandard::Kind { kind } => Ok(Self::Kind(kind.into())),
TagStandard::Kind { kind, uppercase } => Ok(Self::Kind {
kind: kind.into(),
uppercase,
}),
TagStandard::RelayUrl { relay_url } => Ok(Self::Relay(UncheckedUrl::from(relay_url))),
TagStandard::POW { nonce, difficulty } => Ok(Self::POW {
nonce: nonce.parse()?,
Expand Down
24 changes: 16 additions & 8 deletions crates/nostr/src/event/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,10 @@ impl EventBuilder {
uppercase: true,
}));
// Kind
tags.push(Tag::from_standardized_without_cell(TagStandard::Kind(
root.kind,
)));
tags.push(Tag::from_standardized_without_cell(TagStandard::Kind {
kind: root.kind,
uppercase: true,
}));

// Add others `p` tags
tags.extend(
Expand All @@ -554,9 +555,10 @@ impl EventBuilder {
uppercase: false,
}));
// Add `k` tag of event kind
tags.push(Tag::from_standardized_without_cell(TagStandard::Kind(
reply_to.kind,
)));
tags.push(Tag::from_standardized_without_cell(TagStandard::Kind {
kind: reply_to.kind,
uppercase: false,
}));

// Add others `p` tags of reply_to event
tags.extend(
Expand Down Expand Up @@ -680,7 +682,10 @@ impl EventBuilder {
uppercase: false,
}),
Tag::public_key(event.pubkey),
Tag::from_standardized_without_cell(TagStandard::Kind(event.kind)),
Tag::from_standardized_without_cell(TagStandard::Kind {
kind: event.kind,
uppercase: false,
}),
],
)
}
Expand Down Expand Up @@ -743,7 +748,10 @@ impl EventBuilder {
tags.push(Tag::public_key(public_key));

if let Some(kind) = kind {
tags.push(Tag::from_standardized_without_cell(TagStandard::Kind(kind)));
tags.push(Tag::from_standardized_without_cell(TagStandard::Kind {
kind,
uppercase: false,
}));
}

Self::new(Kind::Reaction, reaction, tags)
Expand Down
16 changes: 8 additions & 8 deletions crates/nostr/src/event/tag/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ pub enum TagStandard {
coordinate: Coordinate,
relay_url: Option<UncheckedUrl>,
},
Kind(Kind),
Kind {
kind: Kind,
/// Whether the k tag is an uppercase K or not
uppercase: bool,
},
Relay(UncheckedUrl),
/// Proof of Work
///
Expand Down Expand Up @@ -308,10 +312,6 @@ impl TagStandard {
character: Alphabet::D,
uppercase: false,
}) => Ok(Self::Identifier(tag_1.to_string())),
TagKind::SingleLetter(SingleLetterTag {
character: Alphabet::K,
uppercase: false,
}) => Ok(Self::Kind(Kind::from_str(tag_1)?)),
TagKind::SingleLetter(SingleLetterTag {
character: Alphabet::M,
uppercase: false,
Expand Down Expand Up @@ -509,9 +509,9 @@ impl TagStandard {
character: Alphabet::A,
uppercase: false,
}),
Self::Kind(..) => TagKind::SingleLetter(SingleLetterTag {
Self::Kind { uppercase, .. } => TagKind::SingleLetter(SingleLetterTag {
character: Alphabet::K,
uppercase: false,
uppercase: *uppercase,
}),
Self::Relay(..) => TagKind::Relay,
Self::POW { .. } => TagKind::Nonce,
Expand Down Expand Up @@ -693,7 +693,7 @@ impl From<TagStandard> for Vec<String> {
vec
}
TagStandard::ExternalIdentity(identity) => identity.into(),
TagStandard::Kind(kind) => vec![tag_kind, kind.to_string()],
TagStandard::Kind { kind, .. } => vec![tag_kind, kind.to_string()],
TagStandard::Relay(url) => vec![tag_kind, url.to_string()],
TagStandard::POW { nonce, difficulty } => {
vec![tag_kind, nonce.to_string(), difficulty.to_string()]
Expand Down

0 comments on commit 14a5bd2

Please sign in to comment.