Fix broken notifications

This commit is contained in:
William Casarin
2023-04-15 13:42:10 -07:00
parent 8733a34933
commit ebba9d3004
2 changed files with 24 additions and 19 deletions

View File

@@ -197,9 +197,18 @@ class HomeModel: ObservableObject {
}
func filter_muted() {
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.pubkey) }
notifications.filter_and_build_notifications(damus_state)
events.filter { ev in
!damus_state.contacts.is_muted(ev.pubkey)
}
self.dms.dms = dms.dms.filter { ev in
!damus_state.contacts.is_muted(ev.pubkey)
}
notifications.filter { ev in
!damus_state.contacts.is_muted(ev.pubkey) &&
!damus_state.muted_threads.isMutedThread(ev, privkey: damus_state.keypair.privkey)
}
}
func handle_delete_event(_ ev: NostrEvent) {
@@ -466,11 +475,12 @@ class HomeModel: ObservableObject {
return
}
guard should_show_event(contacts: damus_state.contacts, ev: ev) else {
guard should_show_event(contacts: damus_state.contacts, ev: ev) && !damus_state.muted_threads.isMutedThread(ev, privkey: damus_state.keypair.privkey) else {
return
}
damus_state.events.insert(ev)
if let inner_ev = ev.inner_event {
damus_state.events.insert(inner_ev)
}

View File

@@ -239,7 +239,7 @@ class NotificationsModel: ObservableObject, ScrollQueue {
}
if insert_event_immediate(ev) {
filter_and_build_notifications(damus_state)
self.notifications = build_notifications()
return true
}
@@ -252,47 +252,47 @@ class NotificationsModel: ObservableObject, ScrollQueue {
}
if insert_zap_immediate(zap) {
filter_and_build_notifications(damus_state)
self.notifications = build_notifications()
return true
}
return false
}
func filter_and_build_notifications(_ damus_state: DamusState) {
func filter(_ isIncluded: (NostrEvent) -> Bool) {
var changed = false
var count = 0
count = incoming_events.count
incoming_events = incoming_events.filter { include_event($0, damus_state: damus_state) }
incoming_events = incoming_events.filter(isIncluded)
changed = changed || incoming_events.count != count
count = profile_zaps.zaps.count
profile_zaps.zaps = profile_zaps.zaps.filter { zap in include_event(zap.request.ev, damus_state: damus_state) }
profile_zaps.zaps = profile_zaps.zaps.filter { zap in isIncluded(zap.request.ev) }
changed = changed || profile_zaps.zaps.count != count
for el in reactions {
count = el.value.events.count
el.value.events = el.value.events.filter { include_event($0, damus_state: damus_state) }
el.value.events = el.value.events.filter(isIncluded)
changed = changed || el.value.events.count != count
}
for el in reposts {
count = el.value.events.count
el.value.events = el.value.events.filter { include_event($0, damus_state: damus_state) }
el.value.events = el.value.events.filter(isIncluded)
changed = changed || el.value.events.count != count
}
for el in zaps {
count = el.value.zaps.count
el.value.zaps = el.value.zaps.filter {
include_event($0.request.ev, damus_state: damus_state)
isIncluded($0.request.ev)
}
changed = changed || el.value.zaps.count != count
}
count = replies.count
replies = replies.filter { include_event($0, damus_state: damus_state) }
replies = replies.filter(isIncluded)
changed = changed || replies.count != count
if changed {
@@ -312,14 +312,9 @@ class NotificationsModel: ObservableObject, ScrollQueue {
}
if inserted {
filter_and_build_notifications(damus_state)
self.notifications = build_notifications()
}
return inserted
}
func include_event(_ event: NostrEvent, damus_state: DamusState) -> Bool {
let privkey = damus_state.keypair.privkey
return should_show_event(contacts: damus_state.contacts, ev: event) && !damus_state.muted_threads.isMutedThread(event, privkey: privkey)
}
}