Skip to content

Commit

Permalink
Fix crash when deleting notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceylo committed Apr 20, 2024
1 parent 768b785 commit b6bcd62
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 10 additions & 6 deletions FurAffinity/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,29 +162,33 @@ class Model: ObservableObject {
}
}

func deleteSubmissionCommentNotifications(_ notifications: [FASubmissionCommentNotificationPreview]) async {
func deleteSubmissionCommentNotifications(_ notifications: [FASubmissionCommentNotificationPreview]) {
notificationPreviews = notificationPreviews.map { oldNotifications in
NotificationPreviews(
submissionComments: oldNotifications.submissionComments.filter { !notifications.contains($0) },
journals: oldNotifications.journals
)
}

await fetchNotificationPreviews { session in
await session.deleteSubmissionCommentNotifications(notifications)
Task {
await fetchNotificationPreviews { session in
await session.deleteSubmissionCommentNotifications(notifications)
}
}
}

func deleteJournalNotifications(_ notifications: [FAJournalNotificationPreview]) async {
func deleteJournalNotifications(_ notifications: [FAJournalNotificationPreview]) {
notificationPreviews = notificationPreviews.map { oldNotifications in
NotificationPreviews(
submissionComments: oldNotifications.submissionComments,
journals: oldNotifications.journals.filter { !notifications.contains($0) }
)
}

await fetchNotificationPreviews { session in
await session.deleteJournalNotifications(notifications)
Task {
await fetchNotificationPreviews { session in
await session.deleteJournalNotifications(notifications)
}
}
}

Expand Down
8 changes: 2 additions & 6 deletions FurAffinity/Notifications/RemoteNotificationsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,10 @@ struct RemoteNotificationsView: View {
submissionCommentNotifications: notifications.submissionComments,
journalNotifications: notifications.journals,
onDeleteSubmissionCommentNotifications: { items in
Task {
await model.deleteSubmissionCommentNotifications(items)
}
model.deleteSubmissionCommentNotifications(items)
},
onDeleteJournalNotifications: { items in
Task {
await model.deleteJournalNotifications(items)
}
model.deleteJournalNotifications(items)
},
onNukeSubmissionComments: {
await model.nukeAllSubmissionCommentNotifications()
Expand Down

0 comments on commit b6bcd62

Please sign in to comment.