Skip to content

Commit

Permalink
Merge #281: Add encrypted tag kind
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Feb 5, 2024
2 parents 6931585 + dd7e74e commit b59225b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bindings/nostr-ffi/src/event/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ pub enum TagKind {
Anon,
Proxy,
Emoji,
/// Encrypted
Encrypted,
Request,
Unknown {
unknown: String,
Expand Down Expand Up @@ -304,6 +306,7 @@ impl From<tag::TagKind> for TagKind {
tag::TagKind::Anon => Self::Anon,
tag::TagKind::Proxy => Self::Proxy,
tag::TagKind::Emoji => Self::Emoji,
tag::TagKind::Encrypted => Self::Encrypted,
tag::TagKind::Request => Self::Request,
tag::TagKind::Custom(unknown) => Self::Unknown { unknown },
}
Expand Down Expand Up @@ -362,6 +365,7 @@ impl From<TagKind> for tag::TagKind {
TagKind::Anon => Self::Anon,
TagKind::Proxy => Self::Proxy,
TagKind::Emoji => Self::Emoji,
TagKind::Encrypted => Self::Encrypted,
TagKind::Request => Self::Request,
TagKind::Unknown { unknown } => Self::Custom(unknown),
}
Expand Down Expand Up @@ -555,6 +559,7 @@ pub enum TagEnum {
shortcode: String,
url: String,
},
Encrypted,
Request {
event: Arc<Event>,
},
Expand Down Expand Up @@ -723,6 +728,7 @@ impl From<tag::Tag> for TagEnum {
shortcode,
url: url.to_string(),
},
tag::Tag::Encrypted => Self::Encrypted,
tag::Tag::Request(event) => Self::Request {
event: Arc::new(event.into()),
},
Expand Down Expand Up @@ -869,6 +875,7 @@ impl TryFrom<TagEnum> for tag::Tag {
shortcode,
url: UncheckedUrl::from(url),
}),
TagEnum::Encrypted => Ok(Self::Encrypted),
TagEnum::Request { event } => Ok(Self::Request(event.as_ref().deref().clone())),
TagEnum::DataVendingMachineStatusTag { status, extra_info } => {
Ok(Self::DataVendingMachineStatus {
Expand Down
8 changes: 8 additions & 0 deletions crates/nostr/src/event/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ pub enum TagKind {
Proxy,
/// Emoji
Emoji,
/// Encrypted
Encrypted,
/// Request (NIP90)
Request,
/// Custom tag kind
Expand Down Expand Up @@ -482,6 +484,7 @@ impl fmt::Display for TagKind {
Self::Anon => write!(f, "anon"),
Self::Proxy => write!(f, "proxy"),
Self::Emoji => write!(f, "emoji"),
Self::Encrypted => write!(f, "encrypted"),
Self::Request => write!(f, "request"),
Self::Custom(tag) => write!(f, "{tag}"),
}
Expand Down Expand Up @@ -543,6 +546,7 @@ where
"anon" => Self::Anon,
"proxy" => Self::Proxy,
"emoji" => Self::Emoji,
"encrypted" => Self::Encrypted,
"request" => Self::Request,
t => Self::Custom(t.to_owned()),
}
Expand Down Expand Up @@ -650,6 +654,7 @@ pub enum Tag {
/// URL to the corresponding image file of the emoji
url: UncheckedUrl,
},
Encrypted,
Request(Event),
DataVendingMachineStatus {
status: DataVendingMachineStatus,
Expand Down Expand Up @@ -760,6 +765,7 @@ impl Tag {
Self::Anon { .. } => TagKind::Anon,
Self::Proxy { .. } => TagKind::Proxy,
Self::Emoji { .. } => TagKind::Emoji,
Self::Encrypted => TagKind::Encrypted,
Self::Request(..) => TagKind::Request,
}
}
Expand Down Expand Up @@ -790,6 +796,7 @@ where
match tag_kind {
TagKind::ContentWarning => Ok(Self::ContentWarning { reason: None }),
TagKind::Anon => Ok(Self::Anon { msg: None }),
TagKind::Encrypted => Ok(Self::Encrypted),
_ => Ok(Self::Generic(tag_kind, Vec::new())),
}
} else if tag_len == 2 {
Expand Down Expand Up @@ -1266,6 +1273,7 @@ impl From<Tag> for Vec<String> {
Tag::Emoji { shortcode, url } => {
vec![TagKind::Emoji.to_string(), shortcode, url.to_string()]
}
Tag::Encrypted => vec![TagKind::Encrypted.to_string()],
Tag::Request(event) => vec![TagKind::Request.to_string(), event.as_json()],
Tag::DataVendingMachineStatus { status, extra_info } => {
let mut tag = vec![TagKind::Status.to_string(), status.to_string()];
Expand Down

0 comments on commit b59225b

Please sign in to comment.