From 9d91856ea3d301f588a9312de1d2b4362b1f2336 Mon Sep 17 00:00:00 2001 From: kernelkind Date: Tue, 30 Jan 2024 11:44:15 -0500 Subject: [PATCH] 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 Reviewed-by: William Casarin Signed-off-by: William Casarin --- damus/Models/Mentions.swift | 5 ++++- damusTests/damusTests.swift | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/damus/Models/Mentions.swift b/damus/Models/Mentions.swift index e1089fd9..6fada7d8 100644 --- a/damus/Models/Mentions.swift +++ b/damus/Models/Mentions.swift @@ -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) diff --git a/damusTests/damusTests.swift b/damusTests/damusTests.swift index a03522c0..362f1927 100644 --- a/damusTests/damusTests.swift +++ b/damusTests/damusTests.swift @@ -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() {