Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for ignored tags #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions source/NewtMenulet.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand All @@ -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"];
Expand Down