Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2022-04-30 10:37:29 -07:00
parent ce989450f4
commit a88324333b
12 changed files with 289 additions and 68 deletions

View File

@@ -18,11 +18,6 @@ struct Profile: Decodable {
}
}
enum NostrKind: Int {
case metadata = 0
case text = 1
}
enum NostrTag {
case other_event(OtherEvent)
case key_event(KeyEvent)

View File

@@ -53,6 +53,10 @@ class NostrEvent: Codable, Identifiable, CustomStringConvertible {
let p = pow.map { String($0) } ?? "?"
return "NostrEvent { id: \(id) pubkey \(pubkey) kind \(kind) tags \(tags) pow \(p) content '\(content)' }"
}
var known_kind: NostrKind? {
return NostrKind.init(rawValue: kind)
}
private enum CodingKeys: String, CodingKey {
case id, sig, tags, pubkey, created_at, kind, content

View File

@@ -0,0 +1,18 @@
//
// NostrKind.swift
// damus
//
// Created by William Casarin on 2022-04-27.
//
import Foundation
enum NostrKind: Int {
case metadata = 0
case text = 1
case contacts = 3
case delete = 5
case boost = 6
case like = 7
}

View File

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