9a1ae6f9b5
Extract and use relay hints from bech32 entities (nevent, nprofile, naddr) and event tag references (e, q tags) to fetch events from hinted relays not in the user's relay pool. Changes: - Parse relay hints from bech32 TLV data in URLHandler - Pass relay hints through SearchType and NoteReference enums - Add ensureConnected() to RelayPool for ephemeral relay connections - Implement ephemeral relay lease management with race condition protection - Add repostTarget() helper to extract relay hints from repost e tags - Add QuoteRef struct to preserve relay hints from q tags (NIP-10/NIP-18) - Support relay hints in replies with author pubkey in e-tags (NIP-10) - Implement fallback broadcast when hinted relays don't respond - Add comprehensive test coverage for relay hint functionality - Add DEBUG logging for relay hint tracing during development Implementation details: - Connect to hinted relays as ephemeral, returning early when first connects - Use total deadline to prevent timeout accumulation across hint attempts - Decrement lease count before suspension points to ensure atomicity - Fall back to broadcast if hints don't resolve or respond Closes: https://github.com/damus-io/damus/issues/1147 Changelog-Added: Added relay hint support for nevent, nprofile, naddr links and event tag references (reposts, quotes, replies) Signed-off-by: alltheseas Signed-off-by: Daniel D'Aquino <daniel@daquino.me> Co-authored-by: alltheseas <alltheseas@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Daniel D'Aquino <daniel@daquino.me
109 lines
3.6 KiB
Swift
109 lines
3.6 KiB
Swift
//
|
|
// SelectedEventView.swift
|
|
// damus
|
|
//
|
|
// Created by William Casarin on 2023-01-23.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct SelectedEventView: View {
|
|
let damus: DamusState
|
|
let event: NostrEvent
|
|
let size: EventViewKind
|
|
|
|
@Environment(\.colorScheme) var colorScheme
|
|
|
|
var pubkey: Pubkey {
|
|
event.pubkey
|
|
}
|
|
|
|
@StateObject var bar: ActionBarModel
|
|
|
|
/// Whether to apply sepia styling to the entire view (for longform articles)
|
|
var useSepia: Bool {
|
|
event.known_kind == .longform && damus.settings.longform_sepia_mode
|
|
}
|
|
|
|
init(damus: DamusState, event: NostrEvent, size: EventViewKind) {
|
|
self.damus = damus
|
|
self.event = event
|
|
self.size = size
|
|
self._bar = StateObject(wrappedValue: make_actionbar_model(ev: event.id, damus: damus))
|
|
}
|
|
|
|
var body: some View {
|
|
HStack(alignment: .top) {
|
|
VStack(alignment: .leading) {
|
|
HStack {
|
|
EventProfile(damus_state: damus, pubkey: pubkey, size: .normal)
|
|
|
|
Spacer()
|
|
|
|
EventMenuContext(damus: damus, event: event)
|
|
.padding([.bottom], 4)
|
|
}
|
|
.padding(.horizontal)
|
|
.minimumScaleFactor(0.75)
|
|
.lineLimit(1)
|
|
|
|
ReplyPart(events: damus.events, event: event, keypair: damus.keypair, ndb: damus.ndb)
|
|
.padding(.horizontal)
|
|
|
|
ProxyView(event: event)
|
|
.padding(.top, 5)
|
|
.padding(.horizontal)
|
|
|
|
EventBody(damus_state: damus, event: event, size: size, options: [.wide])
|
|
|
|
Mention
|
|
|
|
Text(verbatim: "\(format_date(created_at: event.created_at))")
|
|
.padding([.top, .leading, .trailing])
|
|
.font(.footnote)
|
|
.foregroundColor(.gray)
|
|
|
|
Divider()
|
|
.padding([.bottom], 4)
|
|
|
|
if !bar.is_empty {
|
|
EventDetailBar(state: damus, target: event.id, target_pk: event.pubkey)
|
|
.padding(.horizontal)
|
|
Divider()
|
|
}
|
|
|
|
EventActionBar(damus_state: damus, event: event)
|
|
.padding([.top], 4)
|
|
.padding(.horizontal)
|
|
|
|
Divider()
|
|
.padding([.top], 4)
|
|
}
|
|
.onReceive(handle_notify(.update_stats)) { target in
|
|
guard target == self.event.id else { return }
|
|
Task { await self.bar.update(damus: self.damus, evid: target) }
|
|
}
|
|
.compositingGroup()
|
|
}
|
|
// Apply sepia background to outer HStack for full width coverage
|
|
// Note: foregroundStyle intentionally NOT applied here to preserve UI element contrast
|
|
// (buttons, icons, timestamps). Article text gets sepia styling via EventBody.
|
|
.background(useSepia ? DamusColors.sepiaBackground(for: colorScheme) : Color.clear)
|
|
}
|
|
|
|
var Mention: some View {
|
|
Group {
|
|
if let mention = first_eref_mention_with_hints(ndb: damus.ndb, ev: event, keypair: damus.keypair) {
|
|
MentionView(damus_state: damus, mention: .note(mention.noteId, index: mention.index), relayHints: mention.relayHints)
|
|
.padding(.horizontal)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct SelectedEventView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
SelectedEventView(damus: test_damus_state, event: test_note, size: .selected)
|
|
}
|
|
}
|