damus

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

commit b5c384da4380ce126123fec338b172b87f4d14a9
parent 356ef45b9154c84e8a52e59a683585ed06677756
Author: William Casarin <jb55@jb55.com>
Date:   Thu, 25 Jan 2024 12:10:08 -0800

Revert "mute: adding filtering support for MuteItem events"

This reverts commit 61a9e44898bda3d7888c116e555f6d02f201a1d9.

Diffstat:
Mdamus/ContentView.swift | 22+++++++++++-----------
Mdamus/Models/Contacts.swift | 18+++++++++---------
Mdamus/Models/HomeModel.swift | 14++++++++------
Mdamus/Models/NotificationsManager.swift | 11++++++++---
Mdamus/Notify/MuteNotify.swift | 6+++---
Mdamus/Notify/NewMutesNotify.swift | 4++--
Mdamus/Notify/NewUnmutesNotify.swift | 4++--
Mdamus/Views/DirectMessagesView.swift | 2+-
Mdamus/Views/Events/EventMenu.swift | 2+-
Mdamus/Views/Events/EventMutingContainerView.swift | 5++---
Mdamus/Views/Profile/ProfileView.swift | 4++--
11 files changed, 49 insertions(+), 43 deletions(-)

diff --git a/damus/ContentView.swift b/damus/ContentView.swift @@ -71,7 +71,7 @@ struct ContentView: View { @State var active_sheet: Sheets? = nil @State var damus_state: DamusState! @SceneStorage("ContentView.selected_timeline") var selected_timeline: Timeline = .home - @State var muting: MuteItem? = nil + @State var muting: Pubkey? = nil @State var confirm_mute: Bool = false @State var hide_bar: Bool = false @State var user_muted_confirm: Bool = false @@ -366,8 +366,8 @@ struct ContentView: View { .onReceive(handle_notify(.report)) { target in self.active_sheet = .report(target) } - .onReceive(handle_notify(.mute)) { mute_item in - self.muting = mute_item + .onReceive(handle_notify(.mute)) { pubkey in + self.muting = pubkey self.confirm_mute = true } .onReceive(handle_notify(.attached_wallet)) { nwc in @@ -526,7 +526,7 @@ struct ContentView: View { user_muted_confirm = false } }, message: { - if case let .user(pubkey, _) = self.muting { + if let pubkey = self.muting { let profile_txn = damus_state!.profiles.lookup(id: pubkey) let profile = profile_txn?.unsafeUnownedValue let name = Profile.displayName(profile: profile, pubkey: pubkey).username.truncate(maxLength: 50) @@ -544,13 +544,13 @@ struct ContentView: View { Button(NSLocalizedString("Yes, Overwrite", comment: "Text of button that confirms to overwrite the existing mutelist.")) { guard let ds = damus_state, let keypair = ds.keypair.to_full(), - let muting, - let mutelist = create_or_update_mutelist(keypair: keypair, mprev: nil, to_add: muting) + let pubkey = muting, + let mutelist = create_or_update_mutelist(keypair: keypair, mprev: nil, to_add: .user(pubkey, nil)) else { return } - ds.contacts.set_mutelist(mutelist) + damus_state?.contacts.set_mutelist(mutelist) ds.postbox.send(mutelist) confirm_overwrite_mutelist = false @@ -573,21 +573,21 @@ struct ContentView: View { confirm_overwrite_mutelist = true } else { guard let keypair = ds.keypair.to_full(), - let muting + let pubkey = muting else { return } - guard let ev = create_or_update_mutelist(keypair: keypair, mprev: ds.contacts.mutelist, to_add: muting) else { + guard let ev = create_or_update_mutelist(keypair: keypair, mprev: ds.contacts.mutelist, to_add: .user(pubkey, nil)) else { return } - ds.contacts.set_mutelist(ev) + damus_state?.contacts.set_mutelist(ev) ds.postbox.send(ev) } } }, message: { - if case let .user(pubkey, _) = muting { + if let pubkey = muting { let profile_txn = damus_state?.profiles.lookup(id: pubkey) let profile = profile_txn?.unsafeUnownedValue let name = Profile.displayName(profile: profile, pubkey: pubkey).username.truncate(maxLength: 50) diff --git a/damus/Models/Contacts.swift b/damus/Models/Contacts.swift @@ -13,7 +13,7 @@ class Contacts { private var friend_of_friends: Set<Pubkey> = Set() /// Tracks which friends are friends of a given pubkey. private var pubkey_to_our_friends = [Pubkey : Set<Pubkey>]() - private var muted: Set<MuteItem> = Set() + private var muted: Set<Pubkey> = Set() let our_pubkey: Pubkey var event: NostrEvent? @@ -23,20 +23,20 @@ class Contacts { self.our_pubkey = our_pubkey } - func is_muted(_ item: MuteItem) -> Bool { - return muted.contains(item) + func is_muted(_ pk: Pubkey) -> Bool { + return muted.contains(pk) } - + func set_mutelist(_ ev: NostrEvent) { let oldlist = self.mutelist self.mutelist = ev - let old: Set<MuteItem> = oldlist?.mute_list ?? Set<MuteItem>() - let new: Set<MuteItem> = ev.mute_list ?? Set<MuteItem>() + let old = oldlist.map({ ev in Set(ev.referenced_pubkeys) }) ?? Set<Pubkey>() + let new = Set(ev.referenced_pubkeys) let diff = old.symmetricDifference(new) - var new_mutes = Set<MuteItem>() - var new_unmutes = Set<MuteItem>() + var new_mutes = Set<Pubkey>() + var new_unmutes = Set<Pubkey>() for d in diff { if new.contains(d) { @@ -47,7 +47,7 @@ class Contacts { } // TODO: set local mutelist here - self.muted = ev.mute_list ?? Set<MuteItem>() + self.muted = Set(ev.referenced_pubkeys) if new_mutes.count > 0 { notify(.new_mutes(new_mutes)) diff --git a/damus/Models/HomeModel.swift b/damus/Models/HomeModel.swift @@ -278,11 +278,11 @@ class HomeModel { func filter_events() { events.filter { ev in - !damus_state.contacts.is_muted(.user(ev.pubkey, nil)) + !damus_state.contacts.is_muted(ev.pubkey) } self.dms.dms = dms.dms.filter { ev in - !damus_state.contacts.is_muted(.user(ev.pubkey, nil)) + !damus_state.contacts.is_muted(ev.pubkey) } notifications.filter { ev in @@ -290,8 +290,7 @@ class HomeModel { return false } - let event_muted = damus_state.contacts.mutelist?.mute_list?.event_muted_reason(ev) != nil - return !event_muted + return !damus_state.contacts.is_muted(ev.pubkey) && !damus_state.muted_threads.isMutedThread(ev, keypair: damus_state.keypair) } } @@ -1094,8 +1093,11 @@ func should_show_event(event: NostrEvent, damus_state: DamusState) -> Bool { } func should_show_event(keypair: Keypair, hellthreads: MutedThreadsManager, contacts: Contacts, ev: NostrEvent) -> Bool { - let event_muted = contacts.mutelist?.mute_list?.event_muted_reason(ev) != nil - if event_muted { + if contacts.is_muted(ev.pubkey) { + return false + } + + if hellthreads.isMutedThread(ev, keypair: keypair) { return false } diff --git a/damus/Models/NotificationsManager.swift b/damus/Models/NotificationsManager.swift @@ -36,11 +36,16 @@ func should_display_notification(state: HeadlessDamusState, event ev: NostrEvent return false } - // Don't show notifications that match mute list. - if state.contacts.mutelist?.mute_list?.event_muted_reason(ev) != nil { + // Don't show notifications from muted threads. + if state.muted_threads.isMutedThread(ev, keypair: state.keypair) { return false } - + + // Don't show notifications from muted users + if state.contacts.is_muted(ev.pubkey) { + return false + } + // Don't show notifications for old events guard ev.age < EVENT_MAX_AGE_FOR_NOTIFICATION else { return false diff --git a/damus/Notify/MuteNotify.swift b/damus/Notify/MuteNotify.swift @@ -8,8 +8,8 @@ import Foundation struct MuteNotify: Notify { - typealias Payload = MuteItem - var payload: MuteItem + typealias Payload = Pubkey + var payload: Payload } extension NotifyHandler { @@ -19,7 +19,7 @@ extension NotifyHandler { } extension Notifications { - static func mute(_ target: MuteItem) -> Notifications<MuteNotify> { + static func mute(_ target: Pubkey) -> Notifications<MuteNotify> { .init(.init(payload: target)) } } diff --git a/damus/Notify/NewMutesNotify.swift b/damus/Notify/NewMutesNotify.swift @@ -8,7 +8,7 @@ import Foundation struct NewMutesNotify: Notify { - typealias Payload = Set<MuteItem> + typealias Payload = Set<Pubkey> var payload: Payload } @@ -19,7 +19,7 @@ extension NotifyHandler { } extension Notifications { - static func new_mutes(_ pubkeys: Set<MuteItem>) -> Notifications<NewMutesNotify> { + static func new_mutes(_ pubkeys: Set<Pubkey>) -> Notifications<NewMutesNotify> { .init(.init(payload: pubkeys)) } } diff --git a/damus/Notify/NewUnmutesNotify.swift b/damus/Notify/NewUnmutesNotify.swift @@ -8,7 +8,7 @@ import Foundation struct NewUnmutesNotify: Notify { - typealias Payload = Set<MuteItem> + typealias Payload = Set<Pubkey> var payload: Payload } @@ -19,7 +19,7 @@ extension NotifyHandler { } extension Notifications { - static func new_unmutes(_ pubkeys: Set<MuteItem>) -> Notifications<NewUnmutesNotify> { + static func new_unmutes(_ pubkeys: Set<Pubkey>) -> Notifications<NewUnmutesNotify> { .init(.init(payload: pubkeys)) } } diff --git a/damus/Views/DirectMessagesView.swift b/damus/Views/DirectMessagesView.swift @@ -39,7 +39,7 @@ struct DirectMessagesView: View { func filter_dms(dms: [DirectMessageModel]) -> [DirectMessageModel] { return dms.filter({ dm in - return damus_state.settings.friend_filter.filter(contacts: damus_state.contacts, pubkey: dm.pubkey) && !damus_state.contacts.is_muted(.user(dm.pubkey, nil)) + return damus_state.settings.friend_filter.filter(contacts: damus_state.contacts, pubkey: dm.pubkey) && !damus_state.contacts.is_muted(dm.pubkey) }) } diff --git a/damus/Views/Events/EventMenu.swift b/damus/Views/Events/EventMenu.swift @@ -142,7 +142,7 @@ struct MenuItems: View { } Button(role: .destructive) { - notify(.mute(.user(target_pubkey, nil))) + notify(.mute(target_pubkey)) } label: { Label(NSLocalizedString("Mute user", comment: "Context menu option for muting users."), image: "mute") } diff --git a/damus/Views/Events/EventMutingContainerView.swift b/damus/Views/Events/EventMutingContainerView.swift @@ -49,13 +49,12 @@ struct EventMutingContainerView<Content: View>: View { } } .onReceive(handle_notify(.new_mutes)) { mutes in - let new_muted_event_reason = mutes.event_muted_reason(event) - if new_muted_event_reason != nil { + if mutes.contains(event.pubkey) { shown = false } } .onReceive(handle_notify(.new_unmutes)) { unmutes in - if unmutes.event_muted_reason(event) != nil { + if unmutes.contains(event.pubkey) { shown = true } } diff --git a/damus/Views/Profile/ProfileView.swift b/damus/Views/Profile/ProfileView.swift @@ -179,7 +179,7 @@ struct ProfileView: View { notify(.report(.user(profile.pubkey))) } - if damus_state.contacts.is_muted(.user(profile.pubkey, nil)) { + if damus_state.contacts.is_muted(profile.pubkey) { Button(NSLocalizedString("Unmute", comment: "Button to unmute a profile.")) { guard let keypair = damus_state.keypair.to_full(), @@ -197,7 +197,7 @@ struct ProfileView: View { } } else { Button(NSLocalizedString("Mute", comment: "Button to mute a profile."), role: .destructive) { - notify(.mute(.user(profile.pubkey, nil))) + notify(.mute(profile.pubkey)) } } }