From 84ccc1ac11e7cb6416fd16892254d1f26d8aab6e Mon Sep 17 00:00:00 2001 From: Aaron Lee Date: Sun, 15 Aug 2021 19:41:35 +0900 Subject: [PATCH] fix: Core Data email association with tracker if tracker has since changed --- Source/MTBReportingManager.m | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Source/MTBReportingManager.m b/Source/MTBReportingManager.m index 4f9be53..1c5a3d3 100644 --- a/Source/MTBReportingManager.m +++ b/Source/MTBReportingManager.m @@ -40,14 +40,23 @@ -(void)markEmailRead:(MTBBlockedMessage*)blkMsg { return; } Email *email; - if (fetchResults.count == 0) { + if (fetchResults.count > 0 && ![fetchResults.firstObject.tracker.name isEqualToString:blkMsg.detectedTracker]) { + // if tracker has assoc with tracker rule that since changed + [context deleteObject:fetchResults.firstObject]; + email = [NSEntityDescription insertNewObjectForEntityForName:@"Email" inManagedObjectContext:context]; [email setSubject:blkMsg.subjectField]; [email setDeeplink:blkMsg.deeplinkField]; - } else { + [email setRead_timestamp:[NSDate date]]; + } else if (fetchResults.count > 0) { + // id'd tracker exists and is same as previous record email = fetchResults.firstObject; + } else { + email = [NSEntityDescription insertNewObjectForEntityForName:@"Email" inManagedObjectContext:context]; + [email setSubject:blkMsg.subjectField]; + [email setDeeplink:blkMsg.deeplinkField]; + [email setRead_timestamp:[NSDate date]]; } - [email setRead_timestamp:[NSDate date]]; // check if tracker has been prev saved if (blkMsg.detectedTracker != nil) {