Add muting and mutelists
- Filter muted posts from feed on mute - List muted users in sidebar Changelog-Added: Added ability to block users
This commit is contained in:
@@ -44,6 +44,12 @@ struct EventMenuContext: View {
|
||||
} label: {
|
||||
Label(NSLocalizedString("Report", comment: "Context menu option for reporting content."), systemImage: "exclamationmark.bubble")
|
||||
}
|
||||
|
||||
Button {
|
||||
notify(.block, event.pubkey)
|
||||
} label: {
|
||||
Label(NSLocalizedString("Block", comment: "Context menu option for blocking users."), systemImage: "exclamationmark.octagon")
|
||||
}
|
||||
|
||||
Button {
|
||||
NotificationCenter.default.post(name: .broadcast_event, object: event)
|
||||
|
||||
@@ -15,26 +15,7 @@ struct FollowUserView: View {
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
let pmodel = ProfileModel(pubkey: target.pubkey, damus: damus_state)
|
||||
let followers = FollowersModel(damus_state: damus_state, target: target.pubkey)
|
||||
let pv = ProfileView(damus_state: damus_state, profile: pmodel, followers: followers)
|
||||
|
||||
NavigationLink(destination: pv) {
|
||||
ProfilePicView(pubkey: target.pubkey, size: PFP_SIZE, highlight: .none, profiles: damus_state.profiles)
|
||||
|
||||
VStack(alignment: .leading) {
|
||||
let profile = damus_state.profiles.lookup(id: target.pubkey)
|
||||
ProfileName(pubkey: target.pubkey, profile: profile, damus: damus_state, show_friend_confirmed: false, show_nip5_domain: false)
|
||||
if let about = profile?.about {
|
||||
Text(FollowUserView.markdown.process(about))
|
||||
.lineLimit(3)
|
||||
.font(.footnote)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.buttonStyle(PlainButtonStyle())
|
||||
UserView(damus_state: damus_state, pubkey: target.pubkey)
|
||||
|
||||
FollowButtonView(target: target, follow_state: damus_state.contacts.follow_state(target.pubkey))
|
||||
}
|
||||
|
||||
67
damus/Views/Muting/MutelistView.swift
Normal file
67
damus/Views/Muting/MutelistView.swift
Normal file
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// MutelistView.swift
|
||||
// damus
|
||||
//
|
||||
// Created by William Casarin on 2023-01-25.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct MutelistView: View {
|
||||
let damus_state: DamusState
|
||||
@State var users: [String]
|
||||
|
||||
func RemoveAction(pubkey: String) -> some View {
|
||||
Button {
|
||||
guard let mutelist = damus_state.contacts.mutelist else {
|
||||
return
|
||||
}
|
||||
|
||||
guard let keypair = damus_state.keypair.to_full() else {
|
||||
return
|
||||
}
|
||||
|
||||
guard let new_ev = remove_from_mutelist(keypair: keypair, prev: mutelist, to_remove: pubkey) else {
|
||||
return
|
||||
}
|
||||
|
||||
damus_state.contacts.set_mutelist(new_ev)
|
||||
damus_state.pool.send(.event(new_ev))
|
||||
users = get_mutelist_users(new_ev)
|
||||
} label: {
|
||||
Label(NSLocalizedString("Delete", comment: "Button to remove a user from their blocklist."), systemImage: "trash")
|
||||
}
|
||||
.tint(.red)
|
||||
}
|
||||
|
||||
|
||||
var body: some View {
|
||||
List(users, id: \.self) { pubkey in
|
||||
UserView(damus_state: damus_state, pubkey: pubkey)
|
||||
.id(pubkey)
|
||||
.swipeActions {
|
||||
RemoveAction(pubkey: pubkey)
|
||||
}
|
||||
}
|
||||
.navigationTitle("Blocked Users")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func get_mutelist_users(_ mlist: NostrEvent?) -> [String] {
|
||||
guard let mutelist = mlist else {
|
||||
return []
|
||||
}
|
||||
|
||||
return mutelist.tags.reduce(into: Array<String>()) { pks, tag in
|
||||
if tag.count >= 2 && tag[0] == "p" {
|
||||
pks.append(tag[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct MutelistView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
MutelistView(damus_state: test_damus_state(), users: [test_event.pubkey, test_event.pubkey+"hi"])
|
||||
}
|
||||
}
|
||||
@@ -383,6 +383,10 @@ struct ProfileView: View {
|
||||
let target: ReportTarget = .user(profile.pubkey)
|
||||
notify(.report, target)
|
||||
}
|
||||
|
||||
Button("Block") {
|
||||
notify(.block, profile.pubkey)
|
||||
}
|
||||
}
|
||||
.ignoresSafeArea()
|
||||
}
|
||||
|
||||
@@ -75,22 +75,6 @@ struct SideMenuView: View {
|
||||
|
||||
Divider()
|
||||
.padding(.trailing,40)
|
||||
|
||||
/*
|
||||
HStack(alignment: .bottom) {
|
||||
Text("69,420")
|
||||
.foregroundColor(.accentColor)
|
||||
.font(.largeTitle)
|
||||
Text("SATS")
|
||||
.font(.caption)
|
||||
.padding(.bottom,6)
|
||||
}
|
||||
|
||||
Divider()
|
||||
.padding(.trailing,40)
|
||||
*/
|
||||
|
||||
// THERE IS A LIMIT OF 10 NAVIGATIONLINKS!!! (Consider some in other views)
|
||||
|
||||
NavigationLink(destination: ProfileView(damus_state: damus_state, profile: profile_model, followers: followers)) {
|
||||
Label(NSLocalizedString("Profile", comment: "Sidebar menu label for Profile view."), systemImage: "person")
|
||||
@@ -123,6 +107,12 @@ struct SideMenuView: View {
|
||||
})
|
||||
*/
|
||||
|
||||
NavigationLink(destination: MutelistView(damus_state: damus_state, users: get_mutelist_users(damus_state.contacts.mutelist) )) {
|
||||
Label(NSLocalizedString("Blocked", comment: "Sidebar menu label for Profile view."), systemImage: "exclamationmark.octagon")
|
||||
.font(.title2)
|
||||
.foregroundColor(textColor())
|
||||
}
|
||||
|
||||
NavigationLink(destination: ConfigView(state: damus_state).environmentObject(user_settings)) {
|
||||
Label(NSLocalizedString("Settings", comment: "Sidebar menu label for accessing the app settings"), systemImage: "gear")
|
||||
.font(.title2)
|
||||
|
||||
Reference in New Issue
Block a user