Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed crash related to tracking delete events #96 #1703

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @[email protected] 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
Loading