Add notification setting to hide hellthreads

Changelog-Added: Add notification setting to hide hellthreads
Closes: https://github.com/damus-io/damus/issues/2943
Signed-off-by: Terry Yiu <git@tyiu.xyz>
This commit is contained in:
2025-03-29 10:21:19 -04:00
committed by Daniel D’Aquino
parent d1cced8d54
commit c146bab08a
11 changed files with 147 additions and 95 deletions

View File

@@ -9,15 +9,17 @@ import SwiftUI
class NotificationFilter: ObservableObject, Equatable {
@Published var state: NotificationFilterState
@Published var fine_filter: FriendFilter
@Published var friend_filter: FriendFilter
@Published var show_hellthreads: Bool = false
static func == (lhs: NotificationFilter, rhs: NotificationFilter) -> Bool {
return lhs.state == rhs.state && lhs.fine_filter == rhs.fine_filter
return lhs.state == rhs.state && lhs.friend_filter == rhs.friend_filter && lhs.show_hellthreads == rhs.show_hellthreads
}
init(state: NotificationFilterState = .all, fine_filter: FriendFilter = .all) {
init(state: NotificationFilterState = .all, friend_filter: FriendFilter = .all, show_hellthreads: Bool = false) {
self.state = state
self.fine_filter = fine_filter
self.friend_filter = friend_filter
self.show_hellthreads = show_hellthreads
}
func filter(contacts: Contacts, items: [NotificationItem]) -> [NotificationItem] {
@@ -26,8 +28,11 @@ class NotificationFilter: ObservableObject, Equatable {
if !self.state.filter(item) {
return
}
if let item = item.filter({ self.fine_filter.filter(contacts: contacts, pubkey: $0.pubkey) }) {
if let item = item.filter({ ev in
self.friend_filter.filter(contacts: contacts, pubkey: ev.pubkey) &&
(show_hellthreads || !ev.is_hellthread)
}) {
acc.append(item)
}
}
@@ -65,7 +70,8 @@ struct NotificationsView: View {
NotificationTab(
NotificationFilter(
state: .all,
fine_filter: filter.fine_filter
friend_filter: filter.friend_filter,
show_hellthreads: state.settings.hellthread_notification
)
)
.tag(NotificationFilterState.all)
@@ -73,7 +79,8 @@ struct NotificationsView: View {
NotificationTab(
NotificationFilter(
state: .zaps,
fine_filter: filter.fine_filter
friend_filter: filter.friend_filter,
show_hellthreads: state.settings.hellthread_notification
)
)
.tag(NotificationFilterState.zaps)
@@ -81,7 +88,8 @@ struct NotificationsView: View {
NotificationTab(
NotificationFilter(
state: .replies,
fine_filter: filter.fine_filter
friend_filter: filter.friend_filter,
show_hellthreads: state.settings.hellthread_notification
)
)
.tag(NotificationFilterState.replies)
@@ -98,20 +106,20 @@ struct NotificationsView: View {
}
ToolbarItem(placement: .navigationBarTrailing) {
if would_filter_non_friends_from_notifications(contacts: state.contacts, state: filter_state, items: self.notifications.notifications) {
FriendsButton(filter: $filter.fine_filter)
FriendsButton(filter: $filter.friend_filter)
}
}
}
.onChange(of: filter.fine_filter) { val in
.onChange(of: filter.friend_filter) { val in
state.settings.friend_filter = val
self.subtitle = filter.fine_filter.description()
self.subtitle = filter.friend_filter.description()
}
.onChange(of: filter_state) { val in
filter.state = val
}
.onAppear {
self.filter.fine_filter = state.settings.friend_filter
self.subtitle = filter.fine_filter.description()
self.filter.friend_filter = state.settings.friend_filter
self.subtitle = filter.friend_filter.description()
filter.state = filter_state
}
.safeAreaInset(edge: .top, spacing: 0) {