Ensure stats get updated in realtime on action bars

Changelog-Fixed: Ensure stats get updated in realtime on action bars
This commit is contained in:
William Casarin
2023-02-14 10:05:59 -08:00
parent 6d634763c5
commit 59211bb4fd
5 changed files with 13 additions and 21 deletions

View File

@@ -230,6 +230,7 @@ class HomeModel: ObservableObject {
case .success(let n):
let boosted = Counted(event: ev, id: e, total: n)
notify(.boosted, boosted)
notify(.update_stats, e)
}
}
@@ -247,6 +248,7 @@ class HomeModel: ObservableObject {
case .success(let n):
let liked = Counted(event: ev, id: e.ref_id, total: n)
notify(.liked, liked)
notify(.update_stats, e.ref_id)
}
}

View File

@@ -98,8 +98,8 @@ extension Notification.Name {
static var deleted_account: Notification.Name {
return Notification.Name("deleted_account")
}
static var new_zap: Notification.Name {
return Notification.Name("new_zap")
static var update_stats: Notification.Name {
return Notification.Name("update_stats")
}
}

View File

@@ -60,7 +60,7 @@ class Zaps {
event_counts[id] = event_counts[id]! + 1
event_totals[id] = event_totals[id]! + zap.invoice.amount
notify(.new_zap, zap)
notify(.update_stats, zap.target.id)
return
}

View File

@@ -111,15 +111,10 @@ struct EventActionBar: View {
} message: {
Text("Are you sure you want to repost this?", comment: "Alert message to ask if user wants to repost a post.")
}
.onReceive(handle_notify(.new_zap)) { n in
let zap = n.object as! Zap
guard case .note(let note_target) = zap.target else {
return
}
guard note_target.note_id == self.event.id else {
return
}
self.bar.update(damus: self.damus_state, evid: self.event.id)
.onReceive(handle_notify(.update_stats)) { n in
let target = n.object as! String
guard target == self.event.id else { return }
self.bar.update(damus: self.damus_state, evid: target)
}
.onReceive(handle_notify(.liked)) { n in
let liked = n.object as! Counted

View File

@@ -54,15 +54,10 @@ struct SelectedEventView: View {
Divider()
.padding([.top], 4)
}
.onReceive(handle_notify(.new_zap)) { n in
let zap = n.object as! Zap
guard case .note(let note_target) = zap.target else {
return
}
guard note_target.note_id == self.event.id else {
return
}
self.bar.update(damus: self.damus, evid: self.event.id)
.onReceive(handle_notify(.update_stats)) { n in
let target = n.object as! String
guard target == self.event.id else { return }
self.bar.update(damus: self.damus, evid: target)
}
.padding([.leading], 2)
.event_context_menu(event, keypair: damus.keypair, target_pubkey: event.pubkey)