damus

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

commit 13cec8cffee919798dac659bcd22c8e8bad768b6
parent 045aaaf59b52736a54e535b99ee4244e46dc343a
Author: William Casarin <jb55@jb55.com>
Date:   Sun,  8 May 2022 16:09:52 -0700

fix likes

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus/ContentView.swift | 5+++--
Mdamus/Models/DamusState.swift | 1-
Mdamus/Models/LikeCounter.swift | 16++++++++--------
Mdamus/Models/ThreadModel.swift | 5++---
4 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/damus/ContentView.swift b/damus/ContentView.swift @@ -377,7 +377,8 @@ struct ContentView: View { } func handle_boost_event(_ ev: NostrEvent) { - damus!.boosts.add_event(ev) + + //damus!.boosts.add_event(ev) } func handle_like_event(_ ev: NostrEvent) { @@ -388,7 +389,7 @@ struct ContentView: View { // CHECK SIGS ON THESE - switch damus!.likes.add_event(ev) { + switch damus!.likes.add_event(ev, target: e.ref_id) { case .user_already_liked: break case .success(let n): diff --git a/damus/Models/DamusState.swift b/damus/Models/DamusState.swift @@ -13,5 +13,4 @@ struct DamusState { let likes: EventCounter let boosts: EventCounter let image_cache: ImageCache - } diff --git a/damus/Models/LikeCounter.swift b/damus/Models/LikeCounter.swift @@ -23,31 +23,31 @@ class EventCounter { self.our_pubkey = our_pubkey } - func add_event(_ ev: NostrEvent) -> LikeResult { + func add_event(_ ev: NostrEvent, target: String) -> LikeResult { let pubkey = ev.pubkey if self.user_events[pubkey] == nil { self.user_events[pubkey] = Set() } - if user_events[pubkey]!.contains(ev.id) { + if user_events[pubkey]!.contains(target) { // don't double count return .user_already_liked } - user_events[pubkey]!.insert(ev.id) + user_events[pubkey]!.insert(target) if ev.pubkey == self.our_pubkey { - our_events[ev.id] = ev + our_events[target] = ev } - if counts[ev.id] == nil { - counts[ev.id] = 1 + if counts[target] == nil { + counts[target] = 1 return .success(1) } - counts[ev.id]! += 1 + counts[target]! += 1 - return .success(counts[ev.id]!) + return .success(counts[target]!) } } diff --git a/damus/Models/ThreadModel.swift b/damus/Models/ThreadModel.swift @@ -101,9 +101,8 @@ class ThreadModel: ObservableObject { } func subscribe() { - let kinds: [Int] = [1, 5, 6, 7] - var ref_events = NostrFilter.filter_kinds(kinds) - var events_filter = NostrFilter.filter_kinds(kinds) + var ref_events = NostrFilter.filter_kinds([1,5,7]) + var events_filter = NostrFilter.filter_kinds([1]) //var likes_filter = NostrFilter.filter_kinds(7]) // TODO: add referenced relays