profile: don't auto-load followers
This is a bandwidth-intensive operation Changelog-Changed: Don't auto-load follower count
This commit is contained in:
@@ -12,12 +12,19 @@ class FollowersModel: ObservableObject {
|
|||||||
let target: String
|
let target: String
|
||||||
var needs_sub: Bool = true
|
var needs_sub: Bool = true
|
||||||
|
|
||||||
@Published var contacts: [String] = []
|
@Published var contacts: [String]? = nil
|
||||||
var has_contact: Set<String> = Set()
|
var has_contact: Set<String> = Set()
|
||||||
|
|
||||||
let sub_id: String = UUID().description
|
let sub_id: String = UUID().description
|
||||||
let profiles_id: String = UUID().description
|
let profiles_id: String = UUID().description
|
||||||
|
|
||||||
|
var count_display: String {
|
||||||
|
guard let contacts = self.contacts else {
|
||||||
|
return "?"
|
||||||
|
}
|
||||||
|
return "\(contacts.count)";
|
||||||
|
}
|
||||||
|
|
||||||
init(damus_state: DamusState, target: String) {
|
init(damus_state: DamusState, target: String) {
|
||||||
self.damus_state = damus_state
|
self.damus_state = damus_state
|
||||||
self.target = target
|
self.target = target
|
||||||
@@ -49,13 +56,13 @@ class FollowersModel: ObservableObject {
|
|||||||
contacts: damus_state.contacts,
|
contacts: damus_state.contacts,
|
||||||
pubkey: damus_state.pubkey, ev: ev
|
pubkey: damus_state.pubkey, ev: ev
|
||||||
)
|
)
|
||||||
contacts.append(ev.pubkey)
|
contacts?.append(ev.pubkey)
|
||||||
has_contact.insert(ev.pubkey)
|
has_contact.insert(ev.pubkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func load_profiles(relay_id: String) {
|
func load_profiles(relay_id: String) {
|
||||||
var filter = NostrFilter.filter_profiles
|
var filter = NostrFilter.filter_profiles
|
||||||
let authors = find_profiles_to_fetch_pk(profiles: damus_state.profiles, event_pubkeys: contacts)
|
let authors = find_profiles_to_fetch_pk(profiles: damus_state.profiles, event_pubkeys: contacts ?? [])
|
||||||
if authors.isEmpty {
|
if authors.isEmpty {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ struct FollowersView: View {
|
|||||||
let profile = damus_state.profiles.lookup(id: whos)
|
let profile = damus_state.profiles.lookup(id: whos)
|
||||||
ScrollView {
|
ScrollView {
|
||||||
LazyVStack(alignment: .leading) {
|
LazyVStack(alignment: .leading) {
|
||||||
ForEach(followers.contacts, id: \.self) { pk in
|
ForEach(followers.contacts ?? [], id: \.self) { pk in
|
||||||
FollowUserView(target: .pubkey(pk), damus_state: damus_state)
|
FollowUserView(target: .pubkey(pk), damus_state: damus_state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -201,20 +201,33 @@ struct ProfileView: View {
|
|||||||
}
|
}
|
||||||
let fview = FollowersView(damus_state: damus_state, whos: profile.pubkey)
|
let fview = FollowersView(damus_state: damus_state, whos: profile.pubkey)
|
||||||
.environmentObject(followers)
|
.environmentObject(followers)
|
||||||
NavigationLink(destination: fview) {
|
if followers.contacts != nil {
|
||||||
HStack {
|
NavigationLink(destination: fview) {
|
||||||
Text("\(followers.contacts.count)")
|
FollowersCount
|
||||||
.font(.subheadline.weight(.medium))
|
|
||||||
Text("Followers")
|
|
||||||
.font(.subheadline)
|
|
||||||
.foregroundColor(.gray)
|
|
||||||
}
|
}
|
||||||
|
.buttonStyle(PlainButtonStyle())
|
||||||
|
} else {
|
||||||
|
FollowersCount
|
||||||
|
.onTapGesture {
|
||||||
|
UIImpactFeedbackGenerator(style: .light).impactOccurred()
|
||||||
|
followers.contacts = []
|
||||||
|
followers.subscribe()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.buttonStyle(PlainButtonStyle())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var FollowersCount: some View {
|
||||||
|
HStack {
|
||||||
|
Text("\(followers.count_display)")
|
||||||
|
.font(.subheadline.weight(.medium))
|
||||||
|
Text("Followers")
|
||||||
|
.font(.subheadline)
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(alignment: .leading) {
|
VStack(alignment: .leading) {
|
||||||
ScrollView {
|
ScrollView {
|
||||||
@@ -237,7 +250,7 @@ struct ProfileView: View {
|
|||||||
}
|
}
|
||||||
.onDisappear {
|
.onDisappear {
|
||||||
profile.unsubscribe()
|
profile.unsubscribe()
|
||||||
//followers.unsubscribe()
|
followers.unsubscribe()
|
||||||
// our profilemodel needs a bit more help
|
// our profilemodel needs a bit more help
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user