diff --git a/damus/Models/ContentFilters.swift b/damus/Models/ContentFilters.swift index ca9baa05..425d2b35 100644 --- a/damus/Models/ContentFilters.swift +++ b/damus/Models/ContentFilters.swift @@ -16,7 +16,7 @@ enum FilterState : Int { func filter(ev: NostrEvent) -> Bool { switch self { case .posts: - return ev.known_kind == .boost || !ev.is_reply() + return ev.known_kind == .boost || ev.known_kind == .highlight || !ev.is_reply() case .posts_and_replies: return true } diff --git a/damus/Models/ThreadModel.swift b/damus/Models/ThreadModel.swift index 2f3b2844..f4f65f8b 100644 --- a/damus/Models/ThreadModel.swift +++ b/damus/Models/ThreadModel.swift @@ -11,13 +11,15 @@ import Foundation class ThreadModel: ObservableObject { @Published var event: NostrEvent let original_event: NostrEvent + let highlight: String? var event_map: Set - init(event: NostrEvent, damus_state: DamusState) { + init(event: NostrEvent, damus_state: DamusState, highlight: String? = nil) { self.damus_state = damus_state self.event_map = Set() self.event = event self.original_event = event + self.highlight = highlight add_event(event, keypair: damus_state.keypair) } diff --git a/damus/Views/Events/Components/ReplyPart.swift b/damus/Views/Events/Components/ReplyPart.swift index 7fa8bffd..85858299 100644 --- a/damus/Views/Events/Components/ReplyPart.swift +++ b/damus/Views/Events/Components/ReplyPart.swift @@ -15,18 +15,12 @@ struct ReplyPart: View { var body: some View { Group { - if let reply_ref = event.thread_reply()?.reply { + if event.known_kind == .highlight { + let highlighted_note = event.highlighted_note_id().flatMap { events.lookup($0) } + HighlightDescription(event: event, highlighted_event: highlighted_note, ndb: ndb) + } else if let reply_ref = event.thread_reply()?.reply { let replying_to = events.lookup(reply_ref.note_id) - if event.known_kind != .highlight { - ReplyDescription(event: event, replying_to: replying_to, ndb: ndb) - } else if event.known_kind == .highlight { - HighlightDescription(event: event, highlighted_event: replying_to, ndb: ndb) - } - else { - EmptyView() - } - } else { - EmptyView() + ReplyDescription(event: event, replying_to: replying_to, ndb: ndb) } } } diff --git a/damus/Views/Events/EventBody.swift b/damus/Views/Events/EventBody.swift index 31c978b5..ea63cdd2 100644 --- a/damus/Views/Events/EventBody.swift +++ b/damus/Views/Events/EventBody.swift @@ -37,6 +37,12 @@ struct EventBody: View { } } else if event.known_kind == .highlight { HighlightBodyView(state: damus_state, ev: event, options: options) + .onTapGesture { + if let highlighted_note = event.highlighted_note_id().flatMap({ damus_state.events.lookup($0) }) { + let thread = ThreadModel(event: highlighted_note, damus_state: damus_state, highlight: event.content) + damus_state.nav.push(route: Route.Thread(thread: thread)) + } + } } else { note_content } diff --git a/damus/Views/Events/Highlight/HighlightPostView.swift b/damus/Views/Events/Highlight/HighlightPostView.swift index d0a23f50..d66e339a 100644 --- a/damus/Views/Events/Highlight/HighlightPostView.swift +++ b/damus/Views/Events/Highlight/HighlightPostView.swift @@ -29,8 +29,7 @@ struct HighlightPostView: View { Spacer() Button(NSLocalizedString("Post", comment: "Button to post a highlight.")) { - var tags: [[String]] = [ ["e", "\(self.event.id)"] ] - tags.append(["context", self.event.content]) + let tags: [[String]] = [ ["e", "\(self.event.id)"] ] let kind = NostrKind.highlight.rawValue guard let ev = NostrEvent(content: selectedText, keypair: damus_state.keypair, kind: kind, tags: tags) else { @@ -53,7 +52,7 @@ struct HighlightPostView: View { HStack { var attributedString: AttributedString { - var attributedString = AttributedString(self.event.content) + var attributedString = AttributedString(selectedText) if let range = attributedString.range(of: selectedText) { attributedString[range].backgroundColor = DamusColors.highlight diff --git a/damus/Views/Events/SelectedEventView.swift b/damus/Views/Events/SelectedEventView.swift index ceb34828..f1baaa46 100644 --- a/damus/Views/Events/SelectedEventView.swift +++ b/damus/Views/Events/SelectedEventView.swift @@ -39,21 +39,10 @@ struct SelectedEventView: View { .padding(.horizontal) .minimumScaleFactor(0.75) .lineLimit(1) - - if let reply_ref = event.thread_reply()?.reply { - let replying_to = damus.events.lookup(reply_ref.note_id) - if event.known_kind == .highlight { - HighlightDescription(event: event, highlighted_event: replying_to, ndb: damus.ndb) - .padding(.horizontal) - } else { - ReplyDescription(event: event, replying_to: replying_to, ndb: damus.ndb) - .padding(.horizontal) - } - } else if event.known_kind == .highlight { - HighlightDescription(event: event, highlighted_event: nil, ndb: damus.ndb) - .padding(.horizontal) - } - + + ReplyPart(events: damus.events, event: event, keypair: damus.keypair, ndb: damus.ndb) + .padding(.horizontal) + ProxyView(event: event) .padding(.top, 5) .padding(.horizontal) diff --git a/nostrdb/NdbNote.swift b/nostrdb/NdbNote.swift index ab2c15f1..9c0f7f8a 100644 --- a/nostrdb/NdbNote.swift +++ b/nostrdb/NdbNote.swift @@ -341,7 +341,14 @@ extension NdbNote { } func thread_reply() -> ThreadReply? { - ThreadReply(tags: self.tags) + if self.known_kind != .highlight { + return ThreadReply(tags: self.tags) + } + return nil + } + + func highlighted_note_id() -> NoteId? { + return ThreadReply(tags: self.tags)?.reply.note_id } func get_content(_ keypair: Keypair) -> String {