Skip to content

Commit

Permalink
Merge pull request #1032 from planetary-social/fix-event-report-format
Browse files Browse the repository at this point in the history
Fix p tags on Reports
  • Loading branch information
mplorentz authored Apr 11, 2024
2 parents 6843a07 + 4b59b75 commit 09ff1f8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Fixed an issue where reports for notes were treated as reports for profiles.
- Fixed the tint color on the Profile screen.
- Added option to connect your existing NIP-05 username.
- Fixed a crash that often occurred after opening the app.
Expand Down
2 changes: 1 addition & 1 deletion Nos/Models/CoreData/Author+CoreDataClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ import Logger
let fetchRequest = NSFetchRequest<Event>(entityName: "Event")
fetchRequest.sortDescriptors = [NSSortDescriptor(keyPath: \Event.createdAt, ascending: false)]
fetchRequest.predicate = NSPredicate(
format: "(kind = %i) AND ANY authorReferences.pubkey = %@",
format: "(kind = %i) AND ANY authorReferences.pubkey = %@ AND eventReferences.@count = 0",
EventKind.report.rawValue,
hexadecimalPublicKey
)
Expand Down
15 changes: 10 additions & 5 deletions Nos/Models/ReportTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,24 @@ enum ReportTarget {
}
}

/// Creates a tag referencing this target that can be attached to a report event.
var tag: [String] {
/// Creates tags referencing this target that can be attached to a report event.
/// - Parameter reportType: the NIP-56 report_type (spam, illegal, etc.)
func tags(for reportType: String) -> [[String]] {
var tags = [[String]]()
switch self {
case .author(let author):
if let pubKey = author.hexadecimalPublicKey {
return ["p", pubKey]
tags.append(["p", pubKey, reportType])
}
case .note(let note):
if let eventID = note.identifier {
return ["e", eventID]
tags.append(["e", eventID, reportType])
}
if let pubKey = note.author?.hexadecimalPublicKey {
tags.append(["p", pubKey])
}
}

return []
return tags
}
}
5 changes: 2 additions & 3 deletions Nos/Views/ReportMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,8 @@ struct ReportMenuModifier: ViewModifier {
content: String(localized: .localizable.reportEventContent(selectedCategory.displayName))
)

var targetTag = reportedObject.tag
targetTag.append(selectedCategory.nip56Code.rawValue)
event.tags.append(targetTag)
let nip56Reason = selectedCategory.nip56Code.rawValue
event.tags += reportedObject.tags(for: nip56Reason)

Task {
do {
Expand Down

0 comments on commit 09ff1f8

Please sign in to comment.