|
|
@ -11,7 +11,6 @@ import SwiftUI |
|
|
|
enum EventViewKind { |
|
|
|
case small |
|
|
|
case normal |
|
|
|
case big |
|
|
|
case selected |
|
|
|
} |
|
|
|
|
|
|
@ -21,56 +20,40 @@ func eventviewsize_to_font(_ size: EventViewKind) -> Font { |
|
|
|
return .body |
|
|
|
case .normal: |
|
|
|
return .body |
|
|
|
case .big: |
|
|
|
return .headline |
|
|
|
case .selected: |
|
|
|
return .custom("selected", size: 21.0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct EventView: View { |
|
|
|
let event: NostrEvent |
|
|
|
let highlight: Highlight |
|
|
|
let has_action_bar: Bool |
|
|
|
let damus: DamusState |
|
|
|
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, embedded: Bool = false) { |
|
|
|
init(event: NostrEvent, has_action_bar: Bool, damus: DamusState) { |
|
|
|
self.event = event |
|
|
|
self.highlight = highlight |
|
|
|
self.has_action_bar = has_action_bar |
|
|
|
self.damus = damus |
|
|
|
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, embedded: Bool = false) { |
|
|
|
init(damus: DamusState, event: NostrEvent) { |
|
|
|
self.event = event |
|
|
|
self.highlight = .none |
|
|
|
self.has_action_bar = false |
|
|
|
self.damus = damus |
|
|
|
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) { |
|
|
|
init(damus: DamusState, event: NostrEvent, pubkey: String) { |
|
|
|
self.event = event |
|
|
|
self.highlight = .none |
|
|
|
self.has_action_bar = false |
|
|
|
self.damus = damus |
|
|
|
self.pubkey = pubkey |
|
|
|
self.show_friend_icon = show_friend_icon |
|
|
|
self.size = size |
|
|
|
self.embedded = embedded |
|
|
|
} |
|
|
|
|
|
|
|
var body: some View { |
|
|
@ -101,88 +84,43 @@ struct EventView: View { |
|
|
|
|
|
|
|
return HStack(alignment: .top) { |
|
|
|
let profile = damus.profiles.lookup(id: pubkey) |
|
|
|
|
|
|
|
if size != .selected { |
|
|
|
VStack { |
|
|
|
let pmodel = ProfileModel(pubkey: pubkey, damus: damus) |
|
|
|
let pv = ProfileView(damus_state: damus, profile: pmodel, followers: FollowersModel(damus_state: damus, target: pubkey)) |
|
|
|
|
|
|
|
if !embedded { |
|
|
|
NavigationLink(destination: pv) { |
|
|
|
ProfilePicView(pubkey: pubkey, size: PFP_SIZE, highlight: highlight, profiles: damus.profiles) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Spacer() |
|
|
|
|
|
|
|
VStack { |
|
|
|
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: .none, profiles: damus.profiles) |
|
|
|
} |
|
|
|
|
|
|
|
Spacer() |
|
|
|
} |
|
|
|
|
|
|
|
VStack(alignment: .leading) { |
|
|
|
HStack(alignment: .center) { |
|
|
|
if size == .selected { |
|
|
|
VStack { |
|
|
|
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) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
EventProfileName(pubkey: pubkey, profile: profile, damus: damus, show_friend_confirmed: true, size: .normal) |
|
|
|
|
|
|
|
EventProfileName(pubkey: pubkey, profile: profile, damus: damus, show_friend_confirmed: show_friend_icon, size: size) |
|
|
|
if size != .selected { |
|
|
|
Text("\(format_relative_time(event.created_at))") |
|
|
|
.font(eventviewsize_to_font(size)) |
|
|
|
.foregroundColor(.gray) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if event.is_reply(damus.keypair.privkey) { |
|
|
|
Text("\(reply_desc(profiles: damus.profiles, event: event))") |
|
|
|
.font(.footnote) |
|
|
|
Text("\(format_relative_time(event.created_at))") |
|
|
|
.foregroundColor(.gray) |
|
|
|
.frame(maxWidth: .infinity, alignment: .leading) |
|
|
|
} |
|
|
|
|
|
|
|
let should_show_img = should_show_images(contacts: damus.contacts, ev: event, our_pubkey: damus.pubkey, booster_pubkey: booster_pubkey) |
|
|
|
|
|
|
|
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) |
|
|
|
EventBody(damus_state: damus, event: event, size: .normal) |
|
|
|
|
|
|
|
if !embedded { |
|
|
|
if let mention = first_eref_mention(ev: event, privkey: damus.keypair.privkey) { |
|
|
|
BuilderEventView(damus: damus, event_id: mention.ref.id) |
|
|
|
} |
|
|
|
if let mention = first_eref_mention(ev: event, privkey: damus.keypair.privkey) { |
|
|
|
BuilderEventView(damus: damus, event_id: mention.ref.id) |
|
|
|
} |
|
|
|
|
|
|
|
if has_action_bar { |
|
|
|
Rectangle().frame(height: 2).opacity(0) |
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
if size == .selected && !bar.is_empty { |
|
|
|
EventDetailBar(state: damus, target: event.id, bar: bar) |
|
|
|
Divider() |
|
|
|
} |
|
|
|
|
|
|
|
EventActionBar(damus_state: damus, event: event, bar: bar) |
|
|
|
.padding([.top], 4) |
|
|
|
} |
|
|
|
|
|
|
|
Divider() |
|
|
|
let bar = make_actionbar_model(ev: event, damus: damus) |
|
|
|
|
|
|
|
EventActionBar(damus_state: damus, event: event, bar: bar) |
|
|
|
.padding([.top], 4) |
|
|
|
} |
|
|
|
|
|
|
|
Divider() |
|
|
|
.padding([.top], 4) |
|
|
|
} |
|
|
|
.padding([.leading], 2) |
|
|
|
} |
|
|
@ -339,31 +277,18 @@ struct EventView_Previews: PreviewProvider { |
|
|
|
|
|
|
|
*/ |
|
|
|
EventView( |
|
|
|
event: NostrEvent( |
|
|
|
content: "hello there https://jb55.com/s/Oct12-150217.png https://jb55.com/red-me.jpg cool", |
|
|
|
pubkey: "pk", |
|
|
|
createdAt: Int64(Date().timeIntervalSince1970 - 100) |
|
|
|
), |
|
|
|
highlight: .none, |
|
|
|
has_action_bar: true, |
|
|
|
damus: test_damus_state(), |
|
|
|
show_friend_icon: true, |
|
|
|
size: .selected |
|
|
|
) |
|
|
|
|
|
|
|
EventView( |
|
|
|
event: NostrEvent( |
|
|
|
content: "hello there https://jb55.com/s/Oct12-150217.png https://jb55.com/red-me.jpg cool", |
|
|
|
pubkey: "pk", |
|
|
|
createdAt: Int64(Date().timeIntervalSince1970 - 100) |
|
|
|
), |
|
|
|
highlight: .none, |
|
|
|
event: test_event, |
|
|
|
has_action_bar: true, |
|
|
|
damus: test_damus_state(), |
|
|
|
show_friend_icon: true, |
|
|
|
size: .normal |
|
|
|
damus: test_damus_state() |
|
|
|
) |
|
|
|
} |
|
|
|
.padding() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
let test_event = |
|
|
|
NostrEvent( |
|
|
|
content: "hello there https://jb55.com/s/Oct12-150217.png https://jb55.com/red-me.jpg cool", |
|
|
|
pubkey: "pk", |
|
|
|
createdAt: Int64(Date().timeIntervalSince1970 - 100) |
|
|
|
) |
|
|
|