Add Friends filter to DMs
Changelog-Added: Add friends filter to DMs
This commit is contained in:
@@ -182,7 +182,7 @@ struct ContentView: View {
|
|||||||
NotificationsView(state: damus, notifications: home.notifications)
|
NotificationsView(state: damus, notifications: home.notifications)
|
||||||
|
|
||||||
case .dms:
|
case .dms:
|
||||||
DirectMessagesView(damus_state: damus_state!, model: damus_state!.dms)
|
DirectMessagesView(damus_state: damus_state!, model: damus_state!.dms, settings: damus_state!.settings)
|
||||||
|
|
||||||
case .none:
|
case .none:
|
||||||
EmptyView()
|
EmptyView()
|
||||||
|
|||||||
@@ -8,13 +8,18 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct FriendsButton: View {
|
struct FriendsButton: View {
|
||||||
@Binding var enabled: Bool
|
@Binding var filter: FriendFilter
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Button(action: {
|
Button(action: {
|
||||||
self.enabled.toggle()
|
switch self.filter {
|
||||||
|
case .all:
|
||||||
|
self.filter = .friends
|
||||||
|
case .friends:
|
||||||
|
self.filter = .all
|
||||||
|
}
|
||||||
}) {
|
}) {
|
||||||
if enabled {
|
if filter == .friends {
|
||||||
LINEAR_GRADIENT
|
LINEAR_GRADIENT
|
||||||
.mask(Image(systemName: "person.2.fill")
|
.mask(Image(systemName: "person.2.fill")
|
||||||
.resizable()
|
.resizable()
|
||||||
@@ -31,9 +36,9 @@ struct FriendsButton: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct FriendsButton_Previews: PreviewProvider {
|
struct FriendsButton_Previews: PreviewProvider {
|
||||||
@State static var enabled: Bool = false
|
@State static var enabled: FriendFilter = .all
|
||||||
|
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
FriendsButton(enabled: $enabled)
|
FriendsButton(filter: $enabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ struct DirectMessagesView: View {
|
|||||||
|
|
||||||
@State var dm_type: DMType = .friend
|
@State var dm_type: DMType = .friend
|
||||||
@ObservedObject var model: DirectMessagesModel
|
@ObservedObject var model: DirectMessagesModel
|
||||||
|
@ObservedObject var settings: UserSettingsStore
|
||||||
|
|
||||||
func MainContent(requests: Bool) -> some View {
|
func MainContent(requests: Bool) -> some View {
|
||||||
ScrollView {
|
ScrollView {
|
||||||
@@ -29,12 +30,9 @@ struct DirectMessagesView: View {
|
|||||||
EmptyTimelineView()
|
EmptyTimelineView()
|
||||||
} else {
|
} else {
|
||||||
let dms = requests ? model.message_requests : model.friend_dms
|
let dms = requests ? model.message_requests : model.friend_dms
|
||||||
ForEach(dms, id: \.pubkey) { tup in
|
ForEach(dms, id: \.pubkey) { dm in
|
||||||
MaybeEvent(tup)
|
MaybeEvent(dm)
|
||||||
.padding(.top, 10)
|
.padding(.top, 10)
|
||||||
|
|
||||||
Divider()
|
|
||||||
.padding([.top], 10)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,11 +50,15 @@ struct DirectMessagesView: View {
|
|||||||
|
|
||||||
func MaybeEvent(_ model: DirectMessageModel) -> some View {
|
func MaybeEvent(_ model: DirectMessageModel) -> some View {
|
||||||
Group {
|
Group {
|
||||||
if let ev = model.events.last {
|
let ok = damus_state.settings.friend_filter.filter(contacts: damus_state.contacts, pubkey: model.pubkey)
|
||||||
|
if ok, let ev = model.events.last {
|
||||||
EventView(damus: damus_state, event: ev, pubkey: model.pubkey, options: options)
|
EventView(damus: damus_state, event: ev, pubkey: model.pubkey, options: options)
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
self.model.open_dm_by_model(model)
|
self.model.open_dm_by_model(model)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Divider()
|
||||||
|
.padding([.top], 10)
|
||||||
} else {
|
} else {
|
||||||
EmptyView()
|
EmptyView()
|
||||||
}
|
}
|
||||||
@@ -84,10 +86,28 @@ struct DirectMessagesView: View {
|
|||||||
}
|
}
|
||||||
.tabViewStyle(.page(indexDisplayMode: .never))
|
.tabViewStyle(.page(indexDisplayMode: .never))
|
||||||
}
|
}
|
||||||
|
.toolbar {
|
||||||
|
ToolbarItem(placement: .navigationBarTrailing) {
|
||||||
|
if would_filter_non_friends_from_dms(contacts: damus_state.contacts, dms: self.model.dms) {
|
||||||
|
|
||||||
|
FriendsButton(filter: $settings.friend_filter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
.navigationTitle(NSLocalizedString("DMs", comment: "Navigation title for view of DMs, where DM is an English abbreviation for Direct Message."))
|
.navigationTitle(NSLocalizedString("DMs", comment: "Navigation title for view of DMs, where DM is an English abbreviation for Direct Message."))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func would_filter_non_friends_from_dms(contacts: Contacts, dms: [DirectMessageModel]) -> Bool {
|
||||||
|
for dm in dms {
|
||||||
|
if !FriendFilter.friends.filter(contacts: contacts, pubkey: dm.pubkey) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
struct DirectMessagesView_Previews: PreviewProvider {
|
struct DirectMessagesView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let ev = NostrEvent(content: "encrypted stuff",
|
let ev = NostrEvent(content: "encrypted stuff",
|
||||||
@@ -95,6 +115,6 @@ struct DirectMessagesView_Previews: PreviewProvider {
|
|||||||
kind: 4,
|
kind: 4,
|
||||||
tags: [])
|
tags: [])
|
||||||
let ds = test_damus_state()
|
let ds = test_damus_state()
|
||||||
DirectMessagesView(damus_state: ds, model: ds.dms)
|
DirectMessagesView(damus_state: ds, model: ds.dms, settings: ds.settings)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,14 +60,6 @@ class NotificationFilter: ObservableObject, Equatable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var fine_filter_binding: Binding<Bool> {
|
|
||||||
Binding(get: {
|
|
||||||
return self.fine_filter == .friends
|
|
||||||
}, set: { v in
|
|
||||||
self.fine_filter = v ? .friends : .all
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func filter(contacts: Contacts, items: [NotificationItem]) -> [NotificationItem] {
|
func filter(contacts: Contacts, items: [NotificationItem]) -> [NotificationItem] {
|
||||||
|
|
||||||
return items.reduce(into: []) { acc, item in
|
return items.reduce(into: []) { acc, item in
|
||||||
@@ -162,7 +154,7 @@ struct NotificationsView: View {
|
|||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItem(placement: .navigationBarTrailing) {
|
ToolbarItem(placement: .navigationBarTrailing) {
|
||||||
if would_filter_non_friends_from_notifications(contacts: state.contacts, state: self.filter_state.state, items: self.notifications.notifications) {
|
if would_filter_non_friends_from_notifications(contacts: state.contacts, state: self.filter_state.state, items: self.notifications.notifications) {
|
||||||
FriendsButton(enabled: self.filter_state.fine_filter_binding)
|
FriendsButton(filter: $filter_state.fine_filter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user