From d4067eb39d618b83c92e3f743ab90ee28f22aee5 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Thu, 16 Sep 2021 10:20:18 +1000 Subject: [PATCH 1/5] mark previous messages as read if there is a sync message --- .../Sending & Receiving/MessageReceiver+Handling.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift b/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift index e06c502b9..cd42d6a2f 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift @@ -318,6 +318,11 @@ extension MessageReceiver { tsMessage.openGroupServerMessageID = serverID tsMessage.save(with: transaction) } + // Mark previous messages as read if there is a sync message + if let tsOutgoingMessage = TSMessage.fetch(uniqueId: tsMessageID, transaction: transaction) as? TSOutgoingMessage, + let thread = TSThread.fetch(uniqueId: threadID, transaction: transaction) { + OWSReadReceiptManager.shared().markAsReadLocally(beforeSortId: tsOutgoingMessage.sortId, thread: thread) + } // 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 } From b3db1ac1edd974305e183a88f12eb16c35711c91 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Thu, 16 Sep 2021 10:20:40 +1000 Subject: [PATCH 2/5] cancel notification if the message is marked as read --- SessionMessagingKit/Messages/Signal/TSIncomingMessage.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m b/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m index ecfc9168f..9467768a7 100644 --- a/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m +++ b/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m @@ -14,6 +14,7 @@ #import #import #import +#import NS_ASSUME_NONNULL_BEGIN @@ -181,6 +182,11 @@ NS_ASSUME_NONNULL_BEGIN [[NSNotificationCenter defaultCenter] postNotificationNameAsync:kIncomingMessageMarkedAsReadNotification object:self]; + if (self.notificationIdentifier != NULL) { + UNUserNotificationCenter *notificationCenter = [UNUserNotificationCenter currentNotificationCenter]; + [notificationCenter removeDeliveredNotificationsWithIdentifiers:@[self.notificationIdentifier]]; + [notificationCenter removePendingNotificationRequestsWithIdentifiers:@[self.notificationIdentifier]]; + } }]; [[OWSDisappearingMessagesJob sharedJob] startAnyExpirationForMessage:self From 6f2dd14ce6b3ba709f5193451485e79282b50090 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Thu, 16 Sep 2021 10:32:03 +1000 Subject: [PATCH 3/5] clean --- SessionMessagingKit/Messages/Signal/TSIncomingMessage.m | 5 ----- 1 file changed, 5 deletions(-) diff --git a/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m b/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m index 9467768a7..1fd37c916 100644 --- a/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m +++ b/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m @@ -182,11 +182,6 @@ NS_ASSUME_NONNULL_BEGIN [[NSNotificationCenter defaultCenter] postNotificationNameAsync:kIncomingMessageMarkedAsReadNotification object:self]; - if (self.notificationIdentifier != NULL) { - UNUserNotificationCenter *notificationCenter = [UNUserNotificationCenter currentNotificationCenter]; - [notificationCenter removeDeliveredNotificationsWithIdentifiers:@[self.notificationIdentifier]]; - [notificationCenter removePendingNotificationRequestsWithIdentifiers:@[self.notificationIdentifier]]; - } }]; [[OWSDisappearingMessagesJob sharedJob] startAnyExpirationForMessage:self From d0947b83a94e6becf54c8da0dc6c5b6831bba3df Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Thu, 16 Sep 2021 10:32:23 +1000 Subject: [PATCH 4/5] cancel specific notification if there is an identifier --- Session/Notifications/AppNotifications.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Session/Notifications/AppNotifications.swift b/Session/Notifications/AppNotifications.swift index ba078de92..8b0ad47c5 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 } From 75a4dcee798d5bc764a70245dcde641df9793660 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Thu, 16 Sep 2021 10:33:54 +1000 Subject: [PATCH 5/5] clean --- SessionMessagingKit/Messages/Signal/TSIncomingMessage.m | 1 - 1 file changed, 1 deletion(-) diff --git a/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m b/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m index 1fd37c916..ecfc9168f 100644 --- a/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m +++ b/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m @@ -14,7 +14,6 @@ #import #import #import -#import NS_ASSUME_NONNULL_BEGIN