Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@

let conversations = fetchedResultsController?.fetchedObjects ?? []
for conversation in conversations {
await context.perform {

Check warning on line 61 in WireDomain/Sources/WireDomain/Synchronization/ConversationUpdatesGenerator.swift

View workflow job for this annotation

GitHub Actions / Test Results

Capture of 'conversation' with non-Sendable type 'ZMConversation' in a '@Sendable' closure

Capture of 'conversation' with non-Sendable type 'ZMConversation' in a '@sendable' closure
if let id = conversation.qualifiedID {

Check warning on line 62 in WireDomain/Sources/WireDomain/Synchronization/ConversationUpdatesGenerator.swift

View workflow job for this annotation

GitHub Actions / Test Results

Capture of 'self' with non-Sendable type 'ConversationUpdatesGenerator' in a '@Sendable' closure

Capture of 'self' with non-Sendable type 'ConversationUpdatesGenerator' in a '@sendable' closure
self.onConversationUpdated(UpdateConversationItem(
repository: self.repository,
conversationID: id.toAPIModel()
Expand All @@ -75,7 +75,11 @@

private func createFetchRequestController() -> NSFetchedResultsController<ZMConversation> {
let request = NSFetchRequest<ZMConversation>(entityName: ZMConversation.entityName())
request.predicate = ZMConversation.predicateForNeedingToBeUpdatedFromBackend()
request.predicate = NSPredicate.all(of: [
ZMConversation.predicateForNeedingToBeUpdatedFromBackend(),
NSPredicate(format: "%K == NO", #keyPath(ZMConversation.isDeletedRemotely))
])

request.sortDescriptors = [NSSortDescriptor(key: ZMConversationLastServerTimeStampKey, ascending: true)]
return NSFetchedResultsController(
fetchRequest: request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,28 @@ class ConversationUpdatesGeneratorTests {

#expect(updateConversationItems.isEmpty)
}

@Test("It does not generate an item when a conversation is deleted")
func deletedConversation() async throws {
// GIVEN
let conversationID = QualifiedID.random()
await coreDataStack.syncContext.perform { [modelHelper, context = coreDataStack.syncContext] in
let conversation = modelHelper.createGroupConversation(
id: conversationID.uuid,
domain: conversationID.domain,
in: context
)
conversation.needsToBeUpdatedFromBackend = true
conversation.isDeletedRemotely = true
}
var updateConversationItems = [UpdateConversationItem]()
updateConversationItemClosure = { item in
updateConversationItems.append(item)
}
// WHEN
await sut.start()

// THEN
#expect(updateConversationItems.isEmpty)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extern NSString * _Nonnull const ZMManagedObjectLocallyModifiedKeysKey;
@property (nonatomic, readonly, nullable) NSSet *ignoredKeys;

/// Returns a predicate that will match objects which need additional data from the backend.
+ (nullable NSPredicate *)predicateForNeedingToBeUpdatedFromBackend;
+ (NSPredicate * _Nonnull)predicateForNeedingToBeUpdatedFromBackend;

/// Returns a predicate that will match objects that have local modifications that need to be pushed to the backend
+ (nullable NSPredicate *)predicateForObjectsThatNeedToBeUpdatedUpstream;
Expand Down
2 changes: 1 addition & 1 deletion wire-ios-data-model/Source/Model/ZMManagedObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ + (NSSet *)fetchObjectsWithRemoteIdentifiers:(NSSet <NSUUID *> *)uuids inManaged

@implementation ZMManagedObject (PersistentChangeTracking)

+ (NSPredicate *)predicateForNeedingToBeUpdatedFromBackend;
+ (NSPredicate * _Nonnull)predicateForNeedingToBeUpdatedFromBackend;
{
return [NSPredicate predicateWithFormat:@"%K != 0", NeedsToBeUpdatedFromBackendKey];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ extension FetchingClientRequestStrategy: ZMContextChangeTracker, ZMContextChange
}

public func fetchRequestForTrackedObjects() -> NSFetchRequest<NSFetchRequestResult>? {
UserClient.sortedFetchRequest(with: UserClient.predicateForNeedingToBeUpdatedFromBackend()!)
UserClient.sortedFetchRequest(with: UserClient.predicateForNeedingToBeUpdatedFromBackend())
}

public func addTrackedObjects(_ objects: Set<NSManagedObject>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ extension UserProfileRequestStrategy: ZMContextChangeTracker {
}

public func fetchRequestForTrackedObjects() -> NSFetchRequest<NSFetchRequestResult>? {
ZMUser.sortedFetchRequest(with: ZMUser.predicateForNeedingToBeUpdatedFromBackend()!)
ZMUser.sortedFetchRequest(with: ZMUser.predicateForNeedingToBeUpdatedFromBackend())
}

public func addTrackedObjects(_ objects: Set<NSManagedObject>) {
Expand Down
Loading