Fix broken notifications
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user