Add thread muting

Changelog-Added: Add thread muting
Closes: #893
This commit is contained in:
2023-04-08 14:44:50 -04:00
committed by William Casarin
parent d5ecc9bce4
commit 1ac9620242
15 changed files with 163 additions and 31 deletions

View File

@@ -52,12 +52,14 @@ class HomeModel: ObservableObject {
init() {
self.damus_state = DamusState.empty
self.dms = DirectMessagesModel(our_pubkey: "")
filter_muted()
}
init(damus_state: DamusState) {
self.damus_state = damus_state
self.dms = DirectMessagesModel(our_pubkey: damus_state.pubkey)
self.setup_debouncer()
filter_muted()
}
var pool: RelayPool {
@@ -134,7 +136,7 @@ class HomeModel: ObservableObject {
return
}
if !notifications.insert_zap(zap) {
if !notifications.insert_zap(zap, damus_state: damus_state) {
return
}
@@ -197,9 +199,9 @@ class HomeModel: ObservableObject {
}
func filter_muted() {
events.filter { !damus_state.contacts.is_muted($0.pubkey) }
events.filter { !damus_state.contacts.is_muted($0.pubkey) && !damus_state.muted_threads.isMutedThread($0) }
self.dms.dms = dms.dms.filter { !damus_state.contacts.is_muted($0.0) }
notifications.filter { !damus_state.contacts.is_muted($0.pubkey) }
notifications.filter_and_build_notifications(damus_state)
}
func handle_delete_event(_ ev: NostrEvent) {
@@ -478,7 +480,7 @@ class HomeModel: ObservableObject {
damus_state.events.insert(inner_ev)
}
if !notifications.insert_event(ev) {
if !notifications.insert_event(ev, damus_state: damus_state) {
return
}
@@ -1044,6 +1046,11 @@ func process_local_notification(damus_state: DamusState, event ev: NostrEvent) {
return
}
// Don't show notifications from muted threads.
if damus_state.muted_threads.isMutedThread(ev) {
return
}
if type == .text && damus_state.settings.mention_notification {
for block in ev.blocks(damus_state.keypair.privkey) {
if case .mention(let mention) = block, mention.ref.ref_id == damus_state.keypair.pubkey,