mirror of
git://jb55.com/damus
synced 2024-09-30 00:40:45 +00:00
Merge pull request #2330 from ericholguin/highlight-fixes
highlight: fixes and improvements
This commit is contained in:
commit
10b1cf64ae
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -40,19 +40,8 @@ struct SelectedEventView: View {
|
||||
.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)
|
||||
ReplyPart(events: damus.events, event: event, keypair: damus.keypair, 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)
|
||||
}
|
||||
|
||||
ProxyView(event: event)
|
||||
.padding(.top, 5)
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user