Adding gesture for marking as read/unread. Needs offline handling for unread.

This commit is contained in:
Samuel Clay 2013-10-01 16:21:23 -07:00
parent da993a8deb
commit a761cb9af0
3 changed files with 90 additions and 84 deletions

View file

@ -1107,10 +1107,10 @@
withRowAnimation:UITableViewRowAnimationFade];
} else if (state == MCSwipeTableViewCellState3) {
// Read
if ([[story objectForKey:@"starred"] boolValue]) {
// [self markStoryAsRead:story];
if ([[story objectForKey:@"read_status"] boolValue]) {
[self markStoryAsUnread:story];
} else {
// [self markStoryAsUnread:story];
[self markStoryAsRead:story];
}
[self.storyTitlesTable reloadRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationFade];
@ -1458,6 +1458,74 @@
#pragma mark -
#pragma mark Story Actions - read
- (void)markStoryAsRead:(NSDictionary *)story {
NSString *urlString = [NSString stringWithFormat:@"%@/reader/mark_story_hashes_as_read",
NEWSBLUR_URL];
NSURL *url = [NSURL URLWithString:urlString];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:[story objectForKey:@"story_hash"]
forKey:@"story_hash"];
[request setDidFinishSelector:@selector(finishMarkAsRead:)];
[request setDidFailSelector:@selector(failedMarkAsRead:)];
[request setDelegate:self];
[request setUserInfo:story];
[request startAsynchronous];
[appDelegate markStoryRead:[story objectForKey:@"story_hash"]
feedId:[story objectForKey:@"story_feed_id"]];
}
- (void)finishMarkAsRead:(ASIFormDataRequest *)request {
if ([request responseStatusCode] != 200) {
return [self failedMarkAsRead:request];
}
[appDelegate.storyPageControl refreshHeaders];
}
- (void)failedMarkAsRead:(ASIFormDataRequest *)request {
NSString *storyFeedId = [request.userInfo objectForKey:@"story_feed_id"];
NSString *storyHash = [request.userInfo objectForKey:@"story_hash"];
[appDelegate queueReadStories:@{storyFeedId: @[storyHash]}];
}
- (void)markStoryAsUnread:(NSDictionary *)story {
NSString *urlString = [NSString stringWithFormat:@"%@/reader/mark_story_as_unread",
NEWSBLUR_URL];
NSURL *url = [NSURL URLWithString:urlString];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:[story objectForKey:@"story_hash"]
forKey:@"story_id"];
[request setPostValue:[story objectForKey:@"story_feed_id"]
forKey:@"feed_id"];
[request setDidFinishSelector:@selector(finishMarkAsUnread:)];
[request setDidFailSelector:@selector(failedMarkAsUnread:)];
[request setDelegate:self];
[request setUserInfo:story];
[request startAsynchronous];
[appDelegate markStoryUnread:[story objectForKey:@"story_hash"]
feedId:[story objectForKey:@"story_feed_id"]];
}
- (void)finishMarkAsUnread:(ASIFormDataRequest *)request {
if ([request responseStatusCode] != 200) {
return [self failedMarkAsUnread:request];
}
[appDelegate.storyPageControl refreshHeaders];
}
- (void)failedMarkAsUnread:(ASIFormDataRequest *)request {
[self informError:@"Failed to unread story"];
// [appDelegate markStory:request.userInfo asRead:YES];
[self.storyTitlesTable reloadData];
}
#pragma mark -
#pragma mark Story Actions - save
@ -1487,7 +1555,6 @@
return [self failedMarkAsSaved:request];
}
[appDelegate.storyPageControl.currentPage setActiveStoryAtIndex:-1];
[appDelegate.storyPageControl refreshHeaders];
}
@ -1523,7 +1590,6 @@
return [self failedMarkAsUnsaved:request];
}
[appDelegate.storyPageControl.currentPage setActiveStoryAtIndex:-1];
[appDelegate.storyPageControl refreshHeaders];
}

View file

