Skip to content

Commit

Permalink
fix: Decrease the unread count when a conversation was deleted WPB-34…
Browse files Browse the repository at this point in the history
…83 (#360)
  • Loading branch information
KaterinaWire committed Jul 25, 2023
1 parent 31f6545 commit b3246d8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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))];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b3246d8

Please sign in to comment.