nip10: simplify and fix reply-to-root bugs
This removes EventRefs alltogether and uses the form we use in Damus Android. This simplifies our ThreadReply logic and fixes a reply-to-root bug Reported-by: NotBiebs <justinbieber@stemstr.app> Changelog-Fixed: Fix thread bug where a quote isn't picked up as a reply Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -340,8 +340,8 @@ extension NdbNote {
|
||||
References<RefId>(tags: self.tags)
|
||||
}
|
||||
|
||||
func thread_reply(_ keypair: Keypair) -> ThreadReply? {
|
||||
ThreadReply(event_refs: interpret_event_refs_ndb(blocks: self.blocks(keypair).blocks, tags: self.tags))
|
||||
func thread_reply() -> ThreadReply? {
|
||||
ThreadReply(tags: self.tags)
|
||||
}
|
||||
|
||||
func get_content(_ keypair: Keypair) -> String {
|
||||
@@ -387,13 +387,13 @@ extension NdbNote {
|
||||
return dec
|
||||
}
|
||||
|
||||
public func direct_replies(_ keypair: Keypair) -> NoteId? {
|
||||
return thread_reply(keypair)?.reply?.note_id
|
||||
public func direct_replies() -> NoteId? {
|
||||
return thread_reply()?.reply.note_id
|
||||
}
|
||||
|
||||
// NDBTODO: just use Id
|
||||
public func thread_id(keypair: Keypair) -> NoteId {
|
||||
guard let root = self.thread_reply(keypair)?.root else {
|
||||
public func thread_id() -> NoteId {
|
||||
guard let root = self.thread_reply()?.root else {
|
||||
return self.id
|
||||
}
|
||||
|
||||
@@ -421,8 +421,8 @@ extension NdbNote {
|
||||
}
|
||||
*/
|
||||
|
||||
func is_reply(_ keypair: Keypair) -> Bool {
|
||||
return thread_reply(keypair)?.reply != nil
|
||||
func is_reply() -> Bool {
|
||||
return thread_reply() != nil
|
||||
}
|
||||
|
||||
func note_language(_ keypair: Keypair) -> String? {
|
||||
|
||||
@@ -202,52 +202,6 @@ final class NdbTests: XCTestCase {
|
||||
return opts
|
||||
}
|
||||
|
||||
func test_perf_interp_evrefs_old() {
|
||||
guard let event = decode_nostr_event_json(test_reply_json) else {
|
||||
return
|
||||
}
|
||||
self.measure(options: longer_iter()) {
|
||||
let blocks = event.blocks(test_keypair).blocks
|
||||
let xs = interpret_event_refs(blocks: blocks, tags: event.tags)
|
||||
XCTAssertEqual(xs.count, 1)
|
||||
}
|
||||
}
|
||||
|
||||
func test_perf_interp_evrefs_ndb() {
|
||||
guard let note = NdbNote.owned_from_json(json: test_reply_json) else {
|
||||
return
|
||||
}
|
||||
self.measure(options: longer_iter()) {
|
||||
let blocks = note.blocks(test_keypair).blocks
|
||||
let xs = interpret_event_refs_ndb(blocks: blocks, tags: note.tags)
|
||||
XCTAssertEqual(xs.count, 1)
|
||||
}
|
||||
}
|
||||
|
||||
func test_decoded_events_are_equal() {
|
||||
let event = decode_nostr_event_json(test_reply_json)
|
||||
let note = NdbNote.owned_from_json(json: test_reply_json)
|
||||
|
||||
XCTAssertNotNil(note)
|
||||
XCTAssertNotNil(event)
|
||||
guard let note else { return }
|
||||
guard let event else { return }
|
||||
|
||||
XCTAssertEqual(note.content_len, UInt32(event.content.utf8.count))
|
||||
XCTAssertEqual(note.pubkey, event.pubkey)
|
||||
XCTAssertEqual(note.id, event.id)
|
||||
|
||||
let ev_blocks = event.blocks(test_keypair)
|
||||
let note_blocks = note.blocks(test_keypair)
|
||||
|
||||
XCTAssertEqual(ev_blocks, note_blocks)
|
||||
|
||||
let event_refs = interpret_event_refs(blocks: ev_blocks.blocks, tags: event.tags)
|
||||
let note_refs = interpret_event_refs_ndb(blocks: note_blocks.blocks, tags: note.tags)
|
||||
|
||||
XCTAssertEqual(event_refs, note_refs)
|
||||
}
|
||||
|
||||
func test_iteration_perf() throws {
|
||||
guard let note = NdbNote.owned_from_json(json: test_contact_list_json) else {
|
||||
XCTAssert(false)
|
||||
|
||||
Reference in New Issue
Block a user