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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user