From 80bf62df901d6d70cae5ab3fca695b7f8b9c5f3e Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Tue, 3 Aug 2021 10:42:09 +1000 Subject: [PATCH] fix nested transaction crash on setting notification identifier --- Session/Notifications/AppNotifications.swift | 4 +--- .../Sending & Receiving/MessageReceiver+Handling.swift | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Session/Notifications/AppNotifications.swift b/Session/Notifications/AppNotifications.swift index ac5f8ebf1..ba078de92 100644 --- a/Session/Notifications/AppNotifications.swift +++ b/Session/Notifications/AppNotifications.swift @@ -221,9 +221,7 @@ public class NotificationPresenter: NSObject, NotificationsProtocol { AppNotificationUserInfoKey.threadId: threadId ] - let transaction = transaction as! YapDatabaseReadWriteTransaction - let identifier: String = UUID().uuidString - incomingMessage.setNotificationIdentifier(identifier, transaction: transaction) + let identifier: String = incomingMessage.notificationIdentifier ?? UUID().uuidString DispatchQueue.main.async { notificationBody = MentionUtilities.highlightMentions(in: notificationBody!, threadID: thread.uniqueId!) diff --git a/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift b/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift index 0e7967ab8..a6f6b47c6 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift @@ -305,6 +305,7 @@ extension MessageReceiver { // Notify the user if needed guard (isMainAppAndActive || isBackgroundPoll), let tsIncomingMessage = TSMessage.fetch(uniqueId: tsMessageID, transaction: transaction) as? TSIncomingMessage, let thread = TSThread.fetch(uniqueId: threadID, transaction: transaction) else { return tsMessageID } + tsIncomingMessage.setNotificationIdentifier(UUID().uuidString, transaction: transaction) DispatchQueue.main.async { Storage.read { transaction in SSKEnvironment.shared.notificationsManager!.notifyUser(for: tsIncomingMessage, in: thread, transaction: transaction)