@ -1638,7 +1638,6 @@
});
}
- (void)markStoryUnread:(NSString *)storyId feedId:(id)feedId {
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
NSDictionary *feed = [self.dictFeeds objectForKey:feedIdStr];

View file

@ -668,24 +668,6 @@
[self informError:@"The server barfed!"];
}
- (void)requestFailedMarkStoryRead:(ASIFormDataRequest *)request {
// [self informError:@"Failed to mark story as read"];
NSString *storyFeedId = [request.userInfo objectForKey:@"story_feed_id"];
NSString *storyHash = [request.userInfo objectForKey:@"story_hash"];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
(unsigned long)NULL), ^(void) {
[appDelegate.database inDatabase:^(FMDatabase *db) {
[db executeUpdate:@"INSERT INTO queued_read_hashes "
"(story_feed_id, story_hash) VALUES "
"(?, ?)", storyFeedId, storyHash];
}];
});
appDelegate.hasQueuedReadStories = YES;
}
#pragma mark -
#pragma mark Actions
@ -754,70 +736,22 @@
// NSLog(@"[appDelegate.activeStory objectForKey:@read_status] intValue] %i", [[appDelegate.activeStory objectForKey:@"read_status"] intValue]);
if ([[appDelegate.activeStory objectForKey:@"read_status"] intValue] != 1 ||
[[appDelegate.unreadStoryHashes objectForKey:[appDelegate.activeStory objectForKey:@"story_hash"]] boolValue]) {
[[appDelegate.unreadStoryHashes
objectForKey:[appDelegate.activeStory objectForKey:@"story_hash"]]
boolValue]) {
[appDelegate markActiveStoryRead];
NSString *urlString;
if (appDelegate.isSocialView || appDelegate.isSocialRiverView) {
urlString = [NSString stringWithFormat:@"%@/reader/mark_social_stories_as_read",
NEWSBLUR_URL];
} else {
urlString = [NSString stringWithFormat:@"%@/reader/mark_story_as_read",
NEWSBLUR_URL];
}
NSString *urlString = [NSString stringWithFormat:@"%@/reader/mark_story_hashes_as_read",
NEWSBLUR_URL];
NSURL *url = [NSURL URLWithString:urlString];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
if (appDelegate.isSocialRiverView) {
// grab the user id from the shared_by_friends
NSArray *storyId = [NSArray arrayWithObject:[appDelegate.activeStory objectForKey:@"id"]];
NSString *friendUserId;
if ([[appDelegate.activeStory objectForKey:@"shared_by_friends"] count]) {
friendUserId = [NSString stringWithFormat:@"%@",
[[appDelegate.activeStory objectForKey:@"shared_by_friends"] objectAtIndex:0]];
} else if ([[appDelegate.activeStory objectForKey:@"commented_by_friends"] count]) {
friendUserId = [NSString stringWithFormat:@"%@",
[[appDelegate.activeStory objectForKey:@"commented_by_friends"] objectAtIndex:0]];
} else {
friendUserId = [NSString stringWithFormat:@"%@",
[[appDelegate.activeStory objectForKey:@"share_user_ids"] objectAtIndex:0]];
}
NSDictionary *feedStory = [NSDictionary dictionaryWithObject:storyId
forKey:[NSString stringWithFormat:@"%@",
[appDelegate.activeStory objectForKey:@"story_feed_id"]]];
NSDictionary *usersFeedsStories = [NSDictionary dictionaryWithObject:feedStory
forKey:friendUserId];
[request setPostValue:[usersFeedsStories JSONRepresentation] forKey:@"users_feeds_stories"];
} else if (appDelegate.isSocialView) {
NSArray *storyId = [NSArray arrayWithObject:[appDelegate.activeStory objectForKey:@"id"]];
NSDictionary *feedStory = [NSDictionary dictionaryWithObject:storyId
forKey:[NSString stringWithFormat:@"%@",
[appDelegate.activeStory objectForKey:@"story_feed_id"]]];
NSDictionary *usersFeedsStories = [NSDictionary dictionaryWithObject:feedStory
forKey:[NSString stringWithFormat:@"%@",
[appDelegate.activeStory objectForKey:@"social_user_id"]]];
[request setPostValue:[usersFeedsStories JSONRepresentation] forKey:@"users_feeds_stories"];
} else {
[request setPostValue:[appDelegate.activeStory
objectForKey:@"story_hash"]
forKey:@"story_id"];
[request setPostValue:[appDelegate.activeStory
objectForKey:@"story_feed_id"]
forKey:@"feed_id"];
[request setUserInfo:@{@"story_feed_id":[appDelegate.activeStory
objectForKey:@"story_feed_id"],
@"story_hash":[appDelegate.activeStory
objectForKey:@"story_hash"]}];
}
[request setPostValue:[appDelegate.activeStory objectForKey:@"story_hash"]
forKey:@"story_hash"];
[request setUserInfo:@{@"story_feed_id":[appDelegate.activeStory
objectForKey:@"story_feed_id"],
@"story_hash":[appDelegate.activeStory
objectForKey:@"story_hash"]}];
[request setDidFinishSelector:@selector(finishMarkAsRead:)];
[request setDidFailSelector:@selector(requestFailedMarkStoryRead:)];
[request setDelegate:self];
@ -825,7 +759,6 @@
}
}
- (void)finishMarkAsRead:(ASIFormDataRequest *)request {
if ([request responseStatusCode] != 200) {
return [self requestFailedMarkStoryRead:request];
@ -837,6 +770,14 @@
// NSLog(@"results in mark as read is %@", results);
}
- (void)requestFailedMarkStoryRead:(ASIFormDataRequest *)request {
// [self informError:@"Failed to mark story as read"];
NSString *storyFeedId = [request.userInfo objectForKey:@"story_feed_id"];
NSString *storyHash = [request.userInfo objectForKey:@"story_hash"];
[appDelegate queueReadStories:@{storyFeedId: @[storyHash]}];
}
- (IBAction)openSendToDialog:(id)sender {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[appDelegate.masterContainerViewController showSendToPopover:sender];