Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions damus/Features/Events/EventMutingContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ struct EventMutingContainerView<Content: View>: View {
self.damus_state = damus_state
self.event = event
self.content = content()
self._shown = State(initialValue: should_show_event(state: damus_state, ev: event))
let initial_shown = should_show_event(state: damus_state, ev: event)
let initial_reason = damus_state.mutelist_manager.event_muted_reason(event)
self._shown = State(initialValue: initial_shown)
self._muted_reason = State(initialValue: initial_reason)
}

init(damus_state: DamusState, event: NostrEvent, muteBox: @escaping MuteBoxViewClosure, @ViewBuilder content: () -> Content) {
Expand All @@ -38,18 +41,40 @@ struct EventMutingContainerView<Content: View>: View {
var should_mute: Bool {
return !should_show_event(state: damus_state, ev: event)
}

var current_muted_reason: MuteItem? {
if let muted_reason {
return muted_reason
}
return damus_state.mutelist_manager.event_muted_reason(event)
}

var should_show_mute_box: Bool {
guard should_mute else {
return false
}
guard let reason = current_muted_reason else {
return true
}
if case .user = reason {
// Skip placeholders for people the user has muted entirely.
return false
}
return true
}

var body: some View {
Group {
if should_mute {
if should_show_mute_box {
let reason = current_muted_reason
if let customMuteBox {
customMuteBox($shown, muted_reason)
customMuteBox($shown, reason)
}
else {
EventMutedBoxView(shown: $shown, reason: muted_reason)
EventMutedBoxView(shown: $shown, reason: reason)
}
}
if shown {
if shown || !should_mute {
self.content
}
}
Expand All @@ -61,9 +86,12 @@ struct EventMutingContainerView<Content: View>: View {
}
}
.onReceive(handle_notify(.new_unmutes)) { unmutes in
if damus_state.mutelist_manager.event_muted_reason(event) != nil {
let latest_reason = damus_state.mutelist_manager.event_muted_reason(event)
if latest_reason == nil {
shown = true
muted_reason = nil
} else {
muted_reason = latest_reason
}
}
}
Expand Down