diff --git a/damus/Models/Reply.swift b/damus/Models/Reply.swift index b3bee54a..c627ea4a 100644 --- 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 index 7687906a..5bc9c89a 100644 --- 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 index 506b3754..3b6dc7b6 100644 --- 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 index fcb7a86a..b9cc53bf 100644 --- a/damus/Views/Events/EventShell.swift +++ b/damus/Views/Events/EventShell.swift @@ -69,7 +69,7 @@ struct EventShell: 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: 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 index 8250b21f..4b29e05e 100644 --- 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) }