@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
18
damus/Nostr/NostrKind.swift
Normal file
18
damus/Nostr/NostrKind.swift
Normal 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
|
||||
}
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user