Skip to content

Commit

Permalink
fix: Core Data email association with tracker if tracker has since ch…
Browse files Browse the repository at this point in the history
…anged
  • Loading branch information
apparition47 committed Aug 15, 2021
1 parent 6f53821 commit 84ccc1a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Source/MTBReportingManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 84ccc1a

Please sign in to comment.