Skip to content

Commit 527d11e

Browse files
committed
nostr: add identifier arg to NIP-51 EventBuilder set constructors
Closes #466 Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent c4a64ad commit 527d11e

File tree

4 files changed

+83
-52
lines changed

4 files changed

+83
-52
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
* nostr: rename NIP-51 `EventBuilder` set constructors and `Kind` variants ([Yuki Kishimoto])
3131
* nostr: small adj. to NIP-47 `ListTransactionsRequestParams` and `LookupInvoiceResponseResult` structs ([Yuki Kishimoto])
32+
* nostr: add `identifier` arg to NIP-51 `EventBuilder` set constructors ([Yuki Kishimoto])
3233
* pool: use per-purpose dedicated relay channels ([Yuki Kishimoto])
3334
* pool: return relay urls to which `messages`/`events` have or not been sent for `send_*` and `batch_*` methods ([Yuki Kishimoto])
3435
* ffi(sdk): convert `RelayPool::handle_notifications` method to async/future ([Yuki Kishimoto])

bindings/nostr-ffi/src/event/builder.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -686,49 +686,56 @@ impl EventBuilder {
686686
///
687687
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
688688
#[uniffi::constructor]
689-
pub fn follow_set(public_keys: Vec<Arc<PublicKey>>) -> Self {
689+
pub fn follow_set(identifier: &str, public_keys: Vec<Arc<PublicKey>>) -> Self {
690690
Self {
691-
inner: nostr::EventBuilder::follow_set(public_keys.into_iter().map(|p| **p)),
691+
inner: nostr::EventBuilder::follow_set(
692+
identifier,
693+
public_keys.into_iter().map(|p| **p),
694+
),
692695
}
693696
}
694697

695698
/// Relay set
696699
///
697700
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
698701
#[uniffi::constructor]
699-
pub fn relay_set(relays: Vec<String>) -> Self {
702+
pub fn relay_set(identifier: &str, relays: Vec<String>) -> Self {
700703
Self {
701-
inner: nostr::EventBuilder::relay_set(relays.into_iter().map(UncheckedUrl::from)),
704+
inner: nostr::EventBuilder::relay_set(
705+
identifier,
706+
relays.into_iter().map(UncheckedUrl::from),
707+
),
702708
}
703709
}
704710

705711
/// Bookmark set
706712
///
707713
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
708714
#[uniffi::constructor]
709-
pub fn bookmarks_set(list: Bookmarks) -> Result<Self> {
715+
pub fn bookmarks_set(identifier: &str, list: Bookmarks) -> Result<Self> {
710716
Ok(Self {
711-
inner: nostr::EventBuilder::bookmarks_set(list.try_into()?),
717+
inner: nostr::EventBuilder::bookmarks_set(identifier, list.try_into()?),
712718
})
713719
}
714720

715721
/// Article Curation set
716722
///
717723
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
718724
#[uniffi::constructor]
719-
pub fn articles_curation_set(list: ArticlesCuration) -> Self {
725+
pub fn articles_curation_set(identifier: &str, list: ArticlesCuration) -> Self {
720726
Self {
721-
inner: nostr::EventBuilder::articles_curation_set(list.into()),
727+
inner: nostr::EventBuilder::articles_curation_set(identifier, list.into()),
722728
}
723729
}
724730

725731
/// Videos Curation set
726732
///
727733
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
728734
#[uniffi::constructor]
729-
pub fn videos_curation_set(video: Vec<Arc<Coordinate>>) -> Self {
735+
pub fn videos_curation_set(identifier: &str, video: Vec<Arc<Coordinate>>) -> Self {
730736
Self {
731737
inner: nostr::EventBuilder::videos_curation_set(
738+
identifier,
732739
video.into_iter().map(|c| c.as_ref().deref().clone()),
733740
),
734741
}
@@ -738,19 +745,19 @@ impl EventBuilder {
738745
///
739746
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
740747
#[uniffi::constructor]
741-
pub fn interest_set(hashtags: Vec<String>) -> Self {
748+
pub fn interest_set(identifier: &str, hashtags: Vec<String>) -> Self {
742749
Self {
743-
inner: nostr::EventBuilder::interest_set(hashtags),
750+
inner: nostr::EventBuilder::interest_set(identifier, hashtags),
744751
}
745752
}
746753

747754
/// Emoji set
748755
///
749756
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
750757
#[uniffi::constructor]
751-
pub fn emoji_set(emojis: Vec<EmojiInfo>) -> Self {
758+
pub fn emoji_set(identifier: &str, emojis: Vec<EmojiInfo>) -> Self {
752759
Self {
753-
inner: nostr::EventBuilder::emoji_set(emojis.into_iter().map(|e| e.into())),
760+
inner: nostr::EventBuilder::emoji_set(identifier, emojis.into_iter().map(|e| e.into())),
754761
}
755762
}
756763

bindings/nostr-js/src/event/builder.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -705,69 +705,72 @@ impl JsEventBuilder {
705705
///
706706
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
707707
#[wasm_bindgen(js_name = followSet)]
708-
pub fn follow_set(public_keys: Vec<JsPublicKey>) -> Self {
708+
pub fn follow_set(identifier: &str, public_keys: Vec<JsPublicKey>) -> Self {
709709
Self {
710-
inner: EventBuilder::follow_set(public_keys.into_iter().map(|p| p.into())),
710+
inner: EventBuilder::follow_set(identifier, public_keys.into_iter().map(|p| p.into())),
711711
}
712712
}
713713

714714
/// Relay set
715715
///
716716
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
717717
#[wasm_bindgen(js_name = relaySet)]
718-
pub fn relay_set(relays: Vec<String>) -> Self {
718+
pub fn relay_set(identifier: &str, relays: Vec<String>) -> Self {
719719
Self {
720-
inner: EventBuilder::relay_set(relays.into_iter().map(UncheckedUrl::from)),
720+
inner: EventBuilder::relay_set(identifier, relays.into_iter().map(UncheckedUrl::from)),
721721
}
722722
}
723723

724724
/// Bookmark set
725725
///
726726
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
727727
#[wasm_bindgen(js_name = bookmarksSet)]
728-
pub fn bookmarks_set(list: &JsBookmarks) -> Result<JsEventBuilder> {
728+
pub fn bookmarks_set(identifier: &str, list: &JsBookmarks) -> Result<JsEventBuilder> {
729729
Ok(Self {
730-
inner: EventBuilder::bookmarks_set(list.clone().try_into()?),
730+
inner: EventBuilder::bookmarks_set(identifier, list.clone().try_into()?),
731731
})
732732
}
733733

734734
/// Article Curation set
735735
///
736736
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
737737
#[wasm_bindgen(js_name = articlesCurationSet)]
738-
pub fn articles_curation_set(list: &JsArticlesCuration) -> Self {
738+
pub fn articles_curation_set(identifier: &str, list: &JsArticlesCuration) -> Self {
739739
Self {
740-
inner: EventBuilder::articles_curation_set(list.clone().into()),
740+
inner: EventBuilder::articles_curation_set(identifier, list.clone().into()),
741741
}
742742
}
743743

744744
/// Videos Curation set
745745
///
746746
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
747747
#[wasm_bindgen(js_name = videosCurationSet)]
748-
pub fn videos_curation_set(video: Vec<JsCoordinate>) -> Self {
748+
pub fn videos_curation_set(identifier: &str, video: Vec<JsCoordinate>) -> Self {
749749
Self {
750-
inner: EventBuilder::videos_curation_set(video.into_iter().map(|c| c.deref().clone())),
750+
inner: EventBuilder::videos_curation_set(
751+
identifier,
752+
video.into_iter().map(|c| c.deref().clone()),
753+
),
751754
}
752755
}
753756

754757
/// Interest set
755758
///
756759
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
757760
#[wasm_bindgen(js_name = interestSet)]
758-
pub fn interest_set(hashtags: Vec<String>) -> Self {
761+
pub fn interest_set(identifier: &str, hashtags: Vec<String>) -> Self {
759762
Self {
760-
inner: EventBuilder::interest_set(hashtags),
763+
inner: EventBuilder::interest_set(identifier, hashtags),
761764
}
762765
}
763766

764767
/// Emoji set
765768
///
766769
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
767770
#[wasm_bindgen(js_name = emojiSet)]
768-
pub fn emoji_set(emoji: Vec<JsEmojiInfo>) -> Self {
771+
pub fn emoji_set(identifier: &str, emoji: Vec<JsEmojiInfo>) -> Self {
769772
Self {
770-
inner: EventBuilder::emoji_set(emoji.into_iter().map(|e| e.into())),
773+
inner: EventBuilder::emoji_set(identifier, emoji.into_iter().map(|e| e.into())),
771774
}
772775
}
773776

crates/nostr/src/event/builder.rs

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,95 +1508,115 @@ impl EventBuilder {
15081508
/// Follow set
15091509
///
15101510
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
1511-
#[inline]
1512-
pub fn follow_set<I>(public_keys: I) -> Self
1511+
pub fn follow_set<ID, I>(identifier: ID, public_keys: I) -> Self
15131512
where
1513+
ID: Into<String>,
15141514
I: IntoIterator<Item = PublicKey>,
15151515
{
1516+
let tags: Vec<Tag> = vec![Tag::identifier(identifier)];
15161517
Self::new(
15171518
Kind::FollowSet,
15181519
"",
1519-
public_keys.into_iter().map(Tag::public_key),
1520+
tags.into_iter()
1521+
.chain(public_keys.into_iter().map(Tag::public_key)),
15201522
)
15211523
}
15221524

15231525
/// Relay set
15241526
///
15251527
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
1526-
#[inline]
1527-
pub fn relay_set<I>(relay: I) -> Self
1528+
pub fn relay_set<ID, I>(identifier: ID, relays: I) -> Self
15281529
where
1530+
ID: Into<String>,
15291531
I: IntoIterator<Item = UncheckedUrl>,
15301532
{
1533+
let tags: Vec<Tag> = vec![Tag::identifier(identifier)];
15311534
Self::new(
15321535
Kind::RelaySet,
15331536
"",
1534-
relay
1535-
.into_iter()
1536-
.map(|r| Tag::from_standardized_without_cell(TagStandard::Relay(r))),
1537+
tags.into_iter().chain(
1538+
relays
1539+
.into_iter()
1540+
.map(|r| Tag::from_standardized_without_cell(TagStandard::Relay(r))),
1541+
),
15371542
)
15381543
}
15391544

15401545
/// Bookmark set
15411546
///
15421547
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
1543-
#[inline]
1544-
pub fn bookmarks_set(list: Bookmarks) -> Self {
1545-
let tags: Vec<Tag> = list.into();
1548+
pub fn bookmarks_set<ID>(identifier: ID, list: Bookmarks) -> Self
1549+
where
1550+
ID: Into<String>,
1551+
{
1552+
let mut tags: Vec<Tag> = list.into();
1553+
tags.push(Tag::identifier(identifier));
15461554
Self::new(Kind::BookmarkSet, "", tags)
15471555
}
15481556

15491557
/// Article Curation set
15501558
///
15511559
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
1552-
#[inline]
1553-
pub fn articles_curation_set(list: ArticlesCuration) -> Self {
1554-
let tags: Vec<Tag> = list.into();
1560+
pub fn articles_curation_set<ID>(identifier: ID, list: ArticlesCuration) -> Self
1561+
where
1562+
ID: Into<String>,
1563+
{
1564+
let mut tags: Vec<Tag> = list.into();
1565+
tags.push(Tag::identifier(identifier));
15551566
Self::new(Kind::ArticlesCurationSet, "", tags)
15561567
}
15571568

15581569
/// Videos Curation set
15591570
///
15601571
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
1561-
#[inline]
1562-
pub fn videos_curation_set<I>(video: I) -> Self
1572+
pub fn videos_curation_set<ID, I>(identifier: ID, video: I) -> Self
15631573
where
1574+
ID: Into<String>,
15641575
I: IntoIterator<Item = Coordinate>,
15651576
{
1577+
let tags: Vec<Tag> = vec![Tag::identifier(identifier)];
15661578
Self::new(
15671579
Kind::VideosCurationSet,
15681580
"",
1569-
video.into_iter().map(Tag::from),
1581+
tags.into_iter()
1582+
.chain(video.into_iter().map(Tag::coordinate)),
15701583
)
15711584
}
15721585

15731586
/// Interest set
15741587
///
15751588
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
1576-
#[inline]
1577-
pub fn interest_set<I, S>(hashtags: I) -> Self
1589+
pub fn interest_set<ID, I, S>(identifier: ID, hashtags: I) -> Self
15781590
where
1591+
ID: Into<String>,
15791592
I: IntoIterator<Item = S>,
15801593
S: Into<String>,
15811594
{
1595+
let tags: Vec<Tag> = vec![Tag::identifier(identifier)];
15821596
Self::new(
15831597
Kind::InterestSet,
15841598
"",
1585-
hashtags.into_iter().map(|t| Tag::hashtag(t)),
1599+
tags.into_iter()
1600+
.chain(hashtags.into_iter().map(Tag::hashtag)),
15861601
)
15871602
}
15881603

15891604
/// Emoji set
15901605
///
15911606
/// <https://github.com/nostr-protocol/nips/blob/master/51.md>
1592-
pub fn emoji_set<I>(emoji: I) -> Self
1607+
pub fn emoji_set<ID, I>(identifier: ID, emojis: I) -> Self
15931608
where
1609+
ID: Into<String>,
15941610
I: IntoIterator<Item = (String, UncheckedUrl)>,
15951611
{
1596-
let tags = emoji.into_iter().map(|(s, url)| {
1597-
Tag::from_standardized_without_cell(TagStandard::Emoji { shortcode: s, url })
1598-
});
1599-
Self::new(Kind::EmojiSet, "", tags)
1612+
let tags: Vec<Tag> = vec![Tag::identifier(identifier)];
1613+
Self::new(
1614+
Kind::EmojiSet,
1615+
"",
1616+
tags.into_iter().chain(emojis.into_iter().map(|(s, url)| {
1617+
Tag::from_standardized_without_cell(TagStandard::Emoji { shortcode: s, url })
1618+
})),
1619+
)
16001620
}
16011621

16021622
/// Label

0 commit comments

Comments
 (0)