diff --git a/Session/Notifications/AppNotifications.swift b/Session/Notifications/AppNotifications.swift index fbb44d372..c482720cd 100644 --- a/Session/Notifications/AppNotifications.swift +++ b/Session/Notifications/AppNotifications.swift @@ -139,7 +139,11 @@ public class NotificationPresenter: NSObject, NotificationsProtocol { switch notification.object { case let incomingMessage as TSIncomingMessage: Logger.debug("canceled notification for message: \(incomingMessage)") - cancelNotifications(threadId: incomingMessage.uniqueThreadId) + if let identifier = incomingMessage.notificationIdentifier { + cancelNotification(identifier) + } else { + cancelNotifications(threadId: incomingMessage.uniqueThreadId) + } default: break } diff --git a/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift b/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift index b76138474..ba761cc26 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift @@ -326,8 +326,11 @@ extension MessageReceiver { tsMessage.openGroupServerMessageID = serverID tsMessage.save(with: transaction) } - // Start expiration for sync messages - if let tsOutgoingMessage = TSMessage.fetch(uniqueId: tsMessageID, transaction: transaction) as? TSOutgoingMessage { + if let tsOutgoingMessage = TSMessage.fetch(uniqueId: tsMessageID, transaction: transaction) as? TSOutgoingMessage, + let thread = TSThread.fetch(uniqueId: threadID, transaction: transaction) { + // Mark previous messages as read if there is a sync message + OWSReadReceiptManager.shared().markAsReadLocally(beforeSortId: tsOutgoingMessage.sortId, thread: thread) + // Start expiration for sync messages OWSDisappearingMessagesJob.shared().startAnyExpiration(for: tsOutgoingMessage, expirationStartedAt: NSDate.millisecondTimestamp(), transaction: transaction) } // Notify the user if needed