Skip to content

Commit

Permalink
Merge pull request #1703 from planetary-social/bdm/96-track-delete-crash
Browse files Browse the repository at this point in the history
fixed crash related to tracking delete events #96
  • Loading branch information
bryanmontz authored Dec 19, 2024
2 parents a43e69f + d31b548 commit 963318f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Release Notes
- Fixed display of mastodon usernames so it shows @username@server.instance rather than [email protected]
- Nos now publishes the hashtags it finds in your note when you post. This means it works the way you’ve always expected it to work. [#44](https://github.com/verse-pbc/issues/issues/44)
- Fixed crash related to tracking delete events. [#96](https://github.com/verse-pbc/issues/issues/96)

### Internal Changes
- Upgraded to Xcode 16. [#1570](https://github.com/planetary-social/nos/issues/1570)
Expand Down
19 changes: 12 additions & 7 deletions Nos/Models/CoreData/Event+CoreDataClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,18 @@ public class Event: NosManagedObject, VerifiableEvent {

/// This tracks which relays this event is deleted on. Hide posts with deletedOn.count > 0
func trackDelete(on relay: Relay, context: NSManagedObjectContext) throws {
if EventKind(rawValue: kind) == .delete, let eTags = allTags as? [[String]] {
for deletedEventId in eTags.map({ $0[1] }) {
if let deletedEvent = Event.find(by: deletedEventId, context: context),
deletedEvent.author?.hexadecimalPublicKey == author?.hexadecimalPublicKey {
print("\(deletedEvent.identifier ?? "n/a") was deleted on \(relay.address ?? "unknown")")
deletedEvent.deletedOn.insert(relay)
}
guard EventKind(rawValue: kind) == .delete,
let tags = allTags as? [[String]] else {
return
}

let eTags = tags.filter { $0.first == "e" && $0.count >= 2 }

for deletedEventId in eTags.map({ $0[1] }) {
if let deletedEvent = Event.find(by: deletedEventId, context: context),
deletedEvent.author?.hexadecimalPublicKey == author?.hexadecimalPublicKey {
print("\(deletedEvent.identifier ?? "n/a") was deleted on \(relay.address ?? "unknown")")
deletedEvent.deletedOn.insert(relay)
}
}
}
Expand Down

0 comments on commit 963318f

Please sign in to comment.