commit 66d731ad0a6d1a54acaa5cf069d2402fbe1e036b
parent 0f86a41c4a5cae6eb431c2fd4c1343e1e4b10982
Author: Daniel D’Aquino <daniel@daquino.me>
Date: Sat, 30 Sep 2023 03:17:16 +0000
ui: Filter out reposts where the inner event is from a person whom the user has muted. (#1216)
Issue reproduction
------------------
**Device:** iPhone 14 Pro simulator
**iOS:** 17.0
**Damus:** `bb2eb904cc`
**Steps:**
1. Repost a note from another account (Account "B")
2. Mute user "B"
3. Check home page and your own profile page. Repost shows up with a muted box.
Fix
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
4 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/damus/ContentView.swift b/damus/ContentView.swift
@@ -88,7 +88,7 @@ struct ContentView: View {
}
func content_filter(_ fstate: FilterState) -> ((NostrEvent) -> Bool) {
- var filters = ContentFilters.defaults(damus_state!.settings)
+ var filters = ContentFilters.defaults(damus_state: damus_state!)
filters.append(fstate.filter)
return ContentFilters(filters: filters).filter
}
diff --git a/damus/Models/ContentFilters.swift b/damus/Models/ContentFilters.swift
@@ -25,7 +25,15 @@ enum FilterState : Int {
/// Simple filter to determine whether to show posts with #nsfw tags
func nsfw_tag_filter(ev: NostrEvent) -> Bool {
- return ev.referenced_hashtags.first(where: { t in t.hashtag == "nsfw" }) == nil
+ return ev.referenced_hashtags.first(where: { t in t.hashtag == "nsfw" }) == nil
+}
+
+func get_repost_of_muted_user_filter(damus_state: DamusState) -> ((_ ev: NostrEvent) -> Bool) {
+ return { ev in
+ guard ev.known_kind == .boost else { return true }
+ guard let inner_ev = ev.get_inner_event(cache: damus_state.events) else { return true }
+ return should_show_event(keypair: damus_state.keypair, hellthreads: damus_state.muted_threads, contacts: damus_state.contacts, ev: inner_ev)
+ }
}
/// Generic filter with various tweakable settings
@@ -44,11 +52,12 @@ struct ContentFilters {
}
extension ContentFilters {
- static func defaults(_ settings: UserSettingsStore) -> [(NostrEvent) -> Bool] {
+ static func defaults(damus_state: DamusState) -> [(NostrEvent) -> Bool] {
var filters = Array<(NostrEvent) -> Bool>()
- if settings.hide_nsfw_tagged_content {
+ if damus_state.settings.hide_nsfw_tagged_content {
filters.append(nsfw_tag_filter)
}
+ filters.append(get_repost_of_muted_user_filter(damus_state: damus_state))
return filters
}
}
diff --git a/damus/Views/Profile/ProfileView.swift b/damus/Views/Profile/ProfileView.swift
@@ -108,6 +108,12 @@ struct ProfileView: View {
let progress = -(yOffset + navbarHeight) / 100
return Double(-yOffset > navbarHeight ? progress : 0)
}
+
+ func content_filter(_ fstate: FilterState) -> ((NostrEvent) -> Bool) {
+ var filters = ContentFilters.defaults(damus_state: damus_state)
+ filters.append(fstate.filter)
+ return ContentFilters(filters: filters).filter
+ }
var bannerSection: some View {
GeometryReader { proxy -> AnyView in
@@ -458,10 +464,10 @@ struct ProfileView: View {
.background(colorScheme == .dark ? Color.black : Color.white)
if filter_state == FilterState.posts {
- InnerTimelineView(events: profile.events, damus: damus_state, filter: FilterState.posts.filter)
+ InnerTimelineView(events: profile.events, damus: damus_state, filter: content_filter(FilterState.posts))
}
if filter_state == FilterState.posts_and_replies {
- InnerTimelineView(events: profile.events, damus: damus_state, filter: FilterState.posts_and_replies.filter)
+ InnerTimelineView(events: profile.events, damus: damus_state, filter: content_filter(FilterState.posts_and_replies))
}
}
.padding(.horizontal, Theme.safeAreaInsets?.left)
diff --git a/damus/Views/SearchHomeView.swift b/damus/Views/SearchHomeView.swift
@@ -16,7 +16,7 @@ struct SearchHomeView: View {
@FocusState private var isFocused: Bool
var content_filter: (NostrEvent) -> Bool {
- let filters = ContentFilters.defaults(self.damus_state.settings)
+ let filters = ContentFilters.defaults(damus_state: self.damus_state)
return ContentFilters(filters: filters).filter
}