diff --git a/SessionMessagingKit/Database/Models/SessionThread.swift b/SessionMessagingKit/Database/Models/SessionThread.swift index 2c6465139..d3ab96bb5 100644 --- a/SessionMessagingKit/Database/Models/SessionThread.swift +++ b/SessionMessagingKit/Database/Models/SessionThread.swift @@ -493,8 +493,24 @@ public extension SessionThread { // If the thread is a message request then we only want to notify for the first message if self.variant == .contact && isMessageRequest { + let numInteractions: Int = { + switch interaction.serverHash { + case .some(let serverHash): + return (try? self.interactions + .filter(Interaction.Columns.serverHash != serverHash) + .fetchCount(db)) + .defaulting(to: 0) + + case .none: + return (try? self.interactions + .filter(Interaction.Columns.timestampMs != interaction.timestampMs) + .fetchCount(db)) + .defaulting(to: 0) + } + }() + // We only want to show a notification for the first interaction in the thread - guard ((try? self.interactions.fetchCount(db)) ?? 0) <= 1 else { return false } + guard numInteractions == 0 else { return false } // Need to re-show the message requests section if it had been hidden if db[.hasHiddenMessageRequests] { diff --git a/SessionNotificationServiceExtension/NotificationServiceExtension.swift b/SessionNotificationServiceExtension/NotificationServiceExtension.swift index 1edbd97aa..f8e74b0b3 100644 --- a/SessionNotificationServiceExtension/NotificationServiceExtension.swift +++ b/SessionNotificationServiceExtension/NotificationServiceExtension.swift @@ -385,15 +385,12 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension } let duration: CFTimeInterval = (CACurrentMediaTime() - startTime) - let logMessage: String = { - switch (isMainAppAndActive, handledNotification, noContent) { - case (true, _, _): return "Called while main app running, ignoring after \(.seconds(duration), unit: .ms)." - case (_, _, true): return "Called with no content, ignoring after \(.seconds(duration), unit: .ms)." - case (_, true, _): return "Completed after handling notification in \(.seconds(duration), unit: .ms)." - default: return "Completed silently after \(.seconds(duration), unit: .ms)." - } - }() - Log.info(logMessage) + switch (isMainAppAndActive, handledNotification, noContent) { + case (true, _, _): Log.info("Called while main app running, ignoring after \(.seconds(duration), unit: .ms).") + case (_, _, true): Log.info("Called with no content, ignoring after \(.seconds(duration), unit: .ms).") + case (_, true, _): Log.info("Completed after handling notification in \(.seconds(duration), unit: .ms).") + default: Log.info("Completed silently after \(.seconds(duration), unit: .ms).") + } Log.flush() self.contentHandler!(silentContent)