| | 97 | #pragma mark - |
| | 98 | |
| | 99 | |
| | 100 | @interface LPMessageCenter (Private) |
| | 101 | + (NSManagedObjectModel *)p_managedObjectModelWithVersionNr:(unsigned int)version; |
| | 102 | + (void)p_migrateOfflineMessagesFromManagedObjectContext:(NSManagedObjectContext *)sourceContext toContext:(NSManagedObjectContext *)targetContext; |
| | 103 | + (void)p_migrateSapoNotificationsFromManagedObjectContext:(NSManagedObjectContext *)sourceContext toContext:(NSManagedObjectContext *)targetContext; |
| | 104 | + (BOOL)p_shouldMigrateFromXMLFilePath:(NSString *)xmlFilePath toSQLiteFilePath:(NSString *)sqliteFilePath; |
| | 105 | + (NSString *)p_migratePersistentStoreWithURL:(NSURL *)storeURL storeType:(NSString *)storeType fromVersion:(int)storeVersionNr; |
| | 106 | - (NSPersistentStoreCoordinator *)p_persistentStoreCoordinator; |
| | 107 | |
| | 108 | - (void)p_updateUnreadOfflineMessagesCountFromManagedObjectsContextEmittingKVONotification:(BOOL)emitNotification; |
| | 109 | - (void)p_setUnreadOfflineMessagesCount:(int)count emitKVONotification:(BOOL)emitNotification; |
| | 110 | |
| | 111 | - (void)p_managedObjectContextObjectsDidChange:(NSNotification *)notif; |
| | 112 | @end |
| | 113 | |
| | 114 | |
| | 115 | #pragma mark - |
| | 116 | |
| | 117 | |
| | 508 | - (void)p_updateUnreadOfflineMessagesCountFromManagedObjectsContextEmittingKVONotification:(BOOL)emitNotification |
| | 509 | { |
| | 510 | NSManagedObjectContext *context = [self managedObjectContext]; |
| | 511 | NSEntityDescription *msgEntity = [NSEntityDescription entityForName:@"LPOfflineMessage" inManagedObjectContext:context]; |
| | 512 | |
| | 513 | NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; |
| | 514 | NSError *error; |
| | 515 | |
| | 516 | // No predicate, fetch them all. |
| | 517 | [fetchRequest setEntity:msgEntity]; |
| | 518 | [fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"unread == YES"]]; |
| | 519 | |
| | 520 | NSArray *result = [context executeFetchRequest:fetchRequest error:&error]; |
| | 521 | [fetchRequest release]; |
| | 522 | |
| | 523 | |
| | 524 | [self p_setUnreadOfflineMessagesCount:[result count] emitKVONotification:emitNotification]; |
| | 525 | } |
| | 526 | |
| | 527 | |
| | 528 | - (int)unreadOfflineMessagesCount |
| | 529 | { |
| | 530 | // Is the unread messages count initialized yet? |
| | 531 | if (m_unreadOfflineMessagesCount < 0) |
| | 532 | [self p_updateUnreadOfflineMessagesCountFromManagedObjectsContextEmittingKVONotification:NO]; |
| | 533 | |
| | 534 | return m_unreadOfflineMessagesCount; |
| | 535 | } |
| | 536 | |
| | 537 | - (void)p_setUnreadOfflineMessagesCount:(int)count emitKVONotification:(BOOL)emitNotification |
| | 538 | { |
| | 539 | if (count != m_unreadOfflineMessagesCount) { |
| | 540 | if (emitNotification) |
| | 541 | [self willChangeValueForKey:@"unreadOfflineMessagesCount"]; |
| | 542 | |
| | 543 | m_unreadOfflineMessagesCount = count; |
| | 544 | |
| | 545 | if (emitNotification) |
| | 546 | [self didChangeValueForKey:@"unreadOfflineMessagesCount"]; |
| | 547 | } |
| | 548 | } |
| | 549 | |
| | 550 | |