Browse Source

misc tweaks

Signed-off-by: William Casarin <jb55@jb55.com>
profiles-everywhere
William Casarin 3 years ago
parent
commit
e1c4f59e9a
  1. 11
      damus/Models/HomeModel.swift
  2. 1
      damus/Nostr/Nostr.swift
  3. 2
      damus/Views/ChatView.swift
  4. 9
      damus/Views/EventActionBar.swift
  5. 7
      damus/Views/EventView.swift
  6. 54
      damus/Views/ProfileName.swift
  7. 2
      damus/Views/ProfilePicView.swift
  8. 67
      damus/Views/ProfileView.swift

11
damus/Models/HomeModel.swift

@ -197,11 +197,8 @@ class HomeModel: ObservableObject {
var friends = damus_state.contacts.get_friend_list()
friends.append(damus_state.pubkey)
var contacts_filter = NostrFilter.filter_kinds([0,3])
var friendosphere = damus_state.contacts.get_friendosphere()
friendosphere.append(damus_state.pubkey)
contacts_filter.authors = friendosphere
var contacts_filter = NostrFilter.filter_kinds([0])
contacts_filter.authors = friends
// TODO: separate likes?
var home_filter = NostrFilter.filter_kinds([
@ -211,7 +208,7 @@ class HomeModel: ObservableObject {
])
// include our pubkey as well even if we're not technically a friend
home_filter.authors = friends
home_filter.limit = 1000
home_filter.limit = 500
var notifications_filter = NostrFilter.filter_kinds([
NostrKind.text.rawValue,
@ -219,7 +216,7 @@ class HomeModel: ObservableObject {
NostrKind.boost.rawValue,
])
notifications_filter.pubkeys = [damus_state.pubkey]
notifications_filter.limit = 1000
notifications_filter.limit = 100
var home_filters = [home_filter]
var notifications_filters = [notifications_filter]

1
damus/Nostr/Nostr.swift

@ -10,6 +10,7 @@ import Foundation
struct Profile: Decodable {
let name: String?
let display_name: String?
let about: String?
let picture: String?

2
damus/Views/ChatView.swift

@ -126,7 +126,7 @@ struct ChatView: View {
.padding(6)
}
.padding([.leading], 2)
.background(Color.secondary.opacity(0.1))
.background(colorScheme == .light ? Color.secondary.opacity(0.1) : Color.secondary.opacity(0.25))
.cornerRadius(8.0)
//.border(Color.red)

9
damus/Views/EventActionBar.swift

@ -38,7 +38,6 @@ struct EventActionBar: View {
EventActionButton(img: "bubble.left", col: nil) {
notify(.reply, event)
}
.padding([.trailing], 20)
}
HStack(alignment: .bottom) {
@ -54,7 +53,6 @@ struct EventActionBar: View {
}
}
}
.padding([.trailing], 20)
HStack(alignment: .bottom) {
Text("\(bar.boosts > 0 ? "\(bar.boosts)" : "")")
@ -69,7 +67,6 @@ struct EventActionBar: View {
}
}
}
.padding([.trailing], 20)
HStack(alignment: .bottom) {
Text("\(bar.tips > 0 ? "\(bar.tips)" : "")")
@ -78,13 +75,12 @@ struct EventActionBar: View {
EventActionButton(img: bar.tipped ? "bitcoinsign.circle.fill" : "bitcoinsign.circle", col: bar.tipped ? Color.orange : nil) {
if bar.tipped {
notify(.delete, bar.our_tip)
//notify(.delete, bar.our_tip)
} else {
notify(.boost, event)
//notify(.boost, event)
}
}
}
}
.onReceive(handle_notify(.liked)) { n in
let liked = n.object as! Counted
@ -104,6 +100,7 @@ func EventActionButton(img: String, col: Color?, action: @escaping () -> ()) ->
Button(action: action) {
Label("", systemImage: img)
.font(.footnote)
.frame(maxWidth: .infinity)
.foregroundColor(col == nil ? Color.gray : col!)
}
}

7
damus/Views/EventView.swift

@ -78,12 +78,11 @@ struct EventView: View {
Spacer()
}
VStack {
HStack {
VStack(alignment: .leading) {
HStack(alignment: .center) {
ProfileName(pubkey: event.pubkey, profile: profile)
Text("\(format_relative_time(event.created_at))")
.foregroundColor(.gray)
Spacer()
}
if event.is_reply {
@ -97,8 +96,6 @@ struct EventView: View {
.frame(maxWidth: .infinity, alignment: .leading)
.textSelection(.enabled)
Spacer()
if has_action_bar {
let bar = make_actionbar_model(ev: event, damus: damus)
EventActionBar(event: event, keypair: damus.keypair, profiles: damus.profiles, bar: bar)

54
damus/Views/ProfileName.swift

@ -7,23 +7,59 @@
import SwiftUI
struct ProfileFullName: View {
let pubkey: String
let profile: Profile?
@State var display_name: String?
var body: some View {
HStack {
if let real_name = profile?.display_name {
Text(real_name)
.bold()
ProfileName(pubkey: pubkey, profile: profile, prefix: "@")
.font(.footnote)
.foregroundColor(.gray)
} else {
ProfileName(pubkey: pubkey, profile: profile)
}
}
}
}
struct ProfileName: View {
let pubkey: String
let profile: Profile?
let prefix: String
@State var display_name: String?
init(pubkey: String, profile: Profile?) {
self.pubkey = pubkey
self.profile = profile
self.prefix = ""
}
init(pubkey: String, profile: Profile?, prefix: String) {
self.pubkey = pubkey
self.profile = profile
self.prefix = prefix
}
var body: some View {
Text(String(display_name ?? Profile.displayName(profile: profile, pubkey: pubkey)))
//.foregroundColor(hex_to_rgb(pubkey))
.bold()
.onReceive(handle_notify(.profile_updated)) { notif in
let update = notif.object as! ProfileUpdate
if update.pubkey != pubkey {
return
}
display_name = Profile.displayName(profile: update.profile, pubkey: pubkey)
HStack {
Text(prefix + String(display_name ?? Profile.displayName(profile: profile, pubkey: pubkey)))
//.foregroundColor(hex_to_rgb(pubkey))
.fontWeight(prefix == "@" ? .none : .bold)
}
.onReceive(handle_notify(.profile_updated)) { notif in
let update = notif.object as! ProfileUpdate
if update.pubkey != pubkey {
return
}
display_name = Profile.displayName(profile: update.profile, pubkey: pubkey)
}
}
}

2
damus/Views/ProfilePicView.swift

@ -102,7 +102,7 @@ struct ProfilePicView: View {
func make_preview_profiles(_ pubkey: String) -> Profiles {
let profiles = Profiles()
let picture = "http://cdn.jb55.com/img/red-me.jpg"
let profile = Profile(name: "Will", about: "It's me", picture: picture)
let profile = Profile(name: "jb55", display_name: "William Casarin", about: "It's me", picture: picture)
let ts_profile = TimestampedProfile(profile: profile, timestamp: 0)
profiles.add(id: pubkey, profile: ts_profile)
return profiles

67
damus/Views/ProfileView.swift

@ -56,26 +56,33 @@ struct ProfileView: View {
var TopSection: some View {
VStack(alignment: .leading) {
let data = damus_state.profiles.lookup(id: profile.pubkey)
HStack(alignment: .top) {
HStack(alignment: .center) {
ProfilePicView(pubkey: profile.pubkey, size: PFP_SIZE, highlight: .custom(Color.black, 2), image_cache: damus_state.image_cache, profiles: damus_state.profiles)
if let real_name = data?.display_name {
VStack(alignment: .leading) {
Text(real_name)
.font(.title)
ProfileName(pubkey: profile.pubkey, profile: data, prefix: "@")
.font(.callout)
.foregroundColor(.gray)
}
} else {
ProfileName(pubkey: profile.pubkey, profile: data)
}
//.border(Color.green)
Spacer()
FollowButtonView(target: profile.get_follow_target(), follow_state: damus_state.contacts.follow_state(profile.pubkey))
}
if let pubkey = profile.pubkey {
ProfileName(pubkey: pubkey, profile: data)
.font(.title)
//.border(Color.green)
Text("\(pubkey)")
.textSelection(.enabled)
.font(.footnote)
.foregroundColor(id_to_color(pubkey))
}
KeyView(pubkey: profile.pubkey)
.padding(.bottom, 10)
Text(data?.about ?? "")
if let contact = profile.contacts {
Divider()
@ -118,10 +125,42 @@ struct ProfileView: View {
}
}
/*
struct ProfileView_Previews: PreviewProvider {
static var previews: some View {
ProfileView()
let ds = test_damus_state()
let profile_model = ProfileModel(pubkey: ds.pubkey, damus: ds)
ProfileView(damus_state: ds, profile: profile_model)
}
}
func test_damus_state() -> DamusState {
let pubkey = "3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681"
let damus = DamusState(pool: RelayPool(), keypair: Keypair(pubkey: pubkey, privkey: "privkey"), likes: EventCounter(our_pubkey: pubkey), boosts: EventCounter(our_pubkey: pubkey), contacts: Contacts(), tips: TipCounter(our_pubkey: pubkey), image_cache: ImageCache(), profiles: Profiles())
let prof = Profile(name: "damus", display_name: "Damus", about: "iOS app!", picture: "https://damus.io/img/logo.png")
let tsprof = TimestampedProfile(profile: prof, timestamp: 0)
damus.profiles.add(id: pubkey, profile: tsprof)
return damus
}
struct KeyView: View {
let pubkey: String
@Environment(\.colorScheme) var colorScheme
var body: some View {
let col = id_to_color(pubkey)
VStack {
Text("\(String(pubkey.prefix(32)))")
.foregroundColor(colorScheme == .light ? .black : col)
.font(.footnote.monospaced())
Text("\(String(pubkey.suffix(32)))")
.font(.footnote.monospaced())
.foregroundColor(colorScheme == .light ? .black : col)
}
}
}
*/

Loading…
Cancel
Save