@@ -113,6 +113,8 @@ struct ChatView: View {
|
||||
if just_started {
|
||||
HStack {
|
||||
ProfileName(pubkey: event.pubkey, profile: profile)
|
||||
.foregroundColor(id_to_color(event.pubkey))
|
||||
//.shadow(color: Color.secondary, radius: 2, x: 2, y: 2)
|
||||
Text("\(format_relative_time(event.created_at))")
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
|
||||
@@ -31,27 +31,17 @@ struct EventActionBar: View {
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
*/
|
||||
|
||||
EventActionButton(img: "bubble.left") {
|
||||
self.sheet = .reply
|
||||
notify(.reply, event)
|
||||
}
|
||||
}
|
||||
.sheet(item: $sheet) { sheet in
|
||||
switch sheet {
|
||||
case .reply:
|
||||
ReplyView(replying_to: event)
|
||||
.environmentObject(profiles)
|
||||
.onReceive(NotificationCenter.default.publisher(for: .post)) { obj in
|
||||
let res = obj.object as! NostrPostResult
|
||||
switch res {
|
||||
case .cancel:
|
||||
self.sheet = nil
|
||||
case .post:
|
||||
self.sheet = nil
|
||||
}
|
||||
}
|
||||
.padding([.trailing], 40)
|
||||
|
||||
EventActionButton(img: "arrow.2.squarepath") {
|
||||
notify(.boost, event)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,3 +54,4 @@ func EventActionButton(img: String, action: @escaping () -> ()) -> some View {
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ struct EventDetailView: View {
|
||||
}
|
||||
}
|
||||
.onAppear() {
|
||||
if highlight == .main {
|
||||
if highlight.is_main {
|
||||
scroll_to_event(scroller: scroller, id: ev.id, delay: 0.5, animate: true)
|
||||
}
|
||||
}
|
||||
@@ -270,6 +270,7 @@ func calculated_collapsed_events(collapsed: Bool, active: NostrEvent?, events: [
|
||||
}
|
||||
count += 1
|
||||
case .main: fallthrough
|
||||
case .custom: fallthrough
|
||||
case .reply:
|
||||
if count != 0 {
|
||||
let c = CollapsedEvents(count: count, start: start, end: i)
|
||||
|
||||
@@ -12,12 +12,20 @@ enum Highlight {
|
||||
case none
|
||||
case main
|
||||
case reply
|
||||
case custom(Color, Float)
|
||||
|
||||
var is_none: Bool {
|
||||
switch self {
|
||||
case .none: return true
|
||||
default: return false
|
||||
var is_main: Bool {
|
||||
if case .main = self {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var is_none: Bool {
|
||||
if case .none = self {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var is_replied_to: Bool {
|
||||
@@ -40,6 +48,9 @@ struct EventView: View {
|
||||
HStack {
|
||||
VStack {
|
||||
ProfilePicView(picture: profile?.picture, size: PFP_SIZE!, highlight: highlight)
|
||||
.onTapGesture {
|
||||
NotificationCenter.default.post(name: .click_profile_pic, object: event.pubkey)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ struct PostView: View {
|
||||
func send_post() {
|
||||
let new_post = NostrPost(content: self.post, references: references)
|
||||
NotificationCenter.default.post(name: .post, object: NostrPostResult.post(new_post))
|
||||
//dismiss()
|
||||
dismiss()
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
|
||||
@@ -9,6 +9,7 @@ import SwiftUI
|
||||
|
||||
func ProfileName(pubkey: String, profile: Profile?) -> some View {
|
||||
Text(String(Profile.displayName(profile: profile, pubkey: pubkey)))
|
||||
.foregroundColor(hex_to_rgb(pubkey))
|
||||
.bold()
|
||||
}
|
||||
|
||||
|
||||
@@ -11,23 +11,24 @@ let PFP_SIZE: CGFloat? = 52.0
|
||||
let CORNER_RADIUS: CGFloat = 32
|
||||
|
||||
func id_to_color(_ id: String) -> Color {
|
||||
return .init(hex: String(id.reversed().prefix(6)))
|
||||
return hex_to_rgb(id)
|
||||
}
|
||||
|
||||
func highlight_color(_ h: Highlight) -> Color {
|
||||
switch h {
|
||||
case .reply: fallthrough
|
||||
case .none: return Color.black
|
||||
case .main: return Color.red
|
||||
case .reply: return Color.black
|
||||
case .none: return Color.black
|
||||
case .custom(let c, _): return c
|
||||
}
|
||||
}
|
||||
|
||||
func pfp_line_width(_ h: Highlight) -> CGFloat {
|
||||
switch h {
|
||||
case .none: fallthrough
|
||||
case .reply:
|
||||
return 0
|
||||
case .reply: return 0
|
||||
case .none: return 0
|
||||
case .main: return 2
|
||||
case .custom(_, let lw): return CGFloat(lw)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,23 +41,29 @@ struct ProfilePicView: View {
|
||||
Color.purple.opacity(0.2)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
if let pic = picture.flatMap({ URL(string: $0) }) {
|
||||
AsyncImage(url: pic) { img in
|
||||
img.resizable()
|
||||
} placeholder: { Placeholder }
|
||||
.frame(width: size, height: size)
|
||||
.clipShape(Circle())
|
||||
.overlay(Circle().stroke(highlight_color(highlight), lineWidth: pfp_line_width(highlight)))
|
||||
.padding(2)
|
||||
} else {
|
||||
Placeholder
|
||||
var MainContent: some View {
|
||||
Group {
|
||||
if let pic = picture.flatMap({ URL(string: $0) }) {
|
||||
AsyncImage(url: pic) { img in
|
||||
img.resizable()
|
||||
} placeholder: { Placeholder }
|
||||
.frame(width: size, height: size)
|
||||
.cornerRadius(CORNER_RADIUS)
|
||||
.clipShape(Circle())
|
||||
.overlay(Circle().stroke(highlight_color(highlight), lineWidth: pfp_line_width(highlight)))
|
||||
.padding(2)
|
||||
} else {
|
||||
Placeholder
|
||||
.frame(width: size, height: size)
|
||||
.cornerRadius(CORNER_RADIUS)
|
||||
.overlay(Circle().stroke(highlight_color(highlight), lineWidth: pfp_line_width(highlight)))
|
||||
.padding(2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
MainContent
|
||||
}
|
||||
}
|
||||
|
||||
struct ProfilePicView_Previews: PreviewProvider {
|
||||
@@ -66,28 +73,36 @@ struct ProfilePicView_Previews: PreviewProvider {
|
||||
}
|
||||
|
||||
|
||||
extension Color {
|
||||
init(hex: String) {
|
||||
var int: UInt64 = 0
|
||||
Scanner(string: hex).scanHexInt64(&int)
|
||||
let a, r, g, b: UInt64
|
||||
switch hex.count {
|
||||
case 3: // RGB (12-bit)
|
||||
(a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17)
|
||||
case 6: // RGB (24-bit)
|
||||
(a, r, g, b) = (255, int >> 16, int >> 8 & 0xFF, int & 0xFF)
|
||||
case 8: // ARGB (32-bit)
|
||||
(a, r, g, b) = (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF)
|
||||
default:
|
||||
(a, r, g, b) = (1, 1, 1, 0)
|
||||
func hex_to_rgb(_ hex: String) -> Color {
|
||||
guard hex.count >= 6 else {
|
||||
return Color.black
|
||||
}
|
||||
|
||||
let arr = Array(hex.utf8)
|
||||
var rgb: [UInt8] = []
|
||||
var i: Int = 0
|
||||
|
||||
while i < 6 {
|
||||
let cs1 = arr[i]
|
||||
let cs2 = arr[i+1]
|
||||
|
||||
guard let c1 = char_to_hex(cs1) else {
|
||||
return Color.black
|
||||
}
|
||||
|
||||
self.init(
|
||||
.sRGB,
|
||||
red: Double(r) / 255,
|
||||
green: Double(g) / 255,
|
||||
blue: Double(b) / 255,
|
||||
opacity: Double(a) / 255
|
||||
)
|
||||
guard let c2 = char_to_hex(cs2) else {
|
||||
return Color.black
|
||||
}
|
||||
|
||||
rgb.append((c1 << 4) | c2)
|
||||
i += 2
|
||||
}
|
||||
|
||||
return Color.init(
|
||||
.sRGB,
|
||||
red: Double(rgb[0]) / 255,
|
||||
green: Double(rgb[1]) / 255,
|
||||
blue: Double(rgb[2]) / 255,
|
||||
opacity: 1
|
||||
)
|
||||
}
|
||||
|
||||
26
damus/Views/ProfileView.swift
Normal file
26
damus/Views/ProfileView.swift
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// ProfileView.swift
|
||||
// damus
|
||||
//
|
||||
// Created by William Casarin on 2022-04-23.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ProfileView: View {
|
||||
let profile: Profile? = nil
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
ProfilePicView(picture: profile?.picture, size: 64, highlight: .custom(Color.black, 4))
|
||||
//ProfileName(pubkey: <#T##String#>, profile: <#T##Profile?#>)
|
||||
}
|
||||
.navigationBarTitle("Profile")
|
||||
}
|
||||
}
|
||||
|
||||
struct ProfileView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ProfileView()
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,13 @@ struct ReplyQuoteView: View {
|
||||
HStack(alignment: .top) {
|
||||
Rectangle().frame(width: 2)
|
||||
.padding([.leading], 4)
|
||||
|
||||
.foregroundColor(.accentColor)
|
||||
|
||||
VStack(alignment: .leading) {
|
||||
HStack(alignment: .top) {
|
||||
ProfilePicView(picture: profiles.lookup(id: event.pubkey)?.picture, size: 16, highlight: .none)
|
||||
ProfileName(pubkey: event.pubkey, profile: profiles.lookup(id: event.pubkey))
|
||||
ProfilePicView(picture: profiles.lookup(id: event.pubkey)?.picture, size: 16, highlight: .reply)
|
||||
Text(Profile.displayName(profile: profiles.lookup(id: event.pubkey), pubkey: event.pubkey))
|
||||
.foregroundColor(.accentColor)
|
||||
Text("\(format_relative_time(event.created_at))")
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user