Compare commits
1 Commits
thai
...
nip56-conf
| Author | SHA1 | Date | |
|---|---|---|---|
|
16c839afa6
|
@@ -7,11 +7,27 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
enum ReportType: String {
|
enum ReportType: String, CustomStringConvertible, CaseIterable {
|
||||||
case explicit
|
|
||||||
case illegal
|
|
||||||
case spam
|
case spam
|
||||||
|
case nudity
|
||||||
|
case profanity
|
||||||
|
case illegal
|
||||||
case impersonation
|
case impersonation
|
||||||
|
|
||||||
|
var description: String {
|
||||||
|
switch self {
|
||||||
|
case .spam:
|
||||||
|
return NSLocalizedString("Spam", comment: "Description of report type for spam.")
|
||||||
|
case .nudity:
|
||||||
|
return NSLocalizedString("Nudity", comment: "Description of report type for nudity.")
|
||||||
|
case .profanity:
|
||||||
|
return NSLocalizedString("Profanity", comment: "Description of report type for profanity.")
|
||||||
|
case .illegal:
|
||||||
|
return NSLocalizedString("Illegal Content", comment: "Description of report type for illegal content.")
|
||||||
|
case .impersonation:
|
||||||
|
return NSLocalizedString("Impersonation", comment: "Description of report type for impersonation.")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ReportNoteTarget {
|
struct ReportNoteTarget {
|
||||||
@@ -31,16 +47,12 @@ struct Report {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func create_report_tags(target: ReportTarget, type: ReportType) -> [[String]] {
|
func create_report_tags(target: ReportTarget, type: ReportType) -> [[String]] {
|
||||||
var tags: [[String]]
|
|
||||||
switch target {
|
switch target {
|
||||||
case .user(let pubkey):
|
case .user(let pubkey):
|
||||||
tags = [["p", pubkey]]
|
return [["p", pubkey, type.rawValue]]
|
||||||
case .note(let notet):
|
case .note(let notet):
|
||||||
tags = [["e", notet.note_id], ["p", notet.pubkey]]
|
return [["e", notet.note_id, type.rawValue], ["p", notet.pubkey]]
|
||||||
}
|
}
|
||||||
|
|
||||||
tags.append(["report", type.rawValue])
|
|
||||||
return tags
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func create_report_event(privkey: String, report: Report) -> NostrEvent? {
|
func create_report_event(privkey: String, report: Report) -> NostrEvent? {
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ struct ReportView: View {
|
|||||||
|
|
||||||
@State var report_sent: Bool = false
|
@State var report_sent: Bool = false
|
||||||
@State var report_id: String = ""
|
@State var report_id: String = ""
|
||||||
|
@State var report_message: String = ""
|
||||||
|
@State var selected_report_type: ReportType?
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
if report_sent {
|
if report_sent {
|
||||||
@@ -43,8 +45,8 @@ struct ReportView: View {
|
|||||||
.padding()
|
.padding()
|
||||||
}
|
}
|
||||||
|
|
||||||
func do_send_report(type: ReportType) {
|
func do_send_report() {
|
||||||
guard let ev = send_report(privkey: privkey, postbox: postbox, target: target, type: type) else {
|
guard let selected_report_type, let ev = send_report(privkey: privkey, postbox: postbox, target: target, type: selected_report_type, message: report_message) else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +57,15 @@ struct ReportView: View {
|
|||||||
report_sent = true
|
report_sent = true
|
||||||
report_id = note_id
|
report_id = note_id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var send_report_button_text: String {
|
||||||
|
switch target {
|
||||||
|
case .note:
|
||||||
|
return NSLocalizedString("Report Note", comment: "Button to report a note.")
|
||||||
|
case .user:
|
||||||
|
return NSLocalizedString("Report User", comment: "Button to report a user.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var MainForm: some View {
|
var MainForm: some View {
|
||||||
VStack {
|
VStack {
|
||||||
@@ -65,23 +76,27 @@ struct ReportView: View {
|
|||||||
|
|
||||||
Form {
|
Form {
|
||||||
Section(content: {
|
Section(content: {
|
||||||
Button(NSLocalizedString("It's spam", comment: "Button for user to report that the account or content has spam.")) {
|
Picker("", selection: $selected_report_type) {
|
||||||
do_send_report(type: .spam)
|
ForEach(ReportType.allCases, id: \.self) { report_type in
|
||||||
}
|
// Impersonation type is not supported when reporting notes.
|
||||||
|
if case .note = target, report_type != .impersonation {
|
||||||
Button(NSLocalizedString("Nudity or explicit content", comment: "Button for user to report that the account or content has nudity or explicit content.")) {
|
Text(verbatim: String(describing: report_type))
|
||||||
do_send_report(type: .explicit)
|
.tag(Optional(report_type))
|
||||||
}
|
} else if case .user = target {
|
||||||
|
Text(verbatim: String(describing: report_type))
|
||||||
Button(NSLocalizedString("Illegal content", comment: "Button for user to report that the account or content has illegal content.")) {
|
.tag(Optional(report_type))
|
||||||
do_send_report(type: .illegal)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if case .user = target {
|
|
||||||
Button(NSLocalizedString("They are impersonating someone", comment: "Button for user to report that the account is impersonating someone.")) {
|
|
||||||
do_send_report(type: .impersonation)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.labelsHidden()
|
||||||
|
.pickerStyle(.inline)
|
||||||
|
|
||||||
|
TextField(NSLocalizedString("Additional information (optional)", comment: "Prompt to enter optional additional information when reporting an account or content."), text: $report_message, axis: .vertical)
|
||||||
|
|
||||||
|
Button(send_report_button_text) {
|
||||||
|
do_send_report()
|
||||||
|
}
|
||||||
|
.disabled(selected_report_type == nil)
|
||||||
}, header: {
|
}, header: {
|
||||||
Text("What do you want to report?", comment: "Header text to prompt user what issue they want to report.")
|
Text("What do you want to report?", comment: "Header text to prompt user what issue they want to report.")
|
||||||
}, footer: {
|
}, footer: {
|
||||||
@@ -92,8 +107,8 @@ struct ReportView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func send_report(privkey: String, postbox: PostBox, target: ReportTarget, type: ReportType) -> NostrEvent? {
|
func send_report(privkey: String, postbox: PostBox, target: ReportTarget, type: ReportType, message: String) -> NostrEvent? {
|
||||||
let report = Report(type: type, target: target, message: "")
|
let report = Report(type: type, target: target, message: message)
|
||||||
guard let ev = create_report_event(privkey: privkey, report: report) else {
|
guard let ev = create_report_event(privkey: privkey, report: report) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user