damus

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

commit 25e022d93314425dcd8c141823598cb4f95429f8
parent e6429139449b1b03a4dab744569c873a5aee3227
Author: William Casarin <jb55@jb55.com>
Date:   Sun,  6 Aug 2023 15:37:32 -0700

reply: ensure the person you're replying to is the first entry in the reply description

Suggested-by: Tanel
Changelog-Fixed: Ensure the person you're replying to is the first entry in the reply description

Diffstat:
Mdamus/Models/Reply.swift | 16++++++++++++----
Mdamus/Views/Events/Components/ReplyDescription.swift | 9+++++----
Mdamus/Views/Events/Components/ReplyPart.swift | 15++++++++++++---
Mdamus/Views/Events/EventShell.swift | 4++--
Mdamus/Views/Events/SelectedEventView.swift | 10+++++++++-
5 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/damus/Models/Reply.swift b/damus/Models/Reply.swift @@ -12,16 +12,24 @@ struct ReplyDesc { let others: Int } -func make_reply_description(_ tags: Tags) -> ReplyDesc { +func make_reply_description(_ event: NostrEvent, replying_to: NostrEvent?) -> ReplyDesc { var c = 0 var ns: [Pubkey] = [] - var i = tags.count + var i = event.tags.count - for tag in tags { + if let replying_to { + ns.append(replying_to.pubkey) + } + + for tag in event.tags { if let pk = Pubkey.from_tag(tag: tag) { c += 1 if ns.count < 2 { - ns.append(pk) + if let replying_to, pk == replying_to.pubkey { + continue + } else { + ns.append(pk) + } } } i -= 1 diff --git a/damus/Views/Events/Components/ReplyDescription.swift b/damus/Views/Events/Components/ReplyDescription.swift @@ -10,10 +10,11 @@ import SwiftUI // jb55 - TODO: this could be a lot better struct ReplyDescription: View { let event: NostrEvent + let replying_to: NostrEvent? let profiles: Profiles var body: some View { - Text(verbatim: "\(reply_desc(profiles: profiles, event: event))") + Text(verbatim: "\(reply_desc(profiles: profiles, event: event, replying_to: replying_to))") .font(.footnote) .foregroundColor(.gray) .frame(maxWidth: .infinity, alignment: .leading) @@ -22,12 +23,12 @@ struct ReplyDescription: View { struct ReplyDescription_Previews: PreviewProvider { static var previews: some View { - ReplyDescription(event: test_note, profiles: test_damus_state().profiles) + ReplyDescription(event: test_note, replying_to: test_note, profiles: test_damus_state().profiles) } } -func reply_desc(profiles: Profiles, event: NostrEvent, locale: Locale = Locale.current) -> String { - let desc = make_reply_description(event.tags) +func reply_desc(profiles: Profiles, event: NostrEvent, replying_to: NostrEvent?, locale: Locale = Locale.current) -> String { + let desc = make_reply_description(event, replying_to: replying_to) let pubkeys = desc.pubkeys let n = desc.others diff --git a/damus/Views/Events/Components/ReplyPart.swift b/damus/Views/Events/Components/ReplyPart.swift @@ -8,14 +8,23 @@ import SwiftUI struct ReplyPart: View { + let events: EventCache let event: NostrEvent let privkey: Privkey? let profiles: Profiles - + + var replying_to: NostrEvent? { + guard let note_ref = event.event_refs(privkey).first(where: { evref in evref.is_direct_reply != nil })?.is_direct_reply else { + return nil + } + + return events.lookup(note_ref.note_id) + } + var body: some View { Group { if event_is_reply(event.event_refs(privkey)) { - ReplyDescription(event: event, profiles: profiles) + ReplyDescription(event: event, replying_to: replying_to, profiles: profiles) } else { EmptyView() } @@ -25,6 +34,6 @@ struct ReplyPart: View { struct ReplyPart_Previews: PreviewProvider { static var previews: some View { - ReplyPart(event: test_note, privkey: nil, profiles: test_damus_state().profiles) + ReplyPart(events: test_damus_state().events, event: test_note, privkey: nil, profiles: test_damus_state().profiles) } } diff --git a/damus/Views/Events/EventShell.swift b/damus/Views/Events/EventShell.swift @@ -69,7 +69,7 @@ struct EventShell<Content: View>: View { EventTop(state: state, event: event, pubkey: pubkey, is_anon: is_anon) if !options.contains(.no_replying_to) { - ReplyPart(event: event, privkey: state.keypair.privkey, profiles: state.profiles) + ReplyPart(events: state.events, event: event, privkey: state.keypair.privkey, profiles: state.profiles) } content @@ -95,7 +95,7 @@ struct EventShell<Content: View>: View { VStack { EventTop(state: state, event: event, pubkey: pubkey, is_anon: is_anon) - ReplyPart(event: event, privkey: state.keypair.privkey, profiles: state.profiles) + ReplyPart(events: state.events, event: event, privkey: state.keypair.privkey, profiles: state.profiles) } } .padding(.horizontal) diff --git a/damus/Views/Events/SelectedEventView.swift b/damus/Views/Events/SelectedEventView.swift @@ -17,6 +17,14 @@ struct SelectedEventView: View { } @StateObject var bar: ActionBarModel + + var replying_to: NostrEvent? { + guard let note_ref = event.event_refs(damus.keypair.privkey).first(where: { evref in evref.is_direct_reply != nil })?.is_direct_reply else { + return nil + } + + return damus.events.lookup(note_ref.note_id) + } init(damus: DamusState, event: NostrEvent, size: EventViewKind) { self.damus = damus @@ -43,7 +51,7 @@ struct SelectedEventView: View { .lineLimit(1) if event_is_reply(event.event_refs(damus.keypair.privkey)) { - ReplyDescription(event: event, profiles: damus.profiles) + ReplyDescription(event: event, replying_to: replying_to, profiles: damus.profiles) .padding(.horizontal) }