From 8f1a03db889588b41d82c3998728c1557e5843db Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Fri, 26 Aug 2022 13:33:49 +1000 Subject: [PATCH] Moved the code for a previous fix to the correct location and fixed a build issue --- .../ConversationVC+Interaction.swift | 108 +++++++++--------- Session/Notifications/AppNotifications.swift | 7 +- 2 files changed, 61 insertions(+), 54 deletions(-) diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 5a9a05bca..dd44a4036 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -1134,58 +1134,7 @@ extension ConversationVC: .filter(id: cellViewModel.id) .asRequest(of: Int64.self) .fetchOne(db) - else { - // If the message hasn't been sent yet then just delete locally - guard cellViewModel.state == .sending || cellViewModel.state == .failed else { return } - - // Retrieve any message send jobs for this interaction - let jobs: [Job] = Storage.shared - .read { db in - try? Job - .filter(Job.Columns.variant == Job.Variant.messageSend) - .filter(Job.Columns.interactionId == cellViewModel.id) - .fetchAll(db) - } - .defaulting(to: []) - - // If the job is currently running then wait until it's done before triggering - // the deletion - let targetJob: Job? = jobs.first(where: { JobRunner.isCurrentlyRunning($0) }) - - guard targetJob == nil else { - JobRunner.afterCurrentlyRunningJob(targetJob) { [weak self] result in - switch result { - // If it succeeded then we'll need to delete from the server so re-run - // this function (if we still don't have the server id for some reason - // then this would result in a local-only deletion which should be fine - case .succeeded: self?.delete(cellViewModel) - - // Otherwise we just need to cancel the pending job (in case it retries) - // and delete the interaction - default: - JobRunner.removePendingJob(targetJob) - - Storage.shared.writeAsync { db in - _ = try Interaction - .filter(id: cellViewModel.id) - .deleteAll(db) - } - } - } - return - } - - // If it's not currently running then remove any pending jobs (just to be safe) and - // delete the interaction locally - jobs.forEach { JobRunner.removePendingJob($0) } - - Storage.shared.writeAsync { db in - _ = try Interaction - .filter(id: cellViewModel.id) - .deleteAll(db) - } - return - } + else { return } if remove { OpenGroupAPI @@ -1434,7 +1383,60 @@ extension ConversationVC: on: openGroup.server ) ) - else { return } + else { + // If the message hasn't been sent yet then just delete locally + guard cellViewModel.state == .sending || cellViewModel.state == .failed else { + return + } + + // Retrieve any message send jobs for this interaction + let jobs: [Job] = Storage.shared + .read { db in + try? Job + .filter(Job.Columns.variant == Job.Variant.messageSend) + .filter(Job.Columns.interactionId == cellViewModel.id) + .fetchAll(db) + } + .defaulting(to: []) + + // If the job is currently running then wait until it's done before triggering + // the deletion + let targetJob: Job? = jobs.first(where: { JobRunner.isCurrentlyRunning($0) }) + + guard targetJob == nil else { + JobRunner.afterCurrentlyRunningJob(targetJob) { [weak self] result in + switch result { + // If it succeeded then we'll need to delete from the server so re-run + // this function (if we still don't have the server id for some reason + // then this would result in a local-only deletion which should be fine + case .succeeded: self?.delete(cellViewModel) + + // Otherwise we just need to cancel the pending job (in case it retries) + // and delete the interaction + default: + JobRunner.removePendingJob(targetJob) + + Storage.shared.writeAsync { db in + _ = try Interaction + .filter(id: cellViewModel.id) + .deleteAll(db) + } + } + } + return + } + + // If it's not currently running then remove any pending jobs (just to be safe) and + // delete the interaction locally + jobs.forEach { JobRunner.removePendingJob($0) } + + Storage.shared.writeAsync { db in + _ = try Interaction + .filter(id: cellViewModel.id) + .deleteAll(db) + } + return + } // Delete the message from the open group deleteRemotely( diff --git a/Session/Notifications/AppNotifications.swift b/Session/Notifications/AppNotifications.swift index 96c6bea16..e0c25749b 100644 --- a/Session/Notifications/AppNotifications.swift +++ b/Session/Notifications/AppNotifications.swift @@ -384,9 +384,14 @@ public class NotificationPresenter: NSObject, NotificationsProtocol { closedGroupName: nil, // Not supported openGroupName: nil // Not supported ) + let fallbackSound: Preferences.Sound = db[.defaultNotificationSound] + .defaulting(to: Preferences.Sound.defaultNotificationSound) DispatchQueue.main.async { - let sound = self.requestSound(thread: thread) + let sound = self.requestSound( + thread: thread, + fallbackSound: fallbackSound + ) self.adaptee.notify( category: category,