Prevent blocking or reporting yourself

This commit is contained in:
2023-01-26 23:34:21 -05:00
parent 51f94cf135
commit 3e02cc6889
7 changed files with 37 additions and 32 deletions

View File

@@ -24,7 +24,7 @@ struct ChatroomView: View {
next_ev: ind == count-1 ? nil : thread.events[ind+1],
damus_state: damus
)
.event_context_menu(ev, pubkey: ev.pubkey, privkey: damus.keypair.privkey)
.event_context_menu(ev, keypair: damus.keypair)
.onTapGesture {
if thread.initial_event.id == ev.id {
//dismiss()

View File

@@ -19,7 +19,7 @@ struct DMChatView: View {
VStack(alignment: .leading) {
ForEach(Array(zip(dms.events, dms.events.indices)), id: \.0.id) { (ev, ind) in
DMView(event: dms.events[ind], damus_state: damus_state)
.event_context_menu(ev, pubkey: ev.pubkey, privkey: damus_state.keypair.privkey)
.event_context_menu(ev, keypair: damus_state.keypair)
}
EndBlock(height: 80)
}

View File

@@ -129,7 +129,7 @@ struct EventView: View {
.id(event.id)
.frame(maxWidth: .infinity, minHeight: PFP_SIZE)
.padding([.bottom], 2)
.event_context_menu(event, pubkey: pubkey, privkey: damus.keypair.privkey)
.event_context_menu(event, keypair: damus.keypair)
}
}
@@ -171,9 +171,9 @@ extension View {
}
}
func event_context_menu(_ event: NostrEvent, pubkey: String, privkey: String?) -> some View {
func event_context_menu(_ event: NostrEvent, keypair: Keypair) -> some View {
return self.contextMenu {
EventMenuContext(event: event, privkey: privkey, pubkey: pubkey)
EventMenuContext(event: event, keypair: keypair)
}
}

View File

@@ -23,7 +23,7 @@ struct EmbeddedEventView: View {
EventBody(damus_state: damus_state, event: event, size: .small)
}
.event_context_menu(event, pubkey: pubkey, privkey: damus_state.keypair.privkey)
.event_context_menu(event, keypair: damus_state.keypair)
}
}

View File

@@ -9,19 +9,18 @@ import SwiftUI
struct EventMenuContext: View {
let event: NostrEvent
let privkey: String?
let pubkey: String
let keypair: Keypair
var body: some View {
Button {
UIPasteboard.general.string = event.get_content(privkey)
UIPasteboard.general.string = event.get_content(keypair.privkey)
} label: {
Label(NSLocalizedString("Copy Text", comment: "Context menu option for copying the text from an note."), systemImage: "doc.on.doc")
}
Button {
UIPasteboard.general.string = bech32_pubkey(pubkey) ?? pubkey
UIPasteboard.general.string = keypair.pubkey_bech32
} label: {
Label(NSLocalizedString("Copy User Pubkey", comment: "Context menu option for copying the ID of the user who created the note."), systemImage: "person")
}
@@ -37,25 +36,28 @@ struct EventMenuContext: View {
} label: {
Label(NSLocalizedString("Copy Note JSON", comment: "Context menu option for copying the JSON text from the note."), systemImage: "square.on.square")
}
Button(role: .destructive) {
let target: ReportTarget = .note(ReportNoteTarget(pubkey: event.pubkey, note_id: event.id))
notify(.report, target)
} label: {
Label(NSLocalizedString("Report", comment: "Context menu option for reporting content."), systemImage: "exclamationmark.bubble")
}
Button(role: .destructive) {
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)
} label: {
Label(NSLocalizedString("Broadcast", comment: "Context menu option for broadcasting the user's note to all of the user's connected relay servers."), systemImage: "globe")
}
// Only allow reporting if logged in with private key and the currently viewed profile is not the logged in profile.
if keypair.pubkey != event.pubkey && keypair.privkey != nil {
Button(role: .destructive) {
let target: ReportTarget = .note(ReportNoteTarget(pubkey: event.pubkey, note_id: event.id))
notify(.report, target)
} label: {
Label(NSLocalizedString("Report", comment: "Context menu option for reporting content."), systemImage: "exclamationmark.bubble")
}
Button(role: .destructive) {
notify(.block, event.pubkey)
} label: {
Label(NSLocalizedString("Block", comment: "Context menu option for blocking users."), systemImage: "exclamationmark.octagon")
}
}
}
}

View File

@@ -49,7 +49,7 @@ struct SelectedEventView: View {
.padding([.top], 4)
}
.padding([.leading], 2)
.event_context_menu(event, pubkey: pubkey, privkey: damus.keypair.privkey)
.event_context_menu(event, keypair: damus.keypair)
}
}
}

View File

@@ -378,14 +378,17 @@ struct ProfileView: View {
Button(NSLocalizedString("Share", comment: "Button to share the link to a profile.")) {
show_share_sheet = true
}
Button(NSLocalizedString("Report", comment: "Button to report a profile."), role: .destructive) {
let target: ReportTarget = .user(profile.pubkey)
notify(.report, target)
}
Button(NSLocalizedString("Block", comment: "Button to block a profile."), role: .destructive) {
notify(.block, profile.pubkey)
// Only allow reporting if logged in with private key and the currently viewed profile is not the logged in profile.
if profile.pubkey != damus_state.pubkey && damus_state.is_privkey_user {
Button(NSLocalizedString("Report", comment: "Button to report a profile."), role: .destructive) {
let target: ReportTarget = .user(profile.pubkey)
notify(.report, target)
}
Button(NSLocalizedString("Block", comment: "Button to block a profile."), role: .destructive) {
notify(.block, profile.pubkey)
}
}
}
.ignoresSafeArea()