Adding custom actions for ios notifications. Needs a custom service target to handle images now.

This commit is contained in:
Samuel Clay 2016-11-21 15:31:14 -08:00
parent 9e6d50b754
commit 8ce74176c3
4 changed files with 112 additions and 10 deletions

View file

@ -233,6 +233,7 @@ class MUserFeedNotification(mongo.Document):
'subtitle': subtitle,
'body': body},
category="STORY_CATEGORY",
mutable_content=True,
custom={'story_hash': story['story_hash'],
'story_feed_id': story['story_feed_id'],
})

View file

@ -1107,6 +1107,11 @@
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
(unsigned long)NULL), ^(void) {
BOOL offlineEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"offline_allowed"];
if (!offlineEnabled) {
NSLog(@"Not saved stories in db, offline not supported.");
return;
}
[appDelegate.database inTransaction:^(FMDatabase *db, BOOL *rollback) {
for (NSDictionary *story in confirmedNewStories) {
[db executeUpdate:@"INSERT into stories"

View file

@ -291,6 +291,7 @@ SFSafariViewControllerDelegate> {
- (void)openUserTagsStory:(id)sender;
- (void)loadFeedDetailView;
- (void)loadFeedDetailView:(BOOL)transition;
- (void)loadFeed:(NSString *)feedId withStory:(NSString *)contentId animated:(BOOL)animated;
- (void)loadTryFeedDetailView:(NSString *)feedId withStory:(NSString *)contentId isSocial:(BOOL)social withUser:(NSDictionary *)user showFindingStory:(BOOL)showHUD;
- (void)loadStarredDetailViewWithStory:(NSString *)contentId showFindingStory:(BOOL)showHUD;
- (void)loadRiverFeedDetailView:(FeedDetailViewController *)feedDetailView withFolder:(NSString *)folder;

View file

@ -341,6 +341,24 @@
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
}];
UNNotificationAction *viewAction = [UNNotificationAction actionWithIdentifier:@"VIEW_STORY_IDENTIFIER"
title:@"View story"
options:UNNotificationActionOptionForeground];
UNNotificationAction *readAction = [UNNotificationAction actionWithIdentifier:@"MARK_READ_IDENTIFIER"
title:@"Mark read"
options:UNNotificationActionOptionNone];
UNNotificationAction *starAction = [UNNotificationAction actionWithIdentifier:@"STAR_IDENTIFIER"
title:@"Save story"
options:UNNotificationActionOptionNone];
UNNotificationAction *dismissAction = [UNNotificationAction actionWithIdentifier:@"DISMISS_IDENTIFIER"
title:@"Dismiss"
options:UNNotificationActionOptionDestructive];
UNNotificationCategory *storyCategory = [UNNotificationCategory categoryWithIdentifier:@"STORY_CATEGORY"
actions:@[viewAction, readAction, starAction, dismissAction]
intentIdentifiers:@[]
options:UNNotificationCategoryOptionNone];
[center setNotificationCategories:[NSSet setWithObject:storyCategory]];
}
//Called when a notification is delivered to a foreground app.
@ -351,21 +369,29 @@
//Called to let your app know which action was selected by the user for a given notification.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{
NSLog(@"User Info : %@", response.notification.request.content.userInfo);
NSLog(@"User Info : %@ / %@", response.notification.request.content.userInfo, response.actionIdentifier);
NSString *storyHash = [response.notification.request.content.userInfo objectForKey:@"story_hash"];
NSString *storyFeedId = [response.notification.request.content.userInfo objectForKey:@"story_feed_id"];
NSNumber *storyFeedId = [response.notification.request.content.userInfo objectForKey:@"story_feed_id"];
NSString *feedIdStr = [NSString stringWithFormat:@"%@", storyFeedId];
if (!self.activeUsername) {
return;
} else {
} else if ([response.actionIdentifier isEqualToString:@"MARK_READ_IDENTIFIER"]) {
[self markStoryAsRead:storyHash inFeed:feedIdStr withCallback:^{
completionHandler();
}];
} else if ([response.actionIdentifier isEqualToString:@"STAR_IDENTIFIER"]) {
[self markStoryAsStarred:storyHash inFeed:feedIdStr withCallback:^{
completionHandler();
}];
} else if ([response.actionIdentifier isEqualToString:@"VIEW_STORY_IDENTIFIER"]) {
[self.navigationController popToRootViewControllerAnimated:NO];
[self loadTryFeedDetailView:storyFeedId
withStory:storyHash
isSocial:NO
withUser:nil
showFindingStory:YES];
self.tryFeedCategory = @"feedsub";
[self loadFeed:feedIdStr withStory:storyHash animated:NO];
completionHandler();
} else if ([response.actionIdentifier isEqualToString:@"DISMISS_IDENTIFIER"]) {
completionHandler();
}
}
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
@ -1013,6 +1039,34 @@
}
- (void)loadFeed:(NSString *)feedId
withStory:(NSString *)contentId
animated:(BOOL)animated {
NSDictionary *feed = [self getFeed:feedId];
self.isTryFeedView = YES;
self.inFindingStoryMode = YES;
self.tryFeedStoryId = contentId;
storiesCollection.isSocialView = NO;
storiesCollection.activeFeed = feed;
storiesCollection.activeFolder = nil;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[self loadFeedDetailView];
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[self.navigationController popToRootViewControllerAnimated:NO];
[self hidePopoverAnimated:NO completion:^{
if (self.navigationController.presentedViewController) {
[self.navigationController dismissViewControllerAnimated:NO completion:^{
[self loadFeedDetailView];
}];
} else {
[self loadFeedDetailView];
}
}];
}
}
- (void)loadTryFeedDetailView:(NSString *)feedId
withStory:(NSString *)contentId
isSocial:(BOOL)social
@ -1035,7 +1089,7 @@
}
storiesCollection.isSocialView = NO;
[self setInFindingStoryMode:NO];
// [self setInFindingStoryMode:NO];
}
self.tryFeedStoryId = contentId;
@ -2000,6 +2054,47 @@
}
}
- (void)markStoryAsRead:(NSString *)storyHash inFeed:(NSString *)feed withCallback:(void(^)())callback {
NSString *urlString = [NSString stringWithFormat:@"%@/reader/mark_story_hashes_as_read",
self.url];
NSURL *url = [NSURL URLWithString:urlString];
__block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:storyHash
forKey:@"story_hash"];
[request setCompletionBlock:^{
NSLog(@"Marked as read: %@", storyHash);
callback();
}];
[request setFailedBlock:^{
NSLog(@"Failed marked as read, queueing: %@", storyHash);
NSMutableDictionary *stories = [NSMutableDictionary dictionary];
[stories setObject:@[storyHash] forKey:feed];
[self queueReadStories:stories];
callback();
}];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)markStoryAsStarred:(NSString *)storyHash inFeed:(NSString *)feed withCallback:(void(^)())callback {
NSString *urlString = [NSString stringWithFormat:@"%@/reader/mark_story_as_starred",
self.url];
NSURL *url = [NSURL URLWithString:urlString];
__block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:storyHash
forKey:@"story_hash"];
[request setCompletionBlock:^{
NSLog(@"Marked as starred: %@", storyHash);
callback();
}];
[request setFailedBlock:^{
NSLog(@"Failed marked as starred: %@", storyHash);
callback();
}];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)markStoriesRead:(NSDictionary *)stories inFeeds:(NSArray *)feeds cutoffTimestamp:(NSInteger)cutoff {
// Must be offline and marking all as read, so load all stories.