2014-08-01 07:53:58 +02:00
|
|
|
|
//
|
2018-01-26 22:23:39 +01:00
|
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
2014-08-01 07:53:58 +02:00
|
|
|
|
//
|
2015-04-14 21:49:00 +02:00
|
|
|
|
|
2016-10-14 22:59:58 +02:00
|
|
|
|
#import "PushManager.h"
|
2015-09-01 19:22:08 +02:00
|
|
|
|
#import "AppDelegate.h"
|
2017-11-06 18:37:15 +01:00
|
|
|
|
#import "NotificationsManager.h"
|
2016-12-20 23:44:11 +01:00
|
|
|
|
#import "Signal-Swift.h"
|
2017-12-01 21:17:29 +01:00
|
|
|
|
#import "SignalApp.h"
|
2017-07-14 15:27:52 +02:00
|
|
|
|
#import "ThreadUtil.h"
|
2017-12-19 03:50:51 +01:00
|
|
|
|
#import <SignalMessaging/OWSContactsManager.h>
|
2018-01-26 22:23:39 +01:00
|
|
|
|
#import <SignalServiceKit/AppReadiness.h>
|
2017-09-22 16:30:35 +02:00
|
|
|
|
#import <SignalServiceKit/NSDate+OWS.h>
|
2018-02-16 02:45:28 +01:00
|
|
|
|
#import <SignalServiceKit/NSString+SSK.h>
|
2017-11-16 15:54:55 +01:00
|
|
|
|
#import <SignalServiceKit/OWSDevice.h>
|
2017-07-25 00:05:26 +02:00
|
|
|
|
#import <SignalServiceKit/OWSMessageReceiver.h>
|
2016-10-14 22:59:58 +02:00
|
|
|
|
#import <SignalServiceKit/OWSMessageSender.h>
|
2017-09-26 17:45:22 +02:00
|
|
|
|
#import <SignalServiceKit/OWSReadReceiptManager.h>
|
2016-12-20 23:44:11 +01:00
|
|
|
|
#import <SignalServiceKit/OWSSignalService.h>
|
2017-05-27 02:41:27 +02:00
|
|
|
|
#import <SignalServiceKit/TSAccountManager.h>
|
2017-09-21 23:09:55 +02:00
|
|
|
|
#import <SignalServiceKit/TSIncomingMessage.h>
|
2017-05-27 02:41:27 +02:00
|
|
|
|
#import <SignalServiceKit/TSOutgoingMessage.h>
|
|
|
|
|
#import <SignalServiceKit/TSSocketManager.h>
|
2014-08-01 07:53:58 +02:00
|
|
|
|
|
2017-05-31 17:49:30 +02:00
|
|
|
|
NSString *const Signal_Thread_UserInfo_Key = @"Signal_Thread_Id";
|
|
|
|
|
NSString *const Signal_Message_UserInfo_Key = @"Signal_Message_Id";
|
|
|
|
|
|
|
|
|
|
NSString *const Signal_Full_New_Message_Category = @"Signal_Full_New_Message";
|
2017-06-23 19:55:21 +02:00
|
|
|
|
NSString *const Signal_Full_New_Message_Category_No_Longer_Verified =
|
|
|
|
|
@"Signal_Full_New_Message_Category_No_Longer_Verified";
|
2017-05-31 17:49:30 +02:00
|
|
|
|
|
|
|
|
|
NSString *const Signal_Message_Reply_Identifier = @"Signal_New_Message_Reply";
|
|
|
|
|
NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRead";
|
2015-02-20 17:02:31 +01:00
|
|
|
|
|
2016-09-14 18:19:05 +02:00
|
|
|
|
@interface PushManager ()
|
2014-08-01 07:53:58 +02:00
|
|
|
|
|
2017-05-09 16:04:48 +02:00
|
|
|
|
@property (nonatomic) NSMutableArray *currentNotifications;
|
2015-04-14 21:49:00 +02:00
|
|
|
|
@property (nonatomic) UIBackgroundTaskIdentifier callBackgroundTask;
|
2016-10-14 22:59:58 +02:00
|
|
|
|
@property (nonatomic, readonly) OWSMessageSender *messageSender;
|
2016-12-20 23:44:11 +01:00
|
|
|
|
@property (nonatomic, readonly) OWSMessageFetcherJob *messageFetcherJob;
|
2017-11-06 18:37:15 +01:00
|
|
|
|
@property (nonatomic, readonly) NotificationsManager *notificationsManager;
|
2015-09-01 19:22:08 +02:00
|
|
|
|
|
2014-08-01 07:53:58 +02:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation PushManager
|
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
|
+ (instancetype)sharedManager {
|
2014-08-01 07:53:58 +02:00
|
|
|
|
static PushManager *sharedManager = nil;
|
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
|
dispatch_once(&onceToken, ^{
|
2016-10-14 22:59:58 +02:00
|
|
|
|
sharedManager = [[self alloc] initDefault];
|
2014-08-01 07:53:58 +02:00
|
|
|
|
});
|
|
|
|
|
return sharedManager;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-14 22:59:58 +02:00
|
|
|
|
- (instancetype)initDefault
|
|
|
|
|
{
|
2017-12-04 16:35:47 +01:00
|
|
|
|
return [self initWithMessageFetcherJob:SignalApp.sharedApp.messageFetcherJob
|
2018-03-05 15:30:58 +01:00
|
|
|
|
primaryStorage:[OWSPrimaryStorage sharedManager]
|
2017-12-04 16:35:47 +01:00
|
|
|
|
messageSender:[Environment current].messageSender
|
|
|
|
|
notificationsManager:SignalApp.sharedApp.notificationsManager];
|
2016-10-14 22:59:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-06 18:03:41 +02:00
|
|
|
|
- (instancetype)initWithMessageFetcherJob:(OWSMessageFetcherJob *)messageFetcherJob
|
2018-03-05 15:30:58 +01:00
|
|
|
|
primaryStorage:(OWSPrimaryStorage *)primaryStorage
|
2017-10-06 18:03:41 +02:00
|
|
|
|
messageSender:(OWSMessageSender *)messageSender
|
2017-11-06 18:37:15 +01:00
|
|
|
|
notificationsManager:(NotificationsManager *)notificationsManager
|
2016-10-14 22:59:58 +02:00
|
|
|
|
{
|
2014-10-29 14:25:41 +01:00
|
|
|
|
self = [super init];
|
2016-09-11 22:53:12 +02:00
|
|
|
|
if (!self) {
|
|
|
|
|
return self;
|
2014-10-29 14:25:41 +01:00
|
|
|
|
}
|
2016-09-11 22:53:12 +02:00
|
|
|
|
|
2017-03-30 18:51:48 +02:00
|
|
|
|
_messageSender = messageSender;
|
2017-10-06 18:03:41 +02:00
|
|
|
|
_messageFetcherJob = messageFetcherJob;
|
2016-09-11 22:53:12 +02:00
|
|
|
|
_callBackgroundTask = UIBackgroundTaskInvalid;
|
Rework push registration
== Account Registration ==
Not complete until push tokens are uploaded
== Remote Notifications Registration ==
Extracted from PushManager
- wait for notification-settings registration to complete before
requesting push tokens, otherwise it's possible token requests will
be ignored.
- Less state required for push notification callbacks, specifically, we
no longer need to ensure we've created a promise before the
registration delegate methods get called.
- no more TOCFuture in Signal-iOS (still in SSK for now). It's not in
cases of inexplicable behavior - one a recently, push notification
premature free, in redphone, and more popular use, and I've seen two
futures inexplicably being nil. Instead, let's consolidate around
PromiseKit for popularly used, maintained, strongly-typed futures.
- separate logic for registering for vanilla push/voip notifications
(few dependencies) from responding to UILocalNotifications (lots of
dependencies). Ultimately I'd like to consolidate the remaining
UILocalNotifications logic with the existing NotificationsManager
== Misc ==
more debug logging
more uniform logging
remove stale logic around newly registered user
// FREEBIE
2017-09-20 23:47:12 +02:00
|
|
|
|
// TODO: consolidate notification tracking with NotificationsManager, which also maintains a list of notifications.
|
2017-04-12 16:03:09 +02:00
|
|
|
|
_currentNotifications = [NSMutableArray array];
|
2017-11-06 18:37:15 +01:00
|
|
|
|
_notificationsManager = notificationsManager;
|
2016-09-11 22:53:12 +02:00
|
|
|
|
|
2017-04-01 00:36:30 +02:00
|
|
|
|
OWSSingletonAssert();
|
|
|
|
|
|
2017-09-14 23:06:35 +02:00
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
|
selector:@selector(handleMessageRead:)
|
2017-09-27 20:05:21 +02:00
|
|
|
|
name:kIncomingMessageMarkedAsReadNotification
|
2017-09-14 23:06:35 +02:00
|
|
|
|
object:nil];
|
|
|
|
|
|
2014-10-29 14:25:41 +01:00
|
|
|
|
return self;
|
|
|
|
|
}
|
2014-10-07 00:04:50 +02:00
|
|
|
|
|
2018-03-08 00:09:07 +01:00
|
|
|
|
- (CallUIAdapter *)callUIAdapter
|
|
|
|
|
{
|
|
|
|
|
return SignalApp.sharedApp.callService.callUIAdapter;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-14 23:06:35 +02:00
|
|
|
|
- (void)handleMessageRead:(NSNotification *)notification
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-09-26 17:45:22 +02:00
|
|
|
|
|
2017-09-14 23:06:35 +02:00
|
|
|
|
if ([notification.object isKindOfClass:[TSIncomingMessage class]]) {
|
|
|
|
|
TSIncomingMessage *message = (TSIncomingMessage *)notification.object;
|
|
|
|
|
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogDebug(@"%@ canceled notification for message:%@", self.logTag, message);
|
2017-09-14 23:06:35 +02:00
|
|
|
|
[self cancelNotificationsWithThreadId:message.uniqueThreadId];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-14 21:49:00 +02:00
|
|
|
|
#pragma mark Manage Incoming Push
|
|
|
|
|
|
Rework push registration
== Account Registration ==
Not complete until push tokens are uploaded
== Remote Notifications Registration ==
Extracted from PushManager
- wait for notification-settings registration to complete before
requesting push tokens, otherwise it's possible token requests will
be ignored.
- Less state required for push notification callbacks, specifically, we
no longer need to ensure we've created a promise before the
registration delegate methods get called.
- no more TOCFuture in Signal-iOS (still in SSK for now). It's not in
cases of inexplicable behavior - one a recently, push notification
premature free, in redphone, and more popular use, and I've seen two
futures inexplicably being nil. Instead, let's consolidate around
PromiseKit for popularly used, maintained, strongly-typed futures.
- separate logic for registering for vanilla push/voip notifications
(few dependencies) from responding to UILocalNotifications (lots of
dependencies). Ultimately I'd like to consolidate the remaining
UILocalNotifications logic with the existing NotificationsManager
== Misc ==
more debug logging
more uniform logging
remove stale logic around newly registered user
// FREEBIE
2017-09-20 23:47:12 +02:00
|
|
|
|
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
|
|
|
|
|
{
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogInfo(@"%@ received remote notification", self.logTag);
|
2016-12-20 23:44:11 +01:00
|
|
|
|
|
2018-01-26 22:23:39 +01:00
|
|
|
|
[AppReadiness runNowOrWhenAppIsReady:^{
|
|
|
|
|
[self.messageFetcherJob run];
|
|
|
|
|
}];
|
2015-04-14 21:49:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-03 23:09:50 +01:00
|
|
|
|
- (void)applicationDidBecomeActive {
|
2018-01-26 22:23:39 +01:00
|
|
|
|
[AppReadiness runNowOrWhenAppIsReady:^{
|
|
|
|
|
[self.messageFetcherJob run];
|
|
|
|
|
}];
|
2017-01-03 23:09:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-14 21:49:00 +02:00
|
|
|
|
/**
|
2015-12-22 12:45:09 +01:00
|
|
|
|
* This code should in principle never be called. The only cases where it would be called are with the old-style
|
|
|
|
|
* "content-available:1" pushes if there is no "voip" token registered
|
2015-04-14 21:49:00 +02:00
|
|
|
|
*
|
|
|
|
|
*/
|
2015-12-22 12:45:09 +01:00
|
|
|
|
- (void)application:(UIApplication *)application
|
|
|
|
|
didReceiveRemoteNotification:(NSDictionary *)userInfo
|
Rework push registration
== Account Registration ==
Not complete until push tokens are uploaded
== Remote Notifications Registration ==
Extracted from PushManager
- wait for notification-settings registration to complete before
requesting push tokens, otherwise it's possible token requests will
be ignored.
- Less state required for push notification callbacks, specifically, we
no longer need to ensure we've created a promise before the
registration delegate methods get called.
- no more TOCFuture in Signal-iOS (still in SSK for now). It's not in
cases of inexplicable behavior - one a recently, push notification
premature free, in redphone, and more popular use, and I've seen two
futures inexplicably being nil. Instead, let's consolidate around
PromiseKit for popularly used, maintained, strongly-typed futures.
- separate logic for registering for vanilla push/voip notifications
(few dependencies) from responding to UILocalNotifications (lots of
dependencies). Ultimately I'd like to consolidate the remaining
UILocalNotifications logic with the existing NotificationsManager
== Misc ==
more debug logging
more uniform logging
remove stale logic around newly registered user
// FREEBIE
2017-09-20 23:47:12 +02:00
|
|
|
|
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
|
|
|
|
|
{
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogInfo(@"%@ received content-available push", self.logTag);
|
Rework push registration
== Account Registration ==
Not complete until push tokens are uploaded
== Remote Notifications Registration ==
Extracted from PushManager
- wait for notification-settings registration to complete before
requesting push tokens, otherwise it's possible token requests will
be ignored.
- Less state required for push notification callbacks, specifically, we
no longer need to ensure we've created a promise before the
registration delegate methods get called.
- no more TOCFuture in Signal-iOS (still in SSK for now). It's not in
cases of inexplicable behavior - one a recently, push notification
premature free, in redphone, and more popular use, and I've seen two
futures inexplicably being nil. Instead, let's consolidate around
PromiseKit for popularly used, maintained, strongly-typed futures.
- separate logic for registering for vanilla push/voip notifications
(few dependencies) from responding to UILocalNotifications (lots of
dependencies). Ultimately I'd like to consolidate the remaining
UILocalNotifications logic with the existing NotificationsManager
== Misc ==
more debug logging
more uniform logging
remove stale logic around newly registered user
// FREEBIE
2017-09-20 23:47:12 +02:00
|
|
|
|
|
|
|
|
|
// If we want to re-introduce silent pushes we can remove this assert.
|
|
|
|
|
OWSFail(@"Unexpected content-available push.");
|
2016-12-20 23:44:11 +01:00
|
|
|
|
|
2018-01-29 17:25:23 +01:00
|
|
|
|
[AppReadiness runNowOrWhenAppIsReady:^{
|
|
|
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 20 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
|
|
|
|
completionHandler(UIBackgroundFetchResultNewData);
|
|
|
|
|
});
|
|
|
|
|
}];
|
2015-04-14 21:49:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
Rework push registration
== Account Registration ==
Not complete until push tokens are uploaded
== Remote Notifications Registration ==
Extracted from PushManager
- wait for notification-settings registration to complete before
requesting push tokens, otherwise it's possible token requests will
be ignored.
- Less state required for push notification callbacks, specifically, we
no longer need to ensure we've created a promise before the
registration delegate methods get called.
- no more TOCFuture in Signal-iOS (still in SSK for now). It's not in
cases of inexplicable behavior - one a recently, push notification
premature free, in redphone, and more popular use, and I've seen two
futures inexplicably being nil. Instead, let's consolidate around
PromiseKit for popularly used, maintained, strongly-typed futures.
- separate logic for registering for vanilla push/voip notifications
(few dependencies) from responding to UILocalNotifications (lots of
dependencies). Ultimately I'd like to consolidate the remaining
UILocalNotifications logic with the existing NotificationsManager
== Misc ==
more debug logging
more uniform logging
remove stale logic around newly registered user
// FREEBIE
2017-09-20 23:47:12 +02:00
|
|
|
|
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogInfo(@"%@ launched from local notification", self.logTag);
|
2016-12-20 23:44:11 +01:00
|
|
|
|
|
2017-09-30 23:59:19 +02:00
|
|
|
|
NSString *_Nullable threadId = notification.userInfo[Signal_Thread_UserInfo_Key];
|
2017-09-28 17:39:25 +02:00
|
|
|
|
|
|
|
|
|
if (threadId) {
|
2017-12-01 21:17:29 +01:00
|
|
|
|
[SignalApp.sharedApp presentConversationForThreadId:threadId];
|
2017-09-28 17:39:25 +02:00
|
|
|
|
} else {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ threadId was unexpectedly nil in %s", self.logTag, __PRETTY_FUNCTION__);
|
2015-04-14 21:49:00 +02:00
|
|
|
|
}
|
2017-11-06 18:37:15 +01:00
|
|
|
|
|
|
|
|
|
// We only want to receive a single local notification per launch.
|
|
|
|
|
[application cancelAllLocalNotifications];
|
|
|
|
|
[self.currentNotifications removeAllObjects];
|
|
|
|
|
[self.notificationsManager clearAllNotifications];
|
2015-04-14 21:49:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
|
- (void)application:(UIApplication *)application
|
|
|
|
|
handleActionWithIdentifier:(NSString *)identifier
|
|
|
|
|
forLocalNotification:(UILocalNotification *)notification
|
2017-11-08 20:04:51 +01:00
|
|
|
|
completionHandler:(void (^)(void))completionHandler
|
Rework push registration
== Account Registration ==
Not complete until push tokens are uploaded
== Remote Notifications Registration ==
Extracted from PushManager
- wait for notification-settings registration to complete before
requesting push tokens, otherwise it's possible token requests will
be ignored.
- Less state required for push notification callbacks, specifically, we
no longer need to ensure we've created a promise before the
registration delegate methods get called.
- no more TOCFuture in Signal-iOS (still in SSK for now). It's not in
cases of inexplicable behavior - one a recently, push notification
premature free, in redphone, and more popular use, and I've seen two
futures inexplicably being nil. Instead, let's consolidate around
PromiseKit for popularly used, maintained, strongly-typed futures.
- separate logic for registering for vanilla push/voip notifications
(few dependencies) from responding to UILocalNotifications (lots of
dependencies). Ultimately I'd like to consolidate the remaining
UILocalNotifications logic with the existing NotificationsManager
== Misc ==
more debug logging
more uniform logging
remove stale logic around newly registered user
// FREEBIE
2017-09-20 23:47:12 +02:00
|
|
|
|
{
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogInfo(@"%@ in %s", self.logTag, __FUNCTION__);
|
2016-12-20 23:44:11 +01:00
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
|
[self application:application
|
|
|
|
|
handleActionWithIdentifier:identifier
|
|
|
|
|
forLocalNotification:notification
|
|
|
|
|
withResponseInfo:@{}
|
|
|
|
|
completionHandler:completionHandler];
|
2015-09-01 19:22:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
|
- (void)application:(UIApplication *)application
|
|
|
|
|
handleActionWithIdentifier:(NSString *)identifier
|
|
|
|
|
forLocalNotification:(UILocalNotification *)notification
|
|
|
|
|
withResponseInfo:(NSDictionary *)responseInfo
|
2017-11-08 20:04:51 +01:00
|
|
|
|
completionHandler:(void (^)(void))completionHandler
|
2016-08-01 00:25:07 +02:00
|
|
|
|
{
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogInfo(@"%@ handling action with identifier: %@", self.logTag, identifier);
|
2016-12-20 23:44:11 +01:00
|
|
|
|
|
2015-09-01 19:22:08 +02:00
|
|
|
|
if ([identifier isEqualToString:Signal_Message_Reply_Identifier]) {
|
|
|
|
|
NSString *threadId = notification.userInfo[Signal_Thread_UserInfo_Key];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2015-09-01 19:22:08 +02:00
|
|
|
|
if (threadId) {
|
|
|
|
|
TSThread *thread = [TSThread fetchObjectWithUniqueID:threadId];
|
2017-07-14 15:27:52 +02:00
|
|
|
|
NSString *replyText = responseInfo[UIUserNotificationActionResponseTypedTextKey];
|
|
|
|
|
|
2018-04-09 15:15:48 +02:00
|
|
|
|
// In line with most apps, we send a normal outgoing messgae here - not a "quoted reply".
|
2017-07-14 15:27:52 +02:00
|
|
|
|
[ThreadUtil sendMessageWithText:replyText
|
|
|
|
|
inThread:thread
|
2018-04-09 15:15:48 +02:00
|
|
|
|
quotedReplyModel:nil
|
2017-07-14 15:27:52 +02:00
|
|
|
|
messageSender:self.messageSender
|
2015-12-22 12:45:09 +01:00
|
|
|
|
success:^{
|
2017-05-31 17:49:30 +02:00
|
|
|
|
// TODO do we really want to mark them all as read?
|
2016-10-14 22:59:58 +02:00
|
|
|
|
[self markAllInThreadAsRead:notification.userInfo completionHandler:completionHandler];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
}
|
2017-07-14 15:27:52 +02:00
|
|
|
|
failure:^(NSError *_Nonnull error) {
|
2016-10-14 22:59:58 +02:00
|
|
|
|
// TODO Surface the specific error in the notification?
|
|
|
|
|
DDLogError(@"Message send failed with error: %@", error);
|
|
|
|
|
|
|
|
|
|
UILocalNotification *failedSendNotif = [[UILocalNotification alloc] init];
|
|
|
|
|
failedSendNotif.alertBody =
|
2018-02-16 02:45:28 +01:00
|
|
|
|
[NSString stringWithFormat:NSLocalizedString(@"NOTIFICATION_SEND_FAILED", nil), [thread name]]
|
|
|
|
|
.filterStringForDisplay;
|
2016-10-14 22:59:58 +02:00
|
|
|
|
failedSendNotif.userInfo = @{ Signal_Thread_UserInfo_Key : thread.uniqueId };
|
2017-04-05 17:13:09 +02:00
|
|
|
|
[self presentNotification:failedSendNotif checkForCancel:NO];
|
2016-10-14 22:59:58 +02:00
|
|
|
|
completionHandler();
|
2015-12-22 12:45:09 +01:00
|
|
|
|
}];
|
2015-09-01 19:22:08 +02:00
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
} else if ([identifier isEqualToString:Signal_Message_MarkAsRead_Identifier]) {
|
2017-05-31 17:49:30 +02:00
|
|
|
|
// TODO mark all as read? Or just this one?
|
2015-09-01 19:22:08 +02:00
|
|
|
|
[self markAllInThreadAsRead:notification.userInfo completionHandler:completionHandler];
|
2016-11-12 18:22:29 +01:00
|
|
|
|
} else if ([identifier isEqualToString:PushManagerActionsAcceptCall]) {
|
|
|
|
|
NSString *localIdString = notification.userInfo[PushManagerUserInfoKeysLocalCallId];
|
|
|
|
|
if (!localIdString) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogError(@"%@ missing localIdString.", self.logTag);
|
2016-11-12 18:22:29 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSUUID *localId = [[NSUUID alloc] initWithUUIDString:localIdString];
|
|
|
|
|
if (!localId) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogError(@"%@ localIdString failed to parse as UUID.", self.logTag);
|
2016-11-12 18:22:29 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-18 21:17:55 +01:00
|
|
|
|
[self.callUIAdapter answerCallWithLocalId:localId];
|
2017-05-31 17:49:30 +02:00
|
|
|
|
completionHandler();
|
2016-11-12 18:22:29 +01:00
|
|
|
|
} else if ([identifier isEqualToString:PushManagerActionsDeclineCall]) {
|
|
|
|
|
NSString *localIdString = notification.userInfo[PushManagerUserInfoKeysLocalCallId];
|
|
|
|
|
if (!localIdString) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogError(@"%@ missing localIdString.", self.logTag);
|
2016-11-12 18:22:29 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSUUID *localId = [[NSUUID alloc] initWithUUIDString:localIdString];
|
|
|
|
|
if (!localId) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogError(@"%@ localIdString failed to parse as UUID.", self.logTag);
|
2016-11-12 18:22:29 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-18 21:17:55 +01:00
|
|
|
|
[self.callUIAdapter declineCallWithLocalId:localId];
|
2017-05-31 17:49:30 +02:00
|
|
|
|
completionHandler();
|
2016-11-12 18:22:29 +01:00
|
|
|
|
} else if ([identifier isEqualToString:PushManagerActionsCallBack]) {
|
2017-05-31 17:49:30 +02:00
|
|
|
|
NSString *recipientId = notification.userInfo[PushManagerUserInfoKeysCallBackSignalRecipientId];
|
|
|
|
|
if (!recipientId) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogError(@"%@ missing call back id", self.logTag);
|
2017-05-31 17:49:30 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2016-11-12 18:22:29 +01:00
|
|
|
|
|
2017-05-31 17:49:30 +02:00
|
|
|
|
[self.callUIAdapter startAndShowOutgoingCallWithRecipientId:recipientId];
|
|
|
|
|
completionHandler();
|
|
|
|
|
} else if ([identifier isEqualToString:PushManagerActionsShowThread]) {
|
|
|
|
|
NSString *threadId = notification.userInfo[Signal_Thread_UserInfo_Key];
|
2017-09-28 17:39:25 +02:00
|
|
|
|
|
|
|
|
|
if (threadId) {
|
2017-12-01 21:17:29 +01:00
|
|
|
|
[SignalApp.sharedApp presentConversationForThreadId:threadId];
|
2017-09-28 17:39:25 +02:00
|
|
|
|
} else {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ threadId was unexpectedly nil in action with identifier: %@", self.logTag, identifier);
|
2017-09-28 17:39:25 +02:00
|
|
|
|
}
|
2017-05-31 17:49:30 +02:00
|
|
|
|
completionHandler();
|
2015-09-01 19:22:08 +02:00
|
|
|
|
} else {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ Unhandled action with identifier: %@", self.logTag, identifier);
|
2015-09-01 19:22:08 +02:00
|
|
|
|
NSString *threadId = notification.userInfo[Signal_Thread_UserInfo_Key];
|
2017-09-28 17:39:25 +02:00
|
|
|
|
if (threadId) {
|
2017-12-01 21:17:29 +01:00
|
|
|
|
[SignalApp.sharedApp presentConversationForThreadId:threadId];
|
2017-09-28 17:39:25 +02:00
|
|
|
|
} else {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ threadId was unexpectedly nil in action with identifier: %@", self.logTag, identifier);
|
2017-09-28 17:39:25 +02:00
|
|
|
|
}
|
2015-04-14 21:49:00 +02:00
|
|
|
|
completionHandler();
|
|
|
|
|
}
|
2015-09-01 19:22:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-08 20:04:51 +01:00
|
|
|
|
- (void)markAllInThreadAsRead:(NSDictionary *)userInfo completionHandler:(void (^)(void))completionHandler
|
|
|
|
|
{
|
2015-09-01 19:22:08 +02:00
|
|
|
|
NSString *threadId = userInfo[Signal_Thread_UserInfo_Key];
|
2018-04-17 21:23:05 +02:00
|
|
|
|
if (!threadId) {
|
2018-04-24 19:43:38 +02:00
|
|
|
|
OWSProdLogAndFail(@"%@ missing thread id for notification.", self.logTag);
|
2018-04-17 21:23:05 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2015-09-01 19:22:08 +02:00
|
|
|
|
TSThread *thread = [TSThread fetchObjectWithUniqueID:threadId];
|
2018-03-05 15:30:58 +01:00
|
|
|
|
[OWSPrimaryStorage.dbReadWriteConnection
|
2017-06-12 17:52:21 +02:00
|
|
|
|
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
|
|
|
|
// TODO: I suspect we only want to mark the message in
|
|
|
|
|
// question as read.
|
|
|
|
|
[thread markAllAsReadWithTransaction:transaction];
|
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
completionBlock:^{
|
2017-06-12 17:52:21 +02:00
|
|
|
|
[self cancelNotificationsWithThreadId:threadId];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2017-06-12 17:52:21 +02:00
|
|
|
|
completionHandler();
|
2015-12-22 12:45:09 +01:00
|
|
|
|
}];
|
2015-04-14 21:49:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
|
- (UIUserNotificationCategory *)fullNewMessageNotificationCategory {
|
2017-06-23 19:55:21 +02:00
|
|
|
|
UIMutableUserNotificationAction *action_markRead = [self markAsReadAction];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
|
|
|
|
UIMutableUserNotificationAction *action_reply = [UIMutableUserNotificationAction new];
|
|
|
|
|
action_reply.identifier = Signal_Message_Reply_Identifier;
|
|
|
|
|
action_reply.title = NSLocalizedString(@"PUSH_MANAGER_REPLY", @"");
|
|
|
|
|
action_reply.destructive = NO;
|
2017-05-26 04:19:20 +02:00
|
|
|
|
action_reply.authenticationRequired = NO;
|
2018-02-23 18:46:04 +01:00
|
|
|
|
action_reply.behavior = UIUserNotificationActionBehaviorTextInput;
|
|
|
|
|
action_reply.activationMode = UIUserNotificationActivationModeBackground;
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2015-04-14 21:49:00 +02:00
|
|
|
|
UIMutableUserNotificationCategory *messageCategory = [UIMutableUserNotificationCategory new];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
messageCategory.identifier = Signal_Full_New_Message_Category;
|
|
|
|
|
[messageCategory setActions:@[ action_markRead, action_reply ] forContext:UIUserNotificationActionContextMinimal];
|
2017-05-26 04:19:20 +02:00
|
|
|
|
[messageCategory setActions:@[ action_markRead, action_reply ] forContext:UIUserNotificationActionContextDefault];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2015-04-14 21:49:00 +02:00
|
|
|
|
return messageCategory;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-23 19:55:21 +02:00
|
|
|
|
- (UIUserNotificationCategory *)fullNewMessageNoLongerVerifiedNotificationCategory
|
|
|
|
|
{
|
|
|
|
|
UIMutableUserNotificationAction *action_markRead = [self markAsReadAction];
|
|
|
|
|
|
|
|
|
|
UIMutableUserNotificationCategory *messageCategory = [UIMutableUserNotificationCategory new];
|
|
|
|
|
messageCategory.identifier = Signal_Full_New_Message_Category_No_Longer_Verified;
|
|
|
|
|
[messageCategory setActions:@[ action_markRead ] forContext:UIUserNotificationActionContextMinimal];
|
|
|
|
|
[messageCategory setActions:@[ action_markRead ] forContext:UIUserNotificationActionContextDefault];
|
|
|
|
|
|
|
|
|
|
return messageCategory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (UIMutableUserNotificationAction *)markAsReadAction
|
|
|
|
|
{
|
|
|
|
|
UIMutableUserNotificationAction *action = [UIMutableUserNotificationAction new];
|
|
|
|
|
action.identifier = Signal_Message_MarkAsRead_Identifier;
|
|
|
|
|
action.title = NSLocalizedString(@"PUSH_MANAGER_MARKREAD", nil);
|
|
|
|
|
action.destructive = NO;
|
|
|
|
|
action.authenticationRequired = NO;
|
|
|
|
|
action.activationMode = UIUserNotificationActivationModeBackground;
|
|
|
|
|
return action;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-12 18:22:29 +01:00
|
|
|
|
#pragma mark - Signal Calls
|
|
|
|
|
|
|
|
|
|
NSString *const PushManagerCategoriesIncomingCall = @"PushManagerCategoriesIncomingCall";
|
|
|
|
|
NSString *const PushManagerCategoriesMissedCall = @"PushManagerCategoriesMissedCall";
|
2017-06-07 00:59:38 +02:00
|
|
|
|
NSString *const PushManagerCategoriesMissedCallFromNoLongerVerifiedIdentity =
|
|
|
|
|
@"PushManagerCategoriesMissedCallFromNoLongerVerifiedIdentity";
|
2016-11-12 18:22:29 +01:00
|
|
|
|
|
|
|
|
|
NSString *const PushManagerActionsAcceptCall = @"PushManagerActionsAcceptCall";
|
|
|
|
|
NSString *const PushManagerActionsDeclineCall = @"PushManagerActionsDeclineCall";
|
|
|
|
|
NSString *const PushManagerActionsCallBack = @"PushManagerActionsCallBack";
|
2017-06-06 22:31:09 +02:00
|
|
|
|
NSString *const PushManagerActionsIgnoreIdentityChangeAndCallBack =
|
|
|
|
|
@"PushManagerActionsIgnoreIdentityChangeAndCallBack";
|
2017-05-31 17:49:30 +02:00
|
|
|
|
NSString *const PushManagerActionsShowThread = @"PushManagerActionsShowThread";
|
2016-11-12 18:22:29 +01:00
|
|
|
|
|
|
|
|
|
NSString *const PushManagerUserInfoKeysLocalCallId = @"PushManagerUserInfoKeysLocalCallId";
|
|
|
|
|
NSString *const PushManagerUserInfoKeysCallBackSignalRecipientId = @"PushManagerUserInfoKeysCallBackSignalRecipientId";
|
|
|
|
|
|
|
|
|
|
- (UIUserNotificationCategory *)signalIncomingCallCategory
|
|
|
|
|
{
|
|
|
|
|
UIMutableUserNotificationAction *acceptAction = [UIMutableUserNotificationAction new];
|
|
|
|
|
acceptAction.identifier = PushManagerActionsAcceptCall;
|
|
|
|
|
acceptAction.title = NSLocalizedString(@"ANSWER_CALL_BUTTON_TITLE", @"");
|
|
|
|
|
acceptAction.activationMode = UIUserNotificationActivationModeForeground;
|
|
|
|
|
acceptAction.destructive = NO;
|
|
|
|
|
acceptAction.authenticationRequired = NO;
|
|
|
|
|
|
|
|
|
|
UIMutableUserNotificationAction *declineAction = [UIMutableUserNotificationAction new];
|
|
|
|
|
declineAction.identifier = PushManagerActionsDeclineCall;
|
|
|
|
|
declineAction.title = NSLocalizedString(@"REJECT_CALL_BUTTON_TITLE", @"");
|
|
|
|
|
declineAction.activationMode = UIUserNotificationActivationModeBackground;
|
|
|
|
|
declineAction.destructive = NO;
|
|
|
|
|
declineAction.authenticationRequired = NO;
|
|
|
|
|
|
|
|
|
|
UIMutableUserNotificationCategory *callCategory = [UIMutableUserNotificationCategory new];
|
|
|
|
|
callCategory.identifier = PushManagerCategoriesIncomingCall;
|
|
|
|
|
[callCategory setActions:@[ acceptAction, declineAction ] forContext:UIUserNotificationActionContextMinimal];
|
|
|
|
|
[callCategory setActions:@[ acceptAction, declineAction ] forContext:UIUserNotificationActionContextDefault];
|
|
|
|
|
|
|
|
|
|
return callCategory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (UIUserNotificationCategory *)signalMissedCallCategory
|
|
|
|
|
{
|
|
|
|
|
UIMutableUserNotificationAction *callBackAction = [UIMutableUserNotificationAction new];
|
|
|
|
|
callBackAction.identifier = PushManagerActionsCallBack;
|
2017-02-02 23:42:06 +01:00
|
|
|
|
callBackAction.title = [CallStrings callBackButtonTitle];
|
2016-11-12 18:22:29 +01:00
|
|
|
|
callBackAction.activationMode = UIUserNotificationActivationModeForeground;
|
|
|
|
|
callBackAction.destructive = NO;
|
|
|
|
|
callBackAction.authenticationRequired = YES;
|
|
|
|
|
|
2017-05-31 17:49:30 +02:00
|
|
|
|
UIMutableUserNotificationCategory *missedCallCategory = [UIMutableUserNotificationCategory new];
|
|
|
|
|
missedCallCategory.identifier = PushManagerCategoriesMissedCall;
|
|
|
|
|
[missedCallCategory setActions:@[ callBackAction ] forContext:UIUserNotificationActionContextMinimal];
|
|
|
|
|
[missedCallCategory setActions:@[ callBackAction ] forContext:UIUserNotificationActionContextDefault];
|
2016-11-12 18:22:29 +01:00
|
|
|
|
|
2017-05-31 17:49:30 +02:00
|
|
|
|
return missedCallCategory;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-07 00:59:38 +02:00
|
|
|
|
- (UIUserNotificationCategory *)signalMissedCallWithNoLongerVerifiedIdentityChangeCategory
|
2017-05-31 17:49:30 +02:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
UIMutableUserNotificationAction *showThreadAction = [UIMutableUserNotificationAction new];
|
|
|
|
|
showThreadAction.identifier = PushManagerActionsShowThread;
|
|
|
|
|
showThreadAction.title = [CallStrings showThreadButtonTitle];
|
|
|
|
|
showThreadAction.activationMode = UIUserNotificationActivationModeForeground;
|
|
|
|
|
showThreadAction.destructive = NO;
|
|
|
|
|
showThreadAction.authenticationRequired = YES;
|
|
|
|
|
|
|
|
|
|
UIMutableUserNotificationCategory *rejectedCallCategory = [UIMutableUserNotificationCategory new];
|
2017-06-07 00:59:38 +02:00
|
|
|
|
rejectedCallCategory.identifier = PushManagerCategoriesMissedCallFromNoLongerVerifiedIdentity;
|
|
|
|
|
[rejectedCallCategory setActions:@[ showThreadAction ] forContext:UIUserNotificationActionContextMinimal];
|
|
|
|
|
[rejectedCallCategory setActions:@[ showThreadAction ] forContext:UIUserNotificationActionContextDefault];
|
2017-05-31 17:49:30 +02:00
|
|
|
|
|
|
|
|
|
return rejectedCallCategory;
|
2014-10-07 00:04:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-12 18:22:29 +01:00
|
|
|
|
#pragma mark Util
|
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
|
- (int)allNotificationTypes {
|
2014-11-19 21:17:53 +01:00
|
|
|
|
return UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge;
|
2014-09-15 01:32:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
Rework push registration
== Account Registration ==
Not complete until push tokens are uploaded
== Remote Notifications Registration ==
Extracted from PushManager
- wait for notification-settings registration to complete before
requesting push tokens, otherwise it's possible token requests will
be ignored.
- Less state required for push notification callbacks, specifically, we
no longer need to ensure we've created a promise before the
registration delegate methods get called.
- no more TOCFuture in Signal-iOS (still in SSK for now). It's not in
cases of inexplicable behavior - one a recently, push notification
premature free, in redphone, and more popular use, and I've seen two
futures inexplicably being nil. Instead, let's consolidate around
PromiseKit for popularly used, maintained, strongly-typed futures.
- separate logic for registering for vanilla push/voip notifications
(few dependencies) from responding to UILocalNotifications (lots of
dependencies). Ultimately I'd like to consolidate the remaining
UILocalNotifications logic with the existing NotificationsManager
== Misc ==
more debug logging
more uniform logging
remove stale logic around newly registered user
// FREEBIE
2017-09-20 23:47:12 +02:00
|
|
|
|
- (UIUserNotificationSettings *)userNotificationSettings
|
2016-10-10 22:02:09 +02:00
|
|
|
|
{
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogDebug(@"%@ registering user notification settings", self.logTag);
|
2017-06-07 00:59:38 +02:00
|
|
|
|
UIUserNotificationSettings *settings = [UIUserNotificationSettings
|
|
|
|
|
settingsForTypes:(UIUserNotificationType)[self allNotificationTypes]
|
|
|
|
|
categories:[NSSet setWithObjects:[self fullNewMessageNotificationCategory],
|
2017-06-23 19:55:21 +02:00
|
|
|
|
[self fullNewMessageNoLongerVerifiedNotificationCategory],
|
2017-06-07 00:59:38 +02:00
|
|
|
|
[self signalIncomingCallCategory],
|
|
|
|
|
[self signalMissedCallCategory],
|
|
|
|
|
[self signalMissedCallWithNoLongerVerifiedIdentityChangeCategory],
|
|
|
|
|
nil]];
|
2016-10-10 22:02:09 +02:00
|
|
|
|
|
Rework push registration
== Account Registration ==
Not complete until push tokens are uploaded
== Remote Notifications Registration ==
Extracted from PushManager
- wait for notification-settings registration to complete before
requesting push tokens, otherwise it's possible token requests will
be ignored.
- Less state required for push notification callbacks, specifically, we
no longer need to ensure we've created a promise before the
registration delegate methods get called.
- no more TOCFuture in Signal-iOS (still in SSK for now). It's not in
cases of inexplicable behavior - one a recently, push notification
premature free, in redphone, and more popular use, and I've seen two
futures inexplicably being nil. Instead, let's consolidate around
PromiseKit for popularly used, maintained, strongly-typed futures.
- separate logic for registering for vanilla push/voip notifications
(few dependencies) from responding to UILocalNotifications (lots of
dependencies). Ultimately I'd like to consolidate the remaining
UILocalNotifications logic with the existing NotificationsManager
== Misc ==
more debug logging
more uniform logging
remove stale logic around newly registered user
// FREEBIE
2017-09-20 23:47:12 +02:00
|
|
|
|
return settings;
|
2015-04-07 17:22:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-14 21:49:00 +02:00
|
|
|
|
- (BOOL)applicationIsActive {
|
|
|
|
|
UIApplication *app = [UIApplication sharedApplication];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2015-04-14 21:49:00 +02:00
|
|
|
|
if (app.applicationState == UIApplicationStateActive) {
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2015-04-14 21:49:00 +02:00
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
Rework push registration
== Account Registration ==
Not complete until push tokens are uploaded
== Remote Notifications Registration ==
Extracted from PushManager
- wait for notification-settings registration to complete before
requesting push tokens, otherwise it's possible token requests will
be ignored.
- Less state required for push notification callbacks, specifically, we
no longer need to ensure we've created a promise before the
registration delegate methods get called.
- no more TOCFuture in Signal-iOS (still in SSK for now). It's not in
cases of inexplicable behavior - one a recently, push notification
premature free, in redphone, and more popular use, and I've seen two
futures inexplicably being nil. Instead, let's consolidate around
PromiseKit for popularly used, maintained, strongly-typed futures.
- separate logic for registering for vanilla push/voip notifications
(few dependencies) from responding to UILocalNotifications (lots of
dependencies). Ultimately I'd like to consolidate the remaining
UILocalNotifications logic with the existing NotificationsManager
== Misc ==
more debug logging
more uniform logging
remove stale logic around newly registered user
// FREEBIE
2017-09-20 23:47:12 +02:00
|
|
|
|
// TODO: consolidate notification tracking with NotificationsManager, which also maintains a list of notifications.
|
2017-04-05 17:13:09 +02:00
|
|
|
|
- (void)presentNotification:(UILocalNotification *)notification checkForCancel:(BOOL)checkForCancel
|
|
|
|
|
{
|
2018-02-16 02:45:28 +01:00
|
|
|
|
notification.alertBody = notification.alertBody.filterStringForDisplay;
|
|
|
|
|
|
2017-04-14 21:27:31 +02:00
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
NSString *threadId = notification.userInfo[Signal_Thread_UserInfo_Key];
|
|
|
|
|
if (checkForCancel && threadId != nil) {
|
2017-11-16 15:54:55 +01:00
|
|
|
|
if ([[OWSDeviceManager sharedManager] hasReceivedSyncMessageInLastSeconds:60.f]) {
|
|
|
|
|
// "If you’ve heard from desktop in last minute, wait 5 seconds."
|
|
|
|
|
//
|
|
|
|
|
// This provides a window in which we can cancel notifications
|
|
|
|
|
// already viewed on desktop before they are presented here.
|
|
|
|
|
const CGFloat kDelaySeconds = 5.f;
|
|
|
|
|
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:kDelaySeconds];
|
|
|
|
|
} else {
|
|
|
|
|
notification.fireDate = [NSDate new];
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-14 21:27:31 +02:00
|
|
|
|
notification.timeZone = [NSTimeZone localTimeZone];
|
|
|
|
|
}
|
2017-04-12 16:03:09 +02:00
|
|
|
|
|
2017-04-14 21:27:31 +02:00
|
|
|
|
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
|
|
|
|
|
[self.currentNotifications addObject:notification];
|
|
|
|
|
});
|
2015-09-01 19:22:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
Rework push registration
== Account Registration ==
Not complete until push tokens are uploaded
== Remote Notifications Registration ==
Extracted from PushManager
- wait for notification-settings registration to complete before
requesting push tokens, otherwise it's possible token requests will
be ignored.
- Less state required for push notification callbacks, specifically, we
no longer need to ensure we've created a promise before the
registration delegate methods get called.
- no more TOCFuture in Signal-iOS (still in SSK for now). It's not in
cases of inexplicable behavior - one a recently, push notification
premature free, in redphone, and more popular use, and I've seen two
futures inexplicably being nil. Instead, let's consolidate around
PromiseKit for popularly used, maintained, strongly-typed futures.
- separate logic for registering for vanilla push/voip notifications
(few dependencies) from responding to UILocalNotifications (lots of
dependencies). Ultimately I'd like to consolidate the remaining
UILocalNotifications logic with the existing NotificationsManager
== Misc ==
more debug logging
more uniform logging
remove stale logic around newly registered user
// FREEBIE
2017-09-20 23:47:12 +02:00
|
|
|
|
// TODO: consolidate notification tracking with NotificationsManager, which also maintains a list of notifications.
|
2017-04-14 21:27:31 +02:00
|
|
|
|
- (void)cancelNotificationsWithThreadId:(NSString *)threadId
|
|
|
|
|
{
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
NSMutableArray *toDelete = [NSMutableArray array];
|
|
|
|
|
[self.currentNotifications
|
|
|
|
|
enumerateObjectsUsingBlock:^(UILocalNotification *notif, NSUInteger idx, BOOL *stop) {
|
|
|
|
|
if ([notif.userInfo[Signal_Thread_UserInfo_Key] isEqualToString:threadId]) {
|
|
|
|
|
[[UIApplication sharedApplication] cancelLocalNotification:notif];
|
|
|
|
|
[toDelete addObject:notif];
|
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
[self.currentNotifications removeObjectsInArray:toDelete];
|
|
|
|
|
});
|
2015-09-01 19:22:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-01 07:53:58 +02:00
|
|
|
|
@end
|