From b3246d8e8e3f42b7ca982601bb03c25126161b37 Mon Sep 17 00:00:00 2001 From: KaterinaWire <57407805+KaterinaWire@users.noreply.github.com> Date: Tue, 25 Jul 2023 19:18:51 +0300 Subject: [PATCH] fix: Decrease the unread count when a conversation was deleted WPB-3483 (#360) --- .../Conversation/ZMConversation+Internal.h | 1 + .../Conversation/ZMConversation+UnreadCount.m | 5 +++-- .../Source/Model/Conversation/ZMConversation.m | 3 ++- .../Model/Conversation/ZMConversation.swift | 3 --- .../Content/ZMLocalNotification.swift | 17 +++++++++++++++++ 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/wire-ios-data-model/Source/Model/Conversation/ZMConversation+Internal.h b/wire-ios-data-model/Source/Model/Conversation/ZMConversation+Internal.h index 47a92bfb1e9..9897ecc05cb 100644 --- a/wire-ios-data-model/Source/Model/Conversation/ZMConversation+Internal.h +++ b/wire-ios-data-model/Source/Model/Conversation/ZMConversation+Internal.h @@ -79,6 +79,7 @@ extern NSString *const ZMConversationLastUnreadKnockDateKey; extern NSString *const ZMConversationLastUnreadMissedCallDateKey; extern NSString *const ZMConversationLastReadLocalTimestampKey; extern NSString *const ZMConversationLegalHoldStatusKey; +extern NSString *const ZMConversationIsDeletedRemotelyKey; extern NSString *const SecurityLevelKey; extern NSString *const ZMConversationLabelsKey; diff --git a/wire-ios-data-model/Source/Model/Conversation/ZMConversation+UnreadCount.m b/wire-ios-data-model/Source/Model/Conversation/ZMConversation+UnreadCount.m index 7360cd67fe7..4f3f8d53aeb 100644 --- a/wire-ios-data-model/Source/Model/Conversation/ZMConversation+UnreadCount.m +++ b/wire-ios-data-model/Source/Model/Conversation/ZMConversation+UnreadCount.m @@ -114,13 +114,14 @@ + (NSPredicate *)predicateForConversationConsideredUnread; { NSPredicate *notSelfConversation = [NSPredicate predicateWithFormat:@"%K != %d", ZMConversationConversationTypeKey, ZMConversationTypeSelf]; NSPredicate *notInvalidConversation = [NSPredicate predicateWithFormat:@"%K != %d", ZMConversationConversationTypeKey, ZMConversationTypeInvalid]; - + NSPredicate *notDeletedRemotelyConversation = [NSPredicate predicateWithFormat:@"%K == NO", ZMConversationIsDeletedRemotelyKey]; + NSPredicate *pendingConnection = [NSPredicate predicateWithFormat:@"%K != nil AND %K.status == %d", ZMConversationConnectionKey, ZMConversationConnectionKey, ZMConnectionStatusPending]; NSPredicate *acceptablePredicate = [NSCompoundPredicate orPredicateWithSubpredicates:@[pendingConnection, [self predicateForUnreadConversation]]]; NSPredicate *notBlockedConnection = [NSPredicate predicateWithFormat:@"(%K == nil) OR (%K != nil AND %K.status != %d)", ZMConversationConnectionKey, ZMConversationConnectionKey, ZMConversationConnectionKey, ZMConnectionStatusBlocked]; - return [NSCompoundPredicate andPredicateWithSubpredicates:@[notSelfConversation, notInvalidConversation, notBlockedConnection, acceptablePredicate]]; + return [NSCompoundPredicate andPredicateWithSubpredicates:@[notSelfConversation, notInvalidConversation, notDeletedRemotelyConversation, notBlockedConnection, acceptablePredicate]]; } + (NSPredicate *)predicateForUnreadConversation diff --git a/wire-ios-data-model/Source/Model/Conversation/ZMConversation.m b/wire-ios-data-model/Source/Model/Conversation/ZMConversation.m index cbde309d75b..6ba05123ce7 100644 --- a/wire-ios-data-model/Source/Model/Conversation/ZMConversation.m +++ b/wire-ios-data-model/Source/Model/Conversation/ZMConversation.m @@ -75,6 +75,7 @@ NSString *const SecurityLevelKey = @"securityLevel"; NSString *const ZMConversationLabelsKey = @"labels"; NSString *const ZMConversationDomainKey = @"domain"; +NSString *const ZMConversationIsDeletedRemotelyKey = @"isDeletedRemotely"; static NSString *const ConnectedUserKey = @"connectedUser"; static NSString *const CreatorKey = @"creator"; @@ -356,7 +357,7 @@ - (NSSet *)ignoredKeys; ZMConversation.mlsStatusKey, ZMConversation.commitPendingProposalDateKey, ZMConversation.epochKey, - ZMConversation.isDeletedRemotelyKey + ZMConversationIsDeletedRemotelyKey }; NSSet *additionalKeys = [NSSet setWithObjects:KeysIgnoredForTrackingModifications count:(sizeof(KeysIgnoredForTrackingModifications) / sizeof(*KeysIgnoredForTrackingModifications))]; diff --git a/wire-ios-data-model/Source/Model/Conversation/ZMConversation.swift b/wire-ios-data-model/Source/Model/Conversation/ZMConversation.swift index e3ea1f8d271..bac3852f876 100644 --- a/wire-ios-data-model/Source/Model/Conversation/ZMConversation.swift +++ b/wire-ios-data-model/Source/Model/Conversation/ZMConversation.swift @@ -20,9 +20,6 @@ import Foundation extension ZMConversation { - @objc - static let isDeletedRemotelyKey: String = #keyPath(ZMConversation.isDeletedRemotely) - /// Whether the conversation was deleted on the backend. @NSManaged diff --git a/wire-ios-request-strategy/Sources/Notifications/Push Notifications/Notification Types/Content/ZMLocalNotification.swift b/wire-ios-request-strategy/Sources/Notifications/Push Notifications/Notification Types/Content/ZMLocalNotification.swift index 49f0d9cc9e4..64742451f8a 100644 --- a/wire-ios-request-strategy/Sources/Notifications/Push Notifications/Notification Types/Content/ZMLocalNotification.swift +++ b/wire-ios-request-strategy/Sources/Notifications/Push Notifications/Notification Types/Content/ZMLocalNotification.swift @@ -169,6 +169,10 @@ extension ZMLocalNotification { WireLogger.badgeCount.info("increase internalEstimatedUnreadCount: \(conversation?.internalEstimatedUnreadCount) in \(conversation?.remoteIdentifier?.uuidString) timestamp: \(Date())") } + if type.shouldDecreaseUnreadCount { + conversation?.internalEstimatedUnreadCount -= 1 + } + if type.shouldIncreaseUnreadMentionCount { conversation?.internalEstimatedUnreadSelfMentionCount += 1 } @@ -199,6 +203,19 @@ extension LocalNotificationType { } } + var shouldDecreaseUnreadCount: Bool { + guard case LocalNotificationType.event(let contentType) = self else { + return false + } + + switch contentType { + case .conversationDeleted: + return true + default: + return false + } + } + var shouldIncreaseUnreadMentionCount: Bool { guard case LocalNotificationType.message(let contentType) = self else { return false