Skip to content

Commit

Permalink
Merge pull request #30 from apptentive/IOSOSX-69
Browse files Browse the repository at this point in the history
Do not mark all messages as read when MC opens and closes.
  • Loading branch information
pkamb committed May 15, 2015
2 parents 9f1bdc9 + bff13ab commit 23c5d8e
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ - (void)viewDidLoad {

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.dataSource markAllMessagesAsRead];
}

- (void)viewDidUnload {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
- (id)initWithDelegate:(NSObject<ATMessageCenterDataSourceDelegate> *)delegate;
- (void)start;
- (void)stop;
- (void)markAllMessagesAsRead;
- (void)createIntroMessageIfNecessary;
@end

@end

@protocol ATMessageCenterDataSourceDelegate <NSObject, NSFetchedResultsControllerDelegate>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ - (NSFetchedResultsController *)fetchedMessagesController {
- (void)start {
[[ATBackend sharedBackend] messageCenterEnteredForeground];

[self markAllMessagesAsRead];
[ATTextMessage clearComposingMessages];

NSError *error = nil;
Expand All @@ -77,30 +76,6 @@ - (void)stop {

}

- (void)markAllMessagesAsRead {
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"ATAbstractMessage" inManagedObjectContext:[[ATBackend sharedBackend] managedObjectContext]]];
[request setFetchBatchSize:20];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"clientCreationTime" ascending:YES];
[request setSortDescriptors:@[sortDescriptor]];
sortDescriptor = nil;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"seenByUser == %d", 0];
[request setPredicate:predicate];

NSManagedObjectContext *moc = [ATData moc];
NSError *error = nil;
NSArray *results = [moc executeFetchRequest:request error:&error];
if (!results) {
ATLogError(@"Error executing fetch request: %@", error);
} else {
for (ATAbstractMessage *message in results) {
[message markAsRead];
}
[ATData save];
}
request = nil;
}

- (void)createIntroMessageIfNecessary {
NSUInteger messageCount = [ATData countEntityNamed:@"ATAbstractMessage" withPredicate:nil];
if (messageCount == 0) {
Expand Down
2 changes: 2 additions & 0 deletions ApptentiveConnect/source/Model/ATAbstractMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ - (void)markAsRead {
if (self.apptentiveID && ![self.sentByUser boolValue]) {
[[NSNotificationCenter defaultCenter] postNotificationName:ATMessageCenterDidReadNotification object:self userInfo:@{ATMessageCenterMessageIDKey:self.apptentiveID}];
}

[ATData save];
}
}

Expand Down

0 comments on commit 23c5d8e

Please sign in to comment.