damus

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

commit 0258ef792fad6948883e4f00783a8614ced813c4
parent 1e6505abe37b36aac7deee1bdee523f7e489c036
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 21 Jan 2023 09:57:29 -0800

Show embedded note references

This reverts commit 3f3b78f9bc5aca3807c9420fe593a91b53c86bed.

Changelog-Fixed: Show embedded note references

Diffstat:
Mdamus/Views/EventView.swift | 76+++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 51 insertions(+), 25 deletions(-)

diff --git a/damus/Views/EventView.swift b/damus/Views/EventView.swift @@ -106,7 +106,7 @@ struct BuilderEventView: View { if let event = event { let ev = event.inner_event ?? event NavigationLink(destination: BuildThreadV2View(damus: damus, event_id: ev.id)) { - EventView(damus: damus, event: event, show_friend_icon: true, size: .small) + EventView(damus: damus, event: event, show_friend_icon: true, size: .small, embedded: true) }.buttonStyle(.plain) } else { ProgressView().padding() @@ -129,10 +129,11 @@ struct EventView: View { let pubkey: String let show_friend_icon: Bool let size: EventViewKind + let embedded: Bool @EnvironmentObject var action_bar: ActionBarModel - init(event: NostrEvent, highlight: Highlight, has_action_bar: Bool, damus: DamusState, show_friend_icon: Bool, size: EventViewKind = .normal) { + init(event: NostrEvent, highlight: Highlight, has_action_bar: Bool, damus: DamusState, show_friend_icon: Bool, size: EventViewKind = .normal, embedded: Bool = false) { self.event = event self.highlight = highlight self.has_action_bar = has_action_bar @@ -140,9 +141,10 @@ struct EventView: View { self.pubkey = event.pubkey self.show_friend_icon = show_friend_icon self.size = size + self.embedded = embedded } - init(damus: DamusState, event: NostrEvent, show_friend_icon: Bool, size: EventViewKind = .normal) { + init(damus: DamusState, event: NostrEvent, show_friend_icon: Bool, size: EventViewKind = .normal, embedded: Bool = false) { self.event = event self.highlight = .none self.has_action_bar = false @@ -150,6 +152,7 @@ struct EventView: View { self.pubkey = event.pubkey self.show_friend_icon = show_friend_icon self.size = size + self.embedded = embedded } init(damus: DamusState, event: NostrEvent, pubkey: String, show_friend_icon: Bool, size: EventViewKind = .normal, embedded: Bool = false) { @@ -160,6 +163,7 @@ struct EventView: View { self.pubkey = pubkey self.show_friend_icon = show_friend_icon self.size = size + self.embedded = embedded } var body: some View { @@ -196,8 +200,10 @@ struct EventView: View { let pmodel = ProfileModel(pubkey: pubkey, damus: damus) let pv = ProfileView(damus_state: damus, profile: pmodel, followers: FollowersModel(damus_state: damus, target: pubkey)) - NavigationLink(destination: pv) { - ProfilePicView(pubkey: pubkey, size: PFP_SIZE, highlight: highlight, profiles: damus.profiles) + if !embedded { + NavigationLink(destination: pv) { + ProfilePicView(pubkey: pubkey, size: PFP_SIZE, highlight: highlight, profiles: damus.profiles) + } } Spacer() @@ -236,33 +242,53 @@ struct EventView: View { NoteContentView(privkey: damus.keypair.privkey, event: event, profiles: damus.profiles, previews: damus.previews, show_images: should_show_img, artifacts: .just_content(content), size: self.size) .frame(maxWidth: .infinity, alignment: .leading) + .allowsHitTesting(!embedded) - if has_action_bar { - if size == .selected { - Text("\(format_date(event.created_at))") - .padding(.top, 10) - .font(.footnote) - .foregroundColor(.gray) + if !embedded { + let blocks = event.blocks(damus.keypair.privkey).filter { block in + guard case .mention(let mention) = block else { + return false + } + + guard case .event = mention.type else { + return false + } + + if mention.ref.key != "e" { + return false + } + - Divider() - .padding([.bottom], 4) - } else { - Rectangle().frame(height: 2).opacity(0) + return true } - let bar = make_actionbar_model(ev: event, damus: damus) - - if size == .selected && !bar.is_empty { - EventDetailBar(state: damus, target: event.id, bar: bar) - Divider() - .padding([.bottom], 4) + /// MARK: - Preview + if let firstBlock = blocks.first, case .mention(let mention) = firstBlock, mention.ref.key == "e" { + BuilderEventView(damus: damus, event_id: mention.ref.id) } - - EventActionBar(damus_state: damus, event: event, bar: bar) } - Divider() - .padding([.top], 4) + if !embedded { + if has_action_bar { + if size == .selected { + Text("\(format_date(event.created_at))") + .padding(.top, 10) + .font(.footnote) + .foregroundColor(.gray) + + Divider() + .padding([.bottom], 4) + } else { + Rectangle().frame(height: 2).opacity(0) + } + + let bar = make_actionbar_model(ev: event, damus: damus) + EventActionBar(damus_state: damus, event: event, bar: bar) + } + + Divider() + .padding([.top], 4) + } } .padding([.leading], 2) }