damus

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

commit 042e02d2e447c2edcca08559a90196becb482b40
parent 40468b16036a41a493e1f9a01f30c5ecd9bbbc6f
Author: William Casarin <jb55@jb55.com>
Date:   Fri, 14 Apr 2023 10:32:54 -0700

regression: unbreak dms

Diffstat:
Mdamus/ContentView.swift | 2+-
Mdamus/Models/DamusState.swift | 3+--
Mdamus/Models/HomeModel.swift | 4++--
Mdamus/Models/MutedThreadsManager.swift | 16++++++++--------
Mdamus/Models/NotificationsModel.swift | 3++-
Mdamus/Views/Events/EventMenu.swift | 4++--
Mdamus/Views/SearchHomeView.swift | 2+-
7 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/damus/ContentView.swift b/damus/ContentView.swift @@ -644,7 +644,7 @@ struct ContentView: View { postbox: PostBox(pool: pool), bootstrap_relays: bootstrap_relays, replies: ReplyCounter(our_pubkey: pubkey), - muted_threads: MutedThreadsManager(pubkey: pubkey) + muted_threads: MutedThreadsManager(keypair: keypair) ) home.damus_state = self.damus_state! diff --git a/damus/Models/DamusState.swift b/damus/Models/DamusState.swift @@ -40,6 +40,5 @@ struct DamusState { } static var empty: DamusState { - return DamusState.init(pool: RelayPool(), keypair: Keypair(pubkey: "", privkey: ""), likes: EventCounter(our_pubkey: ""), boosts: EventCounter(our_pubkey: ""), contacts: Contacts(our_pubkey: ""), tips: TipCounter(our_pubkey: ""), profiles: Profiles(), dms: DirectMessagesModel(our_pubkey: ""), previews: PreviewCache(), zaps: Zaps(our_pubkey: ""), lnurls: LNUrls(), settings: UserSettingsStore(), relay_filters: RelayFilters(our_pubkey: ""), relay_metadata: RelayMetadatas(), drafts: Drafts(), events: EventCache(), bookmarks: BookmarksManager(pubkey: ""), postbox: PostBox(pool: RelayPool()), bootstrap_relays: [], replies: ReplyCounter(our_pubkey: ""), muted_threads: MutedThreadsManager(pubkey: "")) - } + return DamusState.init(pool: RelayPool(), keypair: Keypair(pubkey: "", privkey: ""), likes: EventCounter(our_pubkey: ""), boosts: EventCounter(our_pubkey: ""), contacts: Contacts(our_pubkey: ""), tips: TipCounter(our_pubkey: ""), profiles: Profiles(), dms: DirectMessagesModel(our_pubkey: ""), previews: PreviewCache(), zaps: Zaps(our_pubkey: ""), lnurls: LNUrls(), settings: UserSettingsStore(), relay_filters: RelayFilters(our_pubkey: ""), relay_metadata: RelayMetadatas(), drafts: Drafts(), events: EventCache(), bookmarks: BookmarksManager(pubkey: ""), postbox: PostBox(pool: RelayPool()), bootstrap_relays: [], replies: ReplyCounter(our_pubkey: ""), muted_threads: MutedThreadsManager(keypair: Keypair(pubkey: "", privkey: nil))) } } diff --git a/damus/Models/HomeModel.swift b/damus/Models/HomeModel.swift @@ -199,7 +199,7 @@ class HomeModel: ObservableObject { } func filter_muted() { - events.filter { !damus_state.contacts.is_muted($0.pubkey) && !damus_state.muted_threads.isMutedThread($0) } + events.filter { !damus_state.contacts.is_muted($0.pubkey) && !damus_state.muted_threads.isMutedThread($0, privkey: self.damus_state.keypair.privkey) } self.dms.dms = dms.dms.filter { !damus_state.contacts.is_muted($0.0) } notifications.filter_and_build_notifications(damus_state) } @@ -1047,7 +1047,7 @@ func process_local_notification(damus_state: DamusState, event ev: NostrEvent) { } // Don't show notifications from muted threads. - if damus_state.muted_threads.isMutedThread(ev) { + if damus_state.muted_threads.isMutedThread(ev, privkey: damus_state.keypair.privkey) { return } diff --git a/damus/Models/MutedThreadsManager.swift b/damus/Models/MutedThreadsManager.swift @@ -30,7 +30,7 @@ func saveMutedThreads(pubkey: String, currentValue: [String], value: [String]) - class MutedThreadsManager: ObservableObject { private let userDefaults = UserDefaults.standard - private let pubkey: String + private let keypair: Keypair private var _mutedThreadsSet: Set<String> private var _mutedThreads: [String] @@ -39,26 +39,26 @@ class MutedThreadsManager: ObservableObject { return _mutedThreads } set { - if saveMutedThreads(pubkey: pubkey, currentValue: _mutedThreads, value: newValue) { + if saveMutedThreads(pubkey: keypair.pubkey, currentValue: _mutedThreads, value: newValue) { self._mutedThreads = newValue self.objectWillChange.send() } } } - init(pubkey: String) { - self._mutedThreads = loadMutedThreads(pubkey: pubkey) + init(keypair: Keypair) { + self._mutedThreads = loadMutedThreads(pubkey: keypair.pubkey) self._mutedThreadsSet = Set(_mutedThreads) - self.pubkey = pubkey + self.keypair = keypair } - func isMutedThread(_ ev: NostrEvent) -> Bool { - return _mutedThreadsSet.contains(ev.thread_id(privkey: nil)) + func isMutedThread(_ ev: NostrEvent, privkey: String?) -> Bool { + return _mutedThreadsSet.contains(ev.thread_id(privkey: privkey)) } func updateMutedThread(_ ev: NostrEvent) { let threadId = ev.thread_id(privkey: nil) - if isMutedThread(ev) { + if isMutedThread(ev, privkey: keypair.privkey) { mutedThreads = mutedThreads.filter { $0 != threadId } _mutedThreadsSet.remove(threadId) notify(.unmute_thread, ev) diff --git a/damus/Models/NotificationsModel.swift b/damus/Models/NotificationsModel.swift @@ -319,6 +319,7 @@ class NotificationsModel: ObservableObject, ScrollQueue { } func include_event(_ event: NostrEvent, damus_state: DamusState) -> Bool { - return should_show_event(contacts: damus_state.contacts, ev: event) && !damus_state.muted_threads.isMutedThread(event) + let privkey = damus_state.keypair.privkey + return should_show_event(contacts: damus_state.contacts, ev: event) && !damus_state.muted_threads.isMutedThread(event, privkey: privkey) } } diff --git a/damus/Views/Events/EventMenu.swift b/damus/Views/Events/EventMenu.swift @@ -46,7 +46,7 @@ struct MenuItems: View { let bookmarked = bookmarks.isBookmarked(event) self._isBookmarked = State(initialValue: bookmarked) - let muted_thread = muted_threads.isMutedThread(event) + let muted_thread = muted_threads.isMutedThread(event, privkey: keypair.privkey) self._isMutedThread = State(initialValue: muted_thread) self.bookmarks = bookmarks @@ -96,7 +96,7 @@ struct MenuItems: View { if event.known_kind != .dm { Button { self.muted_threads.updateMutedThread(event) - let muted = self.muted_threads.isMutedThread(event) + let muted = self.muted_threads.isMutedThread(event, privkey: self.keypair.privkey) isMutedThread = muted } label: { let imageName = isMutedThread ? "speaker" : "speaker.slash" diff --git a/damus/Views/SearchHomeView.swift b/damus/Views/SearchHomeView.swift @@ -50,7 +50,7 @@ struct SearchHomeView: View { damus: damus_state, show_friend_icon: true, filter: { - if damus_state.muted_threads.isMutedThread($0) { + if damus_state.muted_threads.isMutedThread($0, privkey: self.damus_state.keypair.privkey) { return false }