old style navigation

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2022-04-30 11:46:56 -07:00
parent a88324333b
commit d574e572d4
13 changed files with 141 additions and 140 deletions

View File

@@ -9,41 +9,24 @@ import Foundation
class ProfileModel: ObservableObject {
@Published var events: [NostrEvent] = []
@Published var pubkey: String?
var seen_event: Set<String> = Set()
let pubkey: String
let pool: RelayPool
var seen_event: Set<String> = Set()
var sub_id = UUID().description
var pool: RelayPool? = nil
deinit {
unsubscribe()
init(pubkey: String, pool: RelayPool) {
self.pubkey = pubkey
self.pool = pool
}
func unsubscribe() {
print("unsubscribing from profile \(pubkey ?? "?") with sub_id \(sub_id)")
pool?.unsubscribe(sub_id: sub_id)
}
func set_pubkey(_ pk: String) {
if pk == self.pubkey {
return
}
self.events.removeAll()
self.seen_event.removeAll()
unsubscribe()
self.sub_id = UUID().description
self.pubkey = pk
subscribe()
print("unsubscribing from profile \(pubkey) with sub_id \(sub_id)")
pool.unsubscribe(sub_id: sub_id)
}
func subscribe() {
guard let pubkey = self.pubkey else {
return
}
let kinds: [Int] = [
NostrKind.text.rawValue,
NostrKind.delete.rawValue,
@@ -54,7 +37,7 @@ class ProfileModel: ObservableObject {
filter.authors = [pubkey]
print("subscribing to profile \(pubkey) with sub_id \(sub_id)")
pool?.subscribe(sub_id: sub_id, filters: [filter], handler: handle_event)
pool.subscribe(sub_id: sub_id, filters: [filter], handler: handle_event)
}
func add_event(_ ev: NostrEvent) {