nip19: do not include tag for nevent mention

When creating an NostrEvent with an nevent1 mention, don't include the
nevent mentions in the event's tags. This matches the behavior for
note1 mentions.

Tests for content with npub1 and note1 mentions were added to confirm
tag generation behavior. Test for nevent mention tag generation was
modified to be the same as note1.

Closes: https://github.com/damus-io/damus/issues/1941
Lightning-address: kernelkind@getalby.com
Signed-off-by: kernelkind <kernelkind@gmail.com>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
kernelkind
2024-01-30 11:44:15 -05:00
committed by William Casarin
parent 7cc2825d89
commit 9d91856ea3
2 changed files with 19 additions and 4 deletions

View File

@@ -269,8 +269,11 @@ func make_post_tags(post_blocks: [Block], tags: [[String]]) -> PostTags {
for post_block in post_blocks {
switch post_block {
case .mention(let mention):
if case .note = mention.ref {
switch(mention.ref) {
case .note, .nevent:
continue
default:
break
}
new_tags.append(mention.ref.tag)

View File

@@ -229,12 +229,24 @@ class damusTests: XCTestCase {
XCTAssertEqual(txt, "there is no mention here")
}
func testTagGeneration_Nevent_ContainsETag() {
func testTagGeneration_Note_ContainsNoTags() {
let ev = createEventFromContentString("note1h865g8j9egu30yequqp3e7ccudq8seeaes7nuw3m82vpwc9226tqtudlvp")
XCTAssertEqual(ev.tags.count, 0)
}
func testTagGeneration_Nevent_ContainsNoTags() {
let ev = createEventFromContentString("nevent1qqstna2yrezu5wghjvswqqculvvwxsrcvu7uc0f78gan4xqhvz49d9spr3mhxue69uhkummnw3ez6un9d3shjtn4de6x2argwghx6egpr4mhxue69uhkummnw3ez6ur4vgh8wetvd3hhyer9wghxuet5nxnepm")
XCTAssertEqual(ev.tags.count, 0)
}
func testTagGeneration_Npub_ContainsPTag() {
let ev = createEventFromContentString("npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6")
XCTAssertEqual(ev.tags.count, 1)
XCTAssertEqual(ev.tags[0][0].string(), "e")
XCTAssertEqual(ev.tags[0][1].string(), "b9f5441e45ca39179320e0031cfb18e34078673dcc3d3e3a3b3a981760aa5696")
XCTAssertEqual(ev.tags[0][0].string(), "p")
XCTAssertEqual(ev.tags[0][1].string(), "3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d")
}
func testTagGeneration_Nprofile_ContainsPTag() {