mirror of
git://jb55.com/damus
synced 2024-09-30 00:40:45 +00:00
nip10: fix mixed nip10 markers
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
parent
a721256e9b
commit
dcd7b5b111
@ -79,19 +79,21 @@ func interp_event_refs_without_mentions_ndb(_ ev_tags: References<NoteRef>) -> [
|
||||
var evrefs: [EventRef] = []
|
||||
var first: Bool = true
|
||||
var root_id: NoteRef? = nil
|
||||
var any_marker: Bool = false
|
||||
|
||||
for ref in ev_tags {
|
||||
if let marker = ref.marker {
|
||||
any_marker = true
|
||||
switch marker {
|
||||
case .root: root_id = ref
|
||||
case .reply: evrefs.append(.reply(ref))
|
||||
case .mention: evrefs.append(.mention(.noteref(ref)))
|
||||
}
|
||||
} else {
|
||||
if first {
|
||||
if !any_marker && first {
|
||||
root_id = ref
|
||||
first = false
|
||||
} else {
|
||||
} else if !any_marker {
|
||||
evrefs.append(.reply(ref))
|
||||
}
|
||||
}
|
||||
|
@ -129,6 +129,36 @@ final class NIP10Tests: XCTestCase {
|
||||
}), [root_note_id])
|
||||
}
|
||||
|
||||
func test_mixed_nip10() {
|
||||
let root_note_id_hex = "27e71cf53299dafb5dc7bcc0a078357418a4375cb1097bf5184662493f79a627"
|
||||
let reply_hex = "1a616998552cf76e9786f76ac68f6104cdae46377330735c68bfe0b9426d2fa8"
|
||||
|
||||
let tags = [
|
||||
[ "e", root_note_id_hex, "", "root" ],
|
||||
[ "e", "f99046bd87be7508d55e139de48517c06ef90830d77a5d3213df858d77bb2f8f" ],
|
||||
[ "e", reply_hex, "", "reply" ],
|
||||
[ "p", "3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681" ],
|
||||
[ "p", "8ea485266b2285463b13bf835907161c22bb3da1e652b443db14f9cee6720a43" ],
|
||||
[ "p", "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245" ]
|
||||
]
|
||||
|
||||
|
||||
let root_note_id = NoteId(hex: root_note_id_hex)!
|
||||
let reply_id = NoteId(hex: reply_hex)!
|
||||
|
||||
let note = NdbNote(content: "hi", keypair: test_keypair, kind: 1, tags: tags)!
|
||||
let refs = interp_event_refs_without_mentions_ndb(note.referenced_noterefs)
|
||||
|
||||
XCTAssertEqual(refs.reduce(into: Array<NoteId>(), { xs, r in
|
||||
if let note_id = r.is_thread_id?.note_id { xs.append(note_id) }
|
||||
}), [root_note_id])
|
||||
|
||||
XCTAssertEqual(refs.reduce(into: Array<NoteId>(), { xs, r in
|
||||
if let note_id = r.is_reply?.note_id { xs.append(note_id) }
|
||||
}), [reply_id])
|
||||
|
||||
}
|
||||
|
||||
func test_deprecated_nip10() {
|
||||
let root_note_id_hex = "7c7d37bc8c04d2ec65cbc7d9275253e6b5cc34b5d10439f158194a3feefa8d52"
|
||||
let direct_reply_hex = "7c7d37bc8c04d2ec65cbc7d9275253e6b5cc34b5d10439f158194a3feefa8d51"
|
||||
|
Loading…
Reference in New Issue
Block a user