From e3e0a594da21a2220fd965ec933def2611fc924d Mon Sep 17 00:00:00 2001 From: Adam Siemion Date: Sat, 1 Jun 2013 14:05:44 +0200 Subject: [PATCH] user can define ignored tags by prefxing them with them a minus; questions with any of these tags are ignored --- source/NewtMenulet.m | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/source/NewtMenulet.m b/source/NewtMenulet.m index 27eac8c..01a46bf 100644 --- a/source/NewtMenulet.m +++ b/source/NewtMenulet.m @@ -352,11 +352,27 @@ - (void)processNewQuestions:(NSDictionary *)data NSDictionary *site = [persistence siteForKey:siteKey]; NSString *userId = [site objectForKey:@"user_id"]; - NSArray *interestingTagsArray = [site objectForKey:@"favourite_tags"]; + NSArray *tagsArray = [site objectForKey:@"favourite_tags"]; NSSet *interestingTags = nil; - if (interestingTagsArray != nil && [interestingTagsArray count] > 0) { - interestingTags = [NSSet setWithArray:interestingTagsArray]; - } + NSSet *ignoredTags = nil; + if (tagsArray != nil && [tagsArray count] > 0) { + NSMutableArray *interestingTagsArray = [NSMutableArray arrayWithCapacity:[tagsArray count]]; + NSMutableArray *ignoredTagsArray = [NSMutableArray arrayWithCapacity:[tagsArray count]]; + for(NSString* tag in tagsArray) { + if([tag hasPrefix:@"-"]) { + [ignoredTagsArray addObject:[tag substringFromIndex:1]]; + } else { + [interestingTagsArray addObject:tag]; + } + } + + if([interestingTagsArray count] > 0) { + interestingTags = [NSSet setWithArray:interestingTagsArray]; + } + if([ignoredTagsArray count] > 0) { + ignoredTags = [NSSet setWithArray:ignoredTagsArray]; + } + } for (NSDictionary *question in questions) { NSArray *tags = [question objectForKey:@"tags"]; @@ -366,6 +382,11 @@ - (void)processNewQuestions:(NSDictionary *)data if (interestingTags != nil && ![interestingTags intersectsSet:[NSSet setWithArray:tags]]) { continue; } + + // filter questions by ignored tags + if(ignoredTags != nil && [ignoredTags intersectsSet:[NSSet setWithArray:tags]]) { + continue; + } // do not display questions asked by a current user NSNumber *author = [[question objectForKey:@"owner"] objectForKey:@"user_id"];