Skip to content

Commit

Permalink
ui: Filter out reposts where the inner event is from a person whom th…
Browse files Browse the repository at this point in the history
…e 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 <[email protected]>
Signed-off-by: William Casarin <[email protected]>
  • Loading branch information
danieldaquino authored and jb55 committed Oct 1, 2023
1 parent 66310a1 commit a2b7dfe
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion damus/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 12 additions & 3 deletions damus/Models/ContentFilters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
10 changes: 8 additions & 2 deletions damus/Views/Profile/ProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion damus/Views/SearchHomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit a2b7dfe

Please sign in to comment.