mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Updating story counts when saving with user tags. Also saving automatic user tags. Now it just needs ability to add and remove user tags.
This commit is contained in:
parent
8744b7729f
commit
1d58643f33
6 changed files with 74 additions and 35 deletions
|
@ -324,6 +324,7 @@
|
|||
- (void)failedMarkAsSaved:(ASIFormDataRequest *)request;
|
||||
- (void)finishMarkAsUnsaved:(ASIFormDataRequest *)request;
|
||||
- (void)failedMarkAsUnsaved:(ASIFormDataRequest *)request;
|
||||
- (NSArray *)updateStarredStoryCounts:(NSDictionary *)results;
|
||||
|
||||
+ (int)computeStoryScore:(NSDictionary *)intelligence;
|
||||
- (NSString *)extractFolderName:(NSString *)folderName;
|
||||
|
|
|
@ -1951,6 +1951,36 @@
|
|||
[dashboardViewController.storiesModule reloadData];
|
||||
}
|
||||
|
||||
- (NSArray *)updateStarredStoryCounts:(NSDictionary *)results {
|
||||
if ([results objectForKey:@"starred_count"]) {
|
||||
self.savedStoriesCount = [[results objectForKey:@"starred_count"] intValue];
|
||||
}
|
||||
|
||||
if (!self.savedStoriesCount) return [[NSArray alloc] init];
|
||||
|
||||
NSMutableDictionary *savedStoryDict = [[NSMutableDictionary alloc] init];
|
||||
NSMutableArray *savedStories = [NSMutableArray array];
|
||||
|
||||
for (NSDictionary *userTag in [results objectForKey:@"starred_counts"]) {
|
||||
if ([[userTag objectForKey:@"tag"] isKindOfClass:[NSNull class]] ||
|
||||
[[userTag objectForKey:@"tag"] isEqualToString:@""]) continue;
|
||||
NSString *savedTagId = [NSString stringWithFormat:@"saved:%@", [userTag objectForKey:@"tag"]];
|
||||
NSDictionary *savedTag = @{@"ps": [userTag objectForKey:@"count"],
|
||||
@"feed_title": [userTag objectForKey:@"tag"],
|
||||
@"id": [userTag objectForKey:@"tag"],
|
||||
@"tag": [userTag objectForKey:@"tag"]};
|
||||
[savedStories addObject:savedTagId];
|
||||
[savedStoryDict setObject:savedTag forKey:savedTagId];
|
||||
[self.dictUnreadCounts setObject:@{@"ps": [userTag objectForKey:@"count"],
|
||||
@"nt": [NSNumber numberWithInt:0],
|
||||
@"ng": [NSNumber numberWithInt:0]}
|
||||
forKey:savedTagId];
|
||||
}
|
||||
|
||||
self.dictSavedStoryTags = savedStoryDict;
|
||||
|
||||
return savedStories;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Story functions
|
||||
|
|
|
@ -569,7 +569,6 @@ static UIFont *userLabelFont;
|
|||
NSArray *socialFeedsArray = [results objectForKey:@"social_feeds"];
|
||||
NSMutableArray *socialFolder = [[NSMutableArray alloc] init];
|
||||
NSMutableDictionary *socialDict = [[NSMutableDictionary alloc] init];
|
||||
NSMutableDictionary *savedStoryDict = [[NSMutableDictionary alloc] init];
|
||||
NSMutableDictionary *tempActiveFeeds = [[NSMutableDictionary alloc] init];
|
||||
appDelegate.dictActiveFeeds = tempActiveFeeds;
|
||||
|
||||
|
@ -593,28 +592,9 @@ static UIFont *userLabelFont;
|
|||
[allFolders setValue:socialFolder forKey:@"river_blurblogs"];
|
||||
[allFolders setValue:[[NSMutableArray alloc] init] forKey:@"river_global"];
|
||||
|
||||
appDelegate.savedStoriesCount = [[results objectForKey:@"starred_count"] intValue];
|
||||
if (appDelegate.savedStoriesCount) {
|
||||
NSMutableArray *savedStories = [NSMutableArray array];
|
||||
for (NSDictionary *userTag in [results objectForKey:@"starred_counts"]) {
|
||||
if ([[userTag objectForKey:@"tag"] isKindOfClass:[NSNull class]] ||
|
||||
[[userTag objectForKey:@"tag"] isEqualToString:@""]) continue;
|
||||
NSString *savedTagId = [NSString stringWithFormat:@"saved:%@", [userTag objectForKey:@"tag"]];
|
||||
NSDictionary *savedTag = @{@"ps": [userTag objectForKey:@"count"],
|
||||
@"feed_title": [userTag objectForKey:@"tag"],
|
||||
@"id": [userTag objectForKey:@"tag"],
|
||||
@"tag": [userTag objectForKey:@"tag"]};
|
||||
[savedStories addObject:savedTagId];
|
||||
[savedStoryDict setObject:savedTag forKey:savedTagId];
|
||||
[appDelegate.dictUnreadCounts setObject:@{@"ps": [userTag objectForKey:@"count"],
|
||||
@"nt": [NSNumber numberWithInt:0],
|
||||
@"ng": [NSNumber numberWithInt:0]}
|
||||
forKey:savedTagId];
|
||||
}
|
||||
[allFolders setValue:savedStories forKey:@"saved_stories"];
|
||||
appDelegate.dictSavedStoryTags = savedStoryDict;
|
||||
}
|
||||
|
||||
NSArray *savedStories = [appDelegate updateStarredStoryCounts:results];
|
||||
[allFolders setValue:savedStories forKey:@"saved_stories"];
|
||||
|
||||
appDelegate.dictFolders = allFolders;
|
||||
|
||||
// set up dictFeeds
|
||||
|
|
|
@ -93,7 +93,7 @@
|
|||
- (void)markStoryUnread:(NSString *)storyId feedId:(id)feedId;
|
||||
- (void)markStoryUnread:(NSDictionary *)story feed:(NSDictionary *)feed;
|
||||
|
||||
- (void)markStory:story asSaved:(BOOL)saved;
|
||||
- (NSDictionary *)markStory:story asSaved:(BOOL)saved;
|
||||
- (void)toggleStorySaved;
|
||||
- (void)toggleStorySaved:(NSDictionary *)story;
|
||||
- (void)syncStoryAsSaved:(NSDictionary *)story;
|
||||
|
|
|
@ -626,21 +626,21 @@
|
|||
|
||||
- (void)toggleStorySaved:(NSDictionary *)story {
|
||||
BOOL isSaved = [[story objectForKey:@"starred"] boolValue];
|
||||
|
||||
if (isSaved) {
|
||||
[self markStory:story asSaved:NO];
|
||||
story = [self markStory:story asSaved:NO];
|
||||
[self syncStoryAsUnsaved:story];
|
||||
} else {
|
||||
[self markStory:story asSaved:YES];
|
||||
story = [self markStory:story asSaved:YES];
|
||||
[self syncStoryAsSaved:story];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)markStory:(NSDictionary *)story asSaved:(BOOL)saved {
|
||||
NSLog(@"Saving in folders: %@", [appDelegate parentFoldersForFeed:[story objectForKey:@"story_feed_id"]]);
|
||||
- (NSDictionary *)markStory:(NSDictionary *)story asSaved:(BOOL)saved {
|
||||
NSMutableDictionary *newStory = [[appDelegate getStory:[story objectForKey:@"story_hash"]] mutableCopy];
|
||||
[newStory setValue:[NSNumber numberWithBool:saved] forKey:@"starred"];
|
||||
if (saved) {
|
||||
[newStory setValue:[Utilities formatLongDateFromTimestamp:nil] forKey:@"starred_date"];
|
||||
[newStory setObject:[Utilities formatLongDateFromTimestamp:nil] forKey:@"starred_date"];
|
||||
} else {
|
||||
[newStory removeObjectForKey:@"starred_date"];
|
||||
}
|
||||
|
@ -650,6 +650,13 @@
|
|||
appDelegate.activeStory = newStory;
|
||||
}
|
||||
|
||||
// Add folder tags if no user tags
|
||||
if (![story objectForKey:@"user_tags"]) {
|
||||
NSArray *parentFolders = [appDelegate parentFoldersForFeed:[story objectForKey:@"story_feed_id"]];
|
||||
NSLog(@"Saving in folders: %@", parentFolders);
|
||||
[newStory setObject:parentFolders forKey:@"user_tags"];
|
||||
}
|
||||
|
||||
// make the story as read in self.activeFeedStories
|
||||
NSString *newStoryIdStr = [NSString stringWithFormat:@"%@", [newStory valueForKey:@"story_hash"]];
|
||||
NSMutableArray *newActiveFeedStories = [self.activeFeedStories mutableCopy];
|
||||
|
@ -668,6 +675,8 @@
|
|||
} else {
|
||||
appDelegate.savedStoriesCount -= 1;
|
||||
}
|
||||
|
||||
return newStory;
|
||||
}
|
||||
|
||||
- (void)syncStoryAsSaved:(NSDictionary *)story {
|
||||
|
@ -676,12 +685,14 @@
|
|||
NSURL *url = [NSURL URLWithString:urlString];
|
||||
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
||||
|
||||
[request setPostValue:[story
|
||||
objectForKey:@"story_hash"]
|
||||
[request setPostValue:[story objectForKey:@"story_hash"]
|
||||
forKey:@"story_id"];
|
||||
[request setPostValue:[story
|
||||
objectForKey:@"story_feed_id"]
|
||||
[request setPostValue:[story objectForKey:@"story_feed_id"]
|
||||
forKey:@"feed_id"];
|
||||
for (NSString *userTag in [story objectForKey:@"user_tags"]) {
|
||||
[request addPostValue:userTag
|
||||
forKey:@"user_tags"];
|
||||
}
|
||||
|
||||
[request setDidFinishSelector:@selector(finishMarkAsSaved:)];
|
||||
[request setDidFailSelector:@selector(requestFailed:)];
|
||||
|
@ -697,10 +708,26 @@
|
|||
if ([request responseStatusCode] != 200) {
|
||||
return [self failedMarkAsSaved:request];
|
||||
}
|
||||
|
||||
|
||||
[self updateSavedStoryCounts:request];
|
||||
|
||||
[appDelegate finishMarkAsSaved:request];
|
||||
}
|
||||
|
||||
- (void)updateSavedStoryCounts:(ASIFormDataRequest *)request {
|
||||
NSString *responseString = [request responseString];
|
||||
NSData *responseData=[responseString dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSError *error;
|
||||
NSDictionary *results = [NSJSONSerialization
|
||||
JSONObjectWithData:responseData
|
||||
options:kNilOptions
|
||||
error:&error];
|
||||
NSArray *savedStories = [appDelegate updateStarredStoryCounts:results];
|
||||
NSMutableDictionary *allFolders = [appDelegate.dictFolders mutableCopy];
|
||||
[allFolders setValue:savedStories forKey:@"saved_stories"];
|
||||
appDelegate.dictFolders = allFolders;
|
||||
}
|
||||
|
||||
- (void)failedMarkAsSaved:(ASIFormDataRequest *)request {
|
||||
[self markStory:request.userInfo asSaved:NO];
|
||||
|
||||
|
@ -735,6 +762,7 @@
|
|||
return [self failedMarkAsUnsaved:request];
|
||||
}
|
||||
|
||||
[self updateSavedStoryCounts:request];
|
||||
[appDelegate finishMarkAsUnsaved:request];
|
||||
}
|
||||
|
||||
|
|
|
@ -389,7 +389,7 @@ body.NB-iphone {
|
|||
}
|
||||
|
||||
.NB-story-starred-date {
|
||||
margin: 4px 0 0 0;
|
||||
margin: 6px 0 0 0;
|
||||
padding: 0 0 0 20px;
|
||||
background: transparent url("data:image/png;charset=utf-8;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAAEx0lEQVRYCc1YQWhcRRj+Z95umwRJIRgREQ3VU0XjTfSkEbF681TUigdBIXTT3ZCm7aVLDlKbDdlttyxW8CBqtCdvKorWm3gSFT1piR4UDCx0kWaT7J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gh0BVLjnPFYvEvzAMWMF0MrOm+TCwhOOF1wBUEebfwvb+/K674/IwtSw1S256e0n7u3uLcwpvhHAEsYDoYO+Ga1hTRQ7BerK8sc3XKenBDCFphgQYhxXj/qggWaMuuQAtRKicLXVwL2qcY8VRhCXuUI9+qRgCxuLpnHyRs2TIJG307BPteinzETOyYsMQGK8UnXKUII0oiIQzUapVHhSe+4Gbk5YExnrYuhP7I1/ob6uR+brVa3WfQ+Pj4JOU6DyHPBFc7cpuCqUxGkny2UJj/3hjceiAhOP0fD8XILXOZoo13E54q3Kzwz94+jO2yYG4FWElvMRcrdYdcR7xI8AjgYIfudqSu69XX3vt/NsSXgCA/uCWf54T2FP+mQ3FltBSS63V8m/h3beug+tRNenGspH7mHUqavB+21BjajwWHYd4CVCEE1ECzPqUAAAAASUVORK5CYII=") no-repeat 0 0;
|
||||
background-size: 16px;
|
||||
|
|
Loading…
Add table
Reference in a new issue