Background tasking unreading of stories.

This commit is contained in:
Samuel Clay 2014-03-05 21:31:53 -08:00
parent 83dcf5640b
commit 9b4c916883
2 changed files with 34 additions and 26 deletions

View file

@ -362,7 +362,10 @@
NSString *storyFeedId = [request.userInfo objectForKey:@"story_feed_id"]; NSString *storyFeedId = [request.userInfo objectForKey:@"story_feed_id"];
NSString *storyHash = [request.userInfo objectForKey:@"story_hash"]; NSString *storyHash = [request.userInfo objectForKey:@"story_hash"];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
(unsigned long)NULL), ^(void) {
BOOL dequeued = [appDelegate dequeueReadStoryHash:storyHash inFeed:storyFeedId]; BOOL dequeued = [appDelegate dequeueReadStoryHash:storyHash inFeed:storyFeedId];
dispatch_async(dispatch_get_main_queue(), ^{
if (!dequeued) { if (!dequeued) {
// Offline means can't unread a story unless it was read while offline. // Offline means can't unread a story unless it was read while offline.
[self markStoryRead:storyHash feedId:storyFeedId]; [self markStoryRead:storyHash feedId:storyFeedId];
@ -373,6 +376,8 @@
[appDelegate.unreadStoryHashes setObject:[NSNumber numberWithBool:YES] forKey:storyHash]; [appDelegate.unreadStoryHashes setObject:[NSNumber numberWithBool:YES] forKey:storyHash];
// [self.storyTitlesTable reloadData]; // [self.storyTitlesTable reloadData];
} }
});
});
} }
#pragma mark - Story Actions #pragma mark - Story Actions
@ -551,6 +556,8 @@
if (!newUnreadCounts) return; if (!newUnreadCounts) return;
[appDelegate.dictUnreadCounts setObject:newUnreadCounts forKey:feedIdStr]; [appDelegate.dictUnreadCounts setObject:newUnreadCounts forKey:feedIdStr];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
(unsigned long)NULL), ^(void) {
[appDelegate.database inTransaction:^(FMDatabase *db, BOOL *rollback) { [appDelegate.database inTransaction:^(FMDatabase *db, BOOL *rollback) {
NSString *storyHash = [newStory objectForKey:@"story_hash"]; NSString *storyHash = [newStory objectForKey:@"story_hash"];
[db executeUpdate:@"UPDATE stories SET story_json = ? WHERE story_hash = ?", [db executeUpdate:@"UPDATE stories SET story_json = ? WHERE story_hash = ?",
@ -565,6 +572,7 @@
[newUnreadCounts objectForKey:@"ng"], [newUnreadCounts objectForKey:@"ng"],
feedIdStr]; feedIdStr];
}]; }];
});
[appDelegate.recentlyReadStories removeObjectForKey:[story objectForKey:@"story_hash"]]; [appDelegate.recentlyReadStories removeObjectForKey:[story objectForKey:@"story_hash"]];
[appDelegate finishMarkAsUnread:story]; [appDelegate finishMarkAsUnread:story];

View file

@ -5,7 +5,7 @@
#import <SystemConfiguration/SystemConfiguration.h> #import <SystemConfiguration/SystemConfiguration.h>
#import <MobileCoreServices/MobileCoreServices.h> #import <MobileCoreServices/MobileCoreServices.h>
#define DEBUG 1 //#define DEBUG 1
//#define PROD_DEBUG 1 //#define PROD_DEBUG 1
#ifdef DEBUG #ifdef DEBUG