damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 59211bb4fdab67142ca30a7ac11cc80c8f1a1ae8
parent 6d634763c555b76f153a5a643bafe3d0fb28de59
Author: William Casarin <jb55@jb55.com>
Date:   Tue, 14 Feb 2023 10:05:59 -0800

Ensure stats get updated in realtime on action bars

Changelog-Fixed: Ensure stats get updated in realtime on action bars

Diffstat:
Mdamus/Models/HomeModel.swift | 2++
Mdamus/Util/Notifications.swift | 4++--
Mdamus/Util/Zaps.swift | 2+-
Mdamus/Views/ActionBar/EventActionBar.swift | 13++++---------
Mdamus/Views/Events/SelectedEventView.swift | 13++++---------
5 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/damus/Models/HomeModel.swift b/damus/Models/HomeModel.swift @@ -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) } } diff --git a/damus/Util/Notifications.swift b/damus/Util/Notifications.swift @@ -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") } } diff --git a/damus/Util/Zaps.swift b/damus/Util/Zaps.swift @@ -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 } diff --git a/damus/Views/ActionBar/EventActionBar.swift b/damus/Views/ActionBar/EventActionBar.swift @@ -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 diff --git a/damus/Views/Events/SelectedEventView.swift b/damus/Views/Events/SelectedEventView.swift @@ -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)