damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 10b1cf64aec6da9b86ef037c5927c2984b3a9dc2
parent 8ab1c6a89956586e7a90184b1bc6fd98ed3b129a
Author: Daniel D’Aquino <daniel@daquino.me>
Date:   Fri, 19 Jul 2024 10:50:30 -0700

Merge pull request #2330 from ericholguin/highlight-fixes

highlight: fixes and improvements
Diffstat:
Mdamus/Models/ContentFilters.swift | 2+-
Mdamus/Models/ThreadModel.swift | 4+++-
Mdamus/Views/Events/Components/ReplyPart.swift | 16+++++-----------
Mdamus/Views/Events/EventBody.swift | 6++++++
Mdamus/Views/Events/Highlight/HighlightPostView.swift | 5++---
Mdamus/Views/Events/SelectedEventView.swift | 19++++---------------
Mnostrdb/NdbNote.swift | 9++++++++-
7 files changed, 29 insertions(+), 32 deletions(-)

diff --git 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 @@ -11,13 +11,15 @@ import Foundation class ThreadModel: ObservableObject { @Published var event: NostrEvent let original_event: NostrEvent + let highlight: String? var event_map: Set<NostrEvent> - 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 {