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>
55 lines
1.2 KiB
Swift
55 lines
1.2 KiB
Swift
//
|
|
// ReplyCounter.swift
|
|
// damus
|
|
//
|
|
// Created by William Casarin on 2023-04-04.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
class ReplyCounter {
|
|
private var replies: [NoteId: Int]
|
|
private var counted: Set<NoteId>
|
|
private var our_replies: [NoteId: NostrEvent]
|
|
private let our_pubkey: Pubkey
|
|
|
|
init(our_pubkey: Pubkey) {
|
|
self.our_pubkey = our_pubkey
|
|
replies = [:]
|
|
counted = Set()
|
|
our_replies = [:]
|
|
}
|
|
|
|
func our_reply(_ evid: NoteId) -> NostrEvent? {
|
|
return our_replies[evid]
|
|
}
|
|
|
|
func get_replies(_ evid: NoteId) -> Int {
|
|
return replies[evid] ?? 0
|
|
}
|
|
|
|
func count_replies(_ event: NostrEvent, keypair: Keypair) {
|
|
guard event.is_textlike else {
|
|
return
|
|
}
|
|
|
|
if counted.contains(event.id) {
|
|
return
|
|
}
|
|
|
|
counted.insert(event.id)
|
|
|
|
if let reply = event.direct_replies() {
|
|
if event.pubkey == our_pubkey {
|
|
self.our_replies[reply] = event
|
|
}
|
|
|
|
if replies[reply] != nil {
|
|
replies[reply] = replies[reply]! + 1
|
|
} else {
|
|
replies[reply] = 1
|
|
}
|
|
}
|
|
}
|
|
}
|