mirror of https://github.com/lukechilds/damus.git
Browse Source
- Filter muted posts from feed on mute - List muted users in sidebar Changelog-Added: Added ability to block userszaps
14 changed files with 349 additions and 39 deletions
@ -0,0 +1,42 @@ |
|||
// |
|||
// UserView.swift |
|||
// damus |
|||
// |
|||
// Created by William Casarin on 2023-01-25. |
|||
// |
|||
|
|||
import SwiftUI |
|||
|
|||
struct UserView: View { |
|||
let damus_state: DamusState |
|||
let pubkey: String |
|||
|
|||
var body: some View { |
|||
let pmodel = ProfileModel(pubkey: pubkey, damus: damus_state) |
|||
let followers = FollowersModel(damus_state: damus_state, target: pubkey) |
|||
let pv = ProfileView(damus_state: damus_state, profile: pmodel, followers: followers) |
|||
|
|||
NavigationLink(destination: pv) { |
|||
ProfilePicView(pubkey: pubkey, size: PFP_SIZE, highlight: .none, profiles: damus_state.profiles) |
|||
|
|||
VStack(alignment: .leading) { |
|||
let profile = damus_state.profiles.lookup(id: pubkey) |
|||
ProfileName(pubkey: pubkey, profile: profile, damus: damus_state, show_friend_confirmed: false, show_nip5_domain: false) |
|||
if let about = profile?.about { |
|||
Text(about) |
|||
.lineLimit(3) |
|||
.font(.footnote) |
|||
} |
|||
} |
|||
|
|||
Spacer() |
|||
} |
|||
.buttonStyle(PlainButtonStyle()) |
|||
} |
|||
} |
|||
|
|||
struct UserView_Previews: PreviewProvider { |
|||
static var previews: some View { |
|||
UserView(damus_state: test_damus_state(), pubkey: "pk") |
|||
} |
|||
} |
@ -0,0 +1,18 @@ |
|||
// |
|||
// ListModel.swift |
|||
// damus |
|||
// |
|||
// Created by William Casarin on 2023-01-25. |
|||
// |
|||
|
|||
import Foundation |
|||
|
|||
|
|||
/* |
|||
class MutelistModel: ObservableObject { |
|||
let contacts: Contacts |
|||
|
|||
@Published var users: [String] |
|||
|
|||
} |
|||
*/ |
@ -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"]) |
|||
} |
|||
} |
Loading…
Reference in new issue