Load profiles everywhere

Fixes: #11
Changelog-Fixed: Missing profiles are now loaded everywhere
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2022-08-04 20:42:18 -07:00
parent 17f87d5438
commit 5c62a06618
6 changed files with 98 additions and 17 deletions

View File

@@ -10,7 +10,7 @@ import Foundation
enum NostrResponse: Decodable {
case event(String, NostrEvent)
case notice(String)
case eose
case eose(String)
init(from decoder: Decoder) throws {
var container = try decoder.unkeyedContainer()
@@ -34,7 +34,8 @@ enum NostrResponse: Decodable {
self = .notice(msg)
return
} else if typ == "EOSE" {
self = .eose
let sub_id = try container.decode(String.self)
self = .eose(sub_id)
return
}

View File

@@ -107,7 +107,7 @@ class RelayPool {
}
}
func unsubscribe(sub_id: String) {
func unsubscribe(sub_id: String, to: [String]? = nil) {
self.remove_handler(sub_id: sub_id)
self.send(.unsubscribe(sub_id))
}
@@ -117,6 +117,11 @@ class RelayPool {
send(.subscribe(.init(filters: filters, sub_id: sub_id)))
}
func subscribe_to(sub_id: String, filters: [NostrFilter], to: [String]?, handler: @escaping (String, NostrConnectionEvent) -> ()) {
register_handler(sub_id: sub_id, handler: handler)
send(.subscribe(.init(filters: filters, sub_id: sub_id)), to: to)
}
func send(_ req: NostrRequest, to: [String]? = nil) {
let relays = to.map{ get_relays($0) } ?? self.relays