NdbNote+.swift (895B)
1 // 2 // NdbNote+.swift 3 // damus 4 // 5 // Created by Daniel D’Aquino on 2023-11-17. 6 // 7 8 import Foundation 9 10 // Extension to make NdbNote compatible with NostrEvent's original API 11 extension NdbNote { 12 func parse_inner_event() -> NdbNote? { 13 return NdbNote.owned_from_json_cstr(json: content_raw, json_len: content_len) 14 } 15 16 func get_cached_inner_event(cache: EventCache) -> NdbNote? { 17 guard self.known_kind == .boost || self.known_kind == .highlight else { 18 return nil 19 } 20 21 if self.content_len == 0, let id = self.referenced_ids.first { 22 // TODO: raw id cache lookups 23 return cache.lookup(id) 24 } 25 26 return nil 27 } 28 29 func get_inner_event(cache: EventCache) -> NdbNote? { 30 if let ev = get_cached_inner_event(cache: cache) { 31 return ev 32 } 33 return self.parse_inner_event() 34 } 35 }