Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for NIP22 - Comment #612

Closed
wants to merge 14 commits into from
Closed

Conversation

reyamir
Copy link
Contributor

@reyamir reyamir commented Nov 8, 2024

Description

Close: #611
Support NIP22: https://github.com/nostr-protocol/nips/blob/master/22.md

Scope:

  • Add Kind::Comment
  • Support uppercase E in TagStandard::Event
  • Support uppercase K in TagStandard::Kind
  • Support uppercase I in TagStandard::ExternalIdentity
  • Support uppercase A in TagStandard::Coordinate
  • Add EventBuilder::comment
  • Add client.comment()
  • Add example

Checklist

@reyamir
Copy link
Contributor Author

reyamir commented Nov 8, 2024

Hi @yukibtc , I wonder is there a way when I set marker: None, it didn't shrink the vector with empty string too?

I reuse TagStandard::Event with added uppercase: bool instead of create a new standard for comment, but in NIP22 marker is unnecessary. But for compality I still keep marker attr. I wonder when marker: None is there a way to remove "" from vector too?

tags.push(Tag::from_standardized_without_cell(TagStandard::Event {
    event_id: root.id,
    relay_url: relay_url.clone(),
    marker: None,
    public_key: Some(root.pubkey),
    uppercase: true,
}));
"tags": [
  [
    "e",
    "b8c6832a2f2ec9172339c194b5e93f54fe7be1df7ec8389996c003302aa13214",
    "",
    "",
    "126103bfddc8df256b6e0abfd7f3797c80dcc4ea88f7c2f87dd4104220b4d65f"
  ],
  [
    "k",
    "1"
  ]
]

@reyamir
Copy link
Contributor Author

reyamir commented Nov 8, 2024

Hi @yukibtc , I wonder is there a way when I set marker: None, it didn't shrink the vector with empty string too?

I reuse TagStandard::Event with added uppercase: bool instead of create a new standard for comment, but in NIP22 marker is unnecessary. But for compality I still keep marker attr. I wonder when marker: None is there a way to remove "" from vector too?

tags.push(Tag::from_standardized_without_cell(TagStandard::Event {
    event_id: root.id,
    relay_url: relay_url.clone(),
    marker: None,
    public_key: Some(root.pubkey),
    uppercase: true,
}));
"tags": [
  [
    "e",
    "b8c6832a2f2ec9172339c194b5e93f54fe7be1df7ec8389996c003302aa13214",
    "",
    "",
    "126103bfddc8df256b6e0abfd7f3797c80dcc4ea88f7c2f87dd4104220b4d65f"
  ],
  [
    "k",
    "1"
  ]
]

I've fixed by using:

if let Some(marker) = marker {
    tag.resize_with(3, String::new);
    tag.push(marker.to_string());

    if let Some(public_key) = public_key {
        tag.resize_with(4, String::new);
        tag.push(public_key.to_string());
    }
} else if let Some(public_key) = public_key {
    tag.resize_with(3, String::new);
    tag.push(public_key.to_string());
}

@reyamir
Copy link
Contributor Author

reyamir commented Nov 8, 2024

My PR is only supporting comment on EventId - e tag, but NIP22 allow comment on Coordinate - a tag and ExternalIdentity - i tag. Do you have any ideas for implement it? create each comment function for each thing is a bit complex. @yukibtc

@reyamir reyamir marked this pull request as ready for review November 9, 2024 01:42
Copy link
Member

@yukibtc yukibtc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I done some changes/fixes in the master branch. I'll do a rebase and squash the commits during the cherry-picking.

My PR is only supporting comment on EventId - e tag, but NIP22 allow comment on Coordinate - a tag and ExternalIdentity - i tag. Do you have any ideas for implement it? create each comment function for each thing is a bit complex.

I'll add the support to these later, thanks!

///
/// <https://github.com/nostr-protocol/nips/blob/master/22.md>
#[inline]
pub async fn comment<S>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking to remove all these kind of methods from Client to keep the APIs more cleaned. At least, the ones that can be simply constructed directly with the EventBuilder:

let builder = EventBuilder::<name>;
self.send_event_builder(builder).await

The more complex ones (the ones that requre more than 2 steps, are dangerous if used incorrectly or are very frequently used) can be left, like set_metadata, gift_wrap, send_private_msg, etc.

This is still an idea. What do you think?
I started removing these methods in PR #608

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I prefer using EventBuilder than client's method

@yukibtc yukibtc closed this in 8c6b2a1 Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support nip22 comments
2 participants