mirror of
git://jb55.com/damus
synced 2024-09-30 00:40:45 +00:00
6376c61bad
This patch adds highlights (NIP-84) to Damus. Kind 9802 are handled by all the necessary models. We show highlighted events, longform events, and url references. Url references also leverage text fragments to take the user to the highlighted text. Testing —— iPhone 15 Pro Max (17.0) Dark Mode: https://v.nostr.build/oM6DW.mp4 iPhone 15 Pro Max (17.0) Light Mode: https://v.nostr.build/BRrmP.mp4 iPhone SE (3rd generation) (16.4) Light Mode: https://v.nostr.build/6GzKa.mp4 —— Closes: https://github.com/damus-io/damus/issues/2172 Closes: https://github.com/damus-io/damus/issues/1772 Closes: https://github.com/damus-io/damus/issues/1773 Closes: https://github.com/damus-io/damus/issues/2173 Closes: https://github.com/damus-io/damus/issues/2175 Changelog-Added: Highlights (NIP-84) PATCH CHANGELOG: V1 -> V2: addressed review comments highlights are now truncated and highlight label shown in Thread view V2 -> V3: handle case where highlight context is smaller than the highlight content Signed-off-by: ericholguin <ericholguin@apache.org>
36 lines
895 B
Swift
36 lines
895 B
Swift
//
|
||
// NdbNote+.swift
|
||
// damus
|
||
//
|
||
// Created by Daniel D’Aquino on 2023-11-17.
|
||
//
|
||
|
||
import Foundation
|
||
|
||
// Extension to make NdbNote compatible with NostrEvent's original API
|
||
extension NdbNote {
|
||
func parse_inner_event() -> NdbNote? {
|
||
return NdbNote.owned_from_json_cstr(json: content_raw, json_len: content_len)
|
||
}
|
||
|
||
func get_cached_inner_event(cache: EventCache) -> NdbNote? {
|
||
guard self.known_kind == .boost || self.known_kind == .highlight else {
|
||
return nil
|
||
}
|
||
|
||
if self.content_len == 0, let id = self.referenced_ids.first {
|
||
// TODO: raw id cache lookups
|
||
return cache.lookup(id)
|
||
}
|
||
|
||
return nil
|
||
}
|
||
|
||
func get_inner_event(cache: EventCache) -> NdbNote? {
|
||
if let ev = get_cached_inner_event(cache: cache) {
|
||
return ev
|
||
}
|
||
return self.parse_inner_event()
|
||
}
|
||
}
|