commit b917b4e9d6cc877a41eb636e2e77f7f03cd2c5c5
parent e981ae247e882866f04bffef2ae865ddb6281ff7
Author: Daniel D’Aquino <daniel@daquino.me>
Date: Tue, 7 May 2024 04:31:47 +0000
Apply mute rules to Timeline views by default
Mute rules were not applied in all timeline views. This commit adds code
to filter out muted events on timelines. It also provides an opt-out
parameter if there is ever a need to a timeline without mute filters
Testing
--------
PASS
Device: iPhone 13 Mini
iOS: 17.4.1
Damus: This commit
Coverage:
1. Add a muted keyword
2. Go to home view, check that events with that keyword are now not showing up
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/damus/Views/Timeline/InnerTimelineView.swift b/damus/Views/Timeline/InnerTimelineView.swift
@@ -13,10 +13,10 @@ struct InnerTimelineView: View {
let state: DamusState
let filter: (NostrEvent) -> Bool
- init(events: EventHolder, damus: DamusState, filter: @escaping (NostrEvent) -> Bool) {
+ init(events: EventHolder, damus: DamusState, filter: @escaping (NostrEvent) -> Bool, apply_mute_rules: Bool = true) {
self.events = events
self.state = damus
- self.filter = filter
+ self.filter = apply_mute_rules ? { filter($0) && !damus.mutelist_manager.is_event_muted($0) } : filter
}
var event_options: EventViewOptions {
diff --git a/damus/Views/TimelineView.swift b/damus/Views/TimelineView.swift
@@ -16,13 +16,15 @@ struct TimelineView<Content: View>: View {
let filter: (NostrEvent) -> Bool
let content: Content?
let debouncer: Debouncer
+ let apply_mute_rules: Bool
- init(events: EventHolder, loading: Binding<Bool>, damus: DamusState, show_friend_icon: Bool, filter: @escaping (NostrEvent) -> Bool, content: (() -> Content)? = nil) {
+ init(events: EventHolder, loading: Binding<Bool>, damus: DamusState, show_friend_icon: Bool, filter: @escaping (NostrEvent) -> Bool, apply_mute_rules: Bool = true, content: (() -> Content)? = nil) {
self.events = events
self._loading = loading
self.damus = damus
self.show_friend_icon = show_friend_icon
self.filter = filter
+ self.apply_mute_rules = apply_mute_rules
self.debouncer = Debouncer(interval: 0.5)
self.content = content?()
}
@@ -42,7 +44,7 @@ struct TimelineView<Content: View>: View {
.id("startblock")
.frame(height: 1)
- InnerTimelineView(events: events, damus: damus, filter: loading ? { _ in true } : filter)
+ InnerTimelineView(events: events, damus: damus, filter: loading ? { _ in true } : filter, apply_mute_rules: self.apply_mute_rules)
.redacted(reason: loading ? .placeholder : [])
.shimmer(loading)
.disabled(loading)