[appstore] Report Content
This view provides a way to report content (nudity, illegal, spam) to relays. Clients can use this information to filter or warn if they choose to. This is needed for the appstore release Changelog-Added: Added a way to report content
This commit is contained in:
@@ -100,6 +100,8 @@ struct EventView: View {
|
||||
|
||||
Text("\(format_relative_time(event.created_at))")
|
||||
.foregroundColor(.gray)
|
||||
|
||||
Spacer()
|
||||
}
|
||||
|
||||
EventBody(damus_state: damus, event: event, size: .normal)
|
||||
@@ -171,35 +173,7 @@ extension View {
|
||||
|
||||
func event_context_menu(_ event: NostrEvent, pubkey: String, privkey: String?) -> some View {
|
||||
return self.contextMenu {
|
||||
Button {
|
||||
UIPasteboard.general.string = event.get_content(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
|
||||
} label: {
|
||||
Label(NSLocalizedString("Copy User ID", comment: "Context menu option for copying the ID of the user who created the note."), systemImage: "person")
|
||||
}
|
||||
|
||||
Button {
|
||||
UIPasteboard.general.string = bech32_note_id(event.id) ?? event.id
|
||||
} label: {
|
||||
Label(NSLocalizedString("Copy Note ID", comment: "Context menu option for copying the ID of the note."), systemImage: "note.text")
|
||||
}
|
||||
|
||||
Button {
|
||||
UIPasteboard.general.string = event_to_json(ev: event)
|
||||
} label: {
|
||||
Label(NSLocalizedString("Copy Note JSON", comment: "Context menu option for copying the JSON text from the note."), systemImage: "j.square.on.square")
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
EventMenuContext(event: event, privkey: privkey, pubkey: pubkey)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
93
damus/Views/Events/EventMenu.swift
Normal file
93
damus/Views/Events/EventMenu.swift
Normal file
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// EventMenu.swift
|
||||
// damus
|
||||
//
|
||||
// Created by William Casarin on 2023-01-23.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct EventMenuContext: View {
|
||||
let event: NostrEvent
|
||||
let privkey: String?
|
||||
let pubkey: String
|
||||
|
||||
var body: some View {
|
||||
|
||||
Button {
|
||||
UIPasteboard.general.string = event.get_content(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
|
||||
} label: {
|
||||
Label(NSLocalizedString("Copy User Pubkey", comment: "Context menu option for copying the ID of the user who created the note."), systemImage: "person")
|
||||
}
|
||||
|
||||
Button {
|
||||
UIPasteboard.general.string = bech32_note_id(event.id) ?? event.id
|
||||
} label: {
|
||||
Label(NSLocalizedString("Copy Note ID", comment: "Context menu option for copying the ID of the note."), systemImage: "note.text")
|
||||
}
|
||||
|
||||
Button {
|
||||
UIPasteboard.general.string = event_to_json(ev: event)
|
||||
} label: {
|
||||
Label(NSLocalizedString("Copy Note JSON", comment: "Context menu option for copying the JSON text from the note."), systemImage: "square.on.square")
|
||||
}
|
||||
|
||||
Button {
|
||||
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 {
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
struct EventMenu: UIViewRepresentable {
|
||||
|
||||
typealias UIViewType = UIButton
|
||||
|
||||
let saveAction = UIAction(title: "") { action in }
|
||||
let saveMenu = UIMenu(title: "", children: [
|
||||
UIAction(title: "First Menu Item", image: UIImage(systemName: "nameOfSFSymbol")) { action in
|
||||
//code action for menu item
|
||||
},
|
||||
UIAction(title: "First Menu Item", image: UIImage(systemName: "nameOfSFSymbol")) { action in
|
||||
//code action for menu item
|
||||
},
|
||||
UIAction(title: "First Menu Item", image: UIImage(systemName: "nameOfSFSymbol")) { action in
|
||||
//code action for menu item
|
||||
},
|
||||
])
|
||||
|
||||
func makeUIView(context: Context) -> UIButton {
|
||||
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
|
||||
button.showsMenuAsPrimaryAction = true
|
||||
button.menu = saveMenu
|
||||
|
||||
return button
|
||||
}
|
||||
|
||||
func updateUIView(_ uiView: UIButton, context: Context) {
|
||||
uiView.setImage(UIImage(systemName: "plus"), for: .normal)
|
||||
}
|
||||
}
|
||||
|
||||
struct EventMenu_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
EventMenu(event: test_event, privkey: nil, pubkey: test_event.pubkey)
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
@@ -49,6 +49,7 @@ struct SelectedEventView: View {
|
||||
.padding([.top], 4)
|
||||
}
|
||||
.padding([.leading], 2)
|
||||
.event_context_menu(event, pubkey: pubkey, privkey: damus.keypair.privkey)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
115
damus/Views/ReportView.swift
Normal file
115
damus/Views/ReportView.swift
Normal file
@@ -0,0 +1,115 @@
|
||||
//
|
||||
// ReportView.swift
|
||||
// damus
|
||||
//
|
||||
// Created by William Casarin on 2023-01-25.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ReportView: View {
|
||||
let pool: RelayPool
|
||||
let target: ReportTarget
|
||||
let privkey: String
|
||||
|
||||
@State var report_sent: Bool = false
|
||||
@State var report_id: String = ""
|
||||
|
||||
var body: some View {
|
||||
if report_sent {
|
||||
Success
|
||||
} else {
|
||||
MainForm
|
||||
}
|
||||
}
|
||||
|
||||
var Success: some View {
|
||||
VStack(alignment: .center, spacing: 20) {
|
||||
Text("Report sent!")
|
||||
.font(.headline)
|
||||
|
||||
Text("Relays have been notified and clients will be able to use this information to filter content. Thank you!")
|
||||
|
||||
Text("Report ID:")
|
||||
|
||||
Text(report_id)
|
||||
|
||||
Button("Copy Report ID") {
|
||||
UIPasteboard.general.string = report_id
|
||||
let g = UIImpactFeedbackGenerator(style: .medium)
|
||||
g.impactOccurred()
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
|
||||
func do_send_report(type: ReportType) {
|
||||
guard let ev = send_report(privkey: privkey, pool: pool, target: target, type: .spam) else {
|
||||
return
|
||||
}
|
||||
|
||||
guard let note_id = bech32_note_id(ev.id) else {
|
||||
return
|
||||
}
|
||||
|
||||
report_sent = true
|
||||
report_id = note_id
|
||||
}
|
||||
|
||||
var MainForm: some View {
|
||||
VStack {
|
||||
|
||||
Text("Report")
|
||||
.font(.headline)
|
||||
.padding()
|
||||
|
||||
Form {
|
||||
Section(content: {
|
||||
Button("It's spam") {
|
||||
do_send_report(type: .spam)
|
||||
}
|
||||
|
||||
Button("Nudity or explicit content") {
|
||||
do_send_report(type: .explicit)
|
||||
}
|
||||
|
||||
Button("Illegal content") {
|
||||
do_send_report(type: .illegal)
|
||||
}
|
||||
|
||||
if case .user = target {
|
||||
Button("They are impersonating someone") {
|
||||
do_send_report(type: .impersonation)
|
||||
}
|
||||
}
|
||||
}, header: {
|
||||
Text("What do you want to report?")
|
||||
}, footer: {
|
||||
Text("Your report will be sent to the relays you are connected to")
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func send_report(privkey: String, pool: RelayPool, target: ReportTarget, type: ReportType) -> NostrEvent? {
|
||||
let report = Report(type: type, target: target, message: "")
|
||||
guard let ev = create_report_event(privkey: privkey, report: report) else {
|
||||
return nil
|
||||
}
|
||||
pool.send(.event(ev))
|
||||
return ev
|
||||
}
|
||||
|
||||
struct ReportView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let ds = test_damus_state()
|
||||
VStack {
|
||||
|
||||
ReportView(pool: ds.pool, target: ReportTarget.user(""), privkey: "")
|
||||
|
||||
ReportView(pool: ds.pool, target: ReportTarget.user(""), privkey: "", report_sent: true, report_id: "report_id")
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user