ndb: sync up a few remaining NdbNote tag differences
This commit is contained in:
@@ -21,6 +21,8 @@ enum ValidationResult: Decodable {
|
||||
}
|
||||
|
||||
//typealias NostrEvent = NdbNote
|
||||
//typealias Tags = TagsSequence
|
||||
typealias Tags = [[String]]
|
||||
typealias NostrEvent = NostrEventOld
|
||||
|
||||
let MAX_NOTE_SIZE: Int = 2 << 18
|
||||
@@ -54,7 +56,7 @@ class NostrEventOld: Codable, Identifiable, CustomStringConvertible, Equatable,
|
||||
let id: String
|
||||
let content: String
|
||||
let sig: String
|
||||
let tags: [[String]]
|
||||
let tags: Tags
|
||||
|
||||
//var boosted_by: String?
|
||||
|
||||
@@ -88,6 +90,18 @@ class NostrEventOld: Codable, Identifiable, CustomStringConvertible, Equatable,
|
||||
hasher.combine(id)
|
||||
}
|
||||
|
||||
static func owned_from_json(json: String) -> NostrEvent? {
|
||||
let decoder = JSONDecoder()
|
||||
guard let dat = json.data(using: .utf8) else {
|
||||
return nil
|
||||
}
|
||||
guard let ev = try? decoder.decode(NostrEvent.self, from: dat) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return ev
|
||||
}
|
||||
|
||||
init?(content: String, keypair: Keypair, kind: UInt32 = 1, tags: [[String]] = [], createdAt: UInt32 = UInt32(Date().timeIntervalSince1970)) {
|
||||
|
||||
self.content = content
|
||||
@@ -937,16 +951,6 @@ func validate_event(ev: NostrEvent) -> ValidationResult {
|
||||
return ok ? .ok : .bad_sig
|
||||
}
|
||||
|
||||
func last_etag(tags: [[String]]) -> String? {
|
||||
var e: String? = nil
|
||||
for tag in tags {
|
||||
if tag.count >= 2 && tag[0] == "e" {
|
||||
e = tag[1]
|
||||
}
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
func first_eref_mention(ev: NostrEvent, privkey: String?) -> Mention? {
|
||||
let blocks = ev.blocks(privkey).blocks.filter { block in
|
||||
guard case .mention(let mention) = block else {
|
||||
|
||||
@@ -29,9 +29,11 @@ struct References: Sequence, IteratorProtocol {
|
||||
|
||||
mutating func next() -> Reference? {
|
||||
while let tag = tags_iter.next() {
|
||||
guard let key = tag[0], key.count == 1,
|
||||
let id = tag[1], tagref_should_be_id(key)
|
||||
else { continue }
|
||||
guard tag.count >= 2 else { continue }
|
||||
let key = tag[0]
|
||||
let id = tag[1]
|
||||
|
||||
guard key.count == 1, tagref_should_be_id(id) else { continue }
|
||||
|
||||
for c in key {
|
||||
guard let a = AsciiCharacter(c) else { break }
|
||||
@@ -64,12 +66,21 @@ struct References: Sequence, IteratorProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
// TagsSequence transition helpers
|
||||
extension [[String]] {
|
||||
func strings() -> [[String]] {
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
||||
// TagsSequence transition helpers
|
||||
extension [String] {
|
||||
func strings() -> [String] {
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
||||
// NdbTagElem transition helpers
|
||||
extension String {
|
||||
func string() -> String {
|
||||
return self
|
||||
@@ -82,6 +93,10 @@ extension String {
|
||||
func matches_char(_ c: AsciiCharacter) -> Bool {
|
||||
return self.first == c.character
|
||||
}
|
||||
|
||||
func matches_str(_ str: String) -> Bool {
|
||||
return self == str
|
||||
}
|
||||
}
|
||||
|
||||
struct ReferencedId: Identifiable, Hashable, Equatable {
|
||||
|
||||
Reference in New Issue
Block a user