Merge branch 'charlesmchen/multipleLocalNotifications'

pull/1/head
Matthew Chen 8 years ago
commit 6297663d34

@ -765,10 +765,14 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
} }
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
OWSAssert([NSThread isMainThread]);
if (!self.isEnvironmentSetup) { if (!self.isEnvironmentSetup) {
OWSFail(@"%@ ignoring %s because environment is not yet set up.", self.tag, __PRETTY_FUNCTION__); OWSFail(
@"%@ ignoring %s because environment is not yet set up: %@.", self.tag, __PRETTY_FUNCTION__, notification);
return; return;
} }
DDLogInfo(@"%@ %s %@", self.tag, __PRETTY_FUNCTION__, notification);
[AppStoreRating preventPromptAtNextTest]; [AppStoreRating preventPromptAtNextTest];
[[PushManager sharedManager] application:application didReceiveLocalNotification:notification]; [[PushManager sharedManager] application:application didReceiveLocalNotification:notification];

@ -7,14 +7,16 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class TSCall;
@class TSContactThread;
@class OWSContactsManager; @class OWSContactsManager;
@class SignalCall;
@class OWSPreferences; @class OWSPreferences;
@class SignalCall;
@class TSCall;
@class TSContactThread;
@interface NotificationsManager : NSObject <NotificationsProtocol, OWSCallNotificationsAdaptee> @interface NotificationsManager : NSObject <NotificationsProtocol, OWSCallNotificationsAdaptee>
- (void)clearAllNotifications;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -422,6 +422,13 @@ NSString *const kNotificationsManagerNewMesssageSoundName = @"NewMessage.aifc";
}); });
} }
- (void)clearAllNotifications
{
OWSAssert([NSThread isMainThread]);
[self.currentNotifications removeAllObjects];
}
#pragma mark - Logging #pragma mark - Logging
+ (NSString *)tag + (NSString *)tag

@ -4,6 +4,7 @@
#import "PushManager.h" #import "PushManager.h"
#import "AppDelegate.h" #import "AppDelegate.h"
#import "NotificationsManager.h"
#import "OWSContactsManager.h" #import "OWSContactsManager.h"
#import "Signal-Swift.h" #import "Signal-Swift.h"
#import "ThreadUtil.h" #import "ThreadUtil.h"
@ -34,6 +35,7 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
@property (nonatomic, readonly) OWSMessageSender *messageSender; @property (nonatomic, readonly) OWSMessageSender *messageSender;
@property (nonatomic, readonly) OWSMessageFetcherJob *messageFetcherJob; @property (nonatomic, readonly) OWSMessageFetcherJob *messageFetcherJob;
@property (nonatomic, readonly) CallUIAdapter *callUIAdapter; @property (nonatomic, readonly) CallUIAdapter *callUIAdapter;
@property (nonatomic, readonly) NotificationsManager *notificationsManager;
@end @end
@ -53,13 +55,15 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
return [self initWithMessageFetcherJob:[Environment getCurrent].messageFetcherJob return [self initWithMessageFetcherJob:[Environment getCurrent].messageFetcherJob
storageManager:[TSStorageManager sharedManager] storageManager:[TSStorageManager sharedManager]
callUIAdapter:[Environment getCurrent].callService.callUIAdapter callUIAdapter:[Environment getCurrent].callService.callUIAdapter
messageSender:[Environment getCurrent].messageSender]; messageSender:[Environment getCurrent].messageSender
notificationsManager:[Environment getCurrent].notificationsManager];
} }
- (instancetype)initWithMessageFetcherJob:(OWSMessageFetcherJob *)messageFetcherJob - (instancetype)initWithMessageFetcherJob:(OWSMessageFetcherJob *)messageFetcherJob
storageManager:(TSStorageManager *)storageManager storageManager:(TSStorageManager *)storageManager
callUIAdapter:(CallUIAdapter *)callUIAdapter callUIAdapter:(CallUIAdapter *)callUIAdapter
messageSender:(OWSMessageSender *)messageSender messageSender:(OWSMessageSender *)messageSender
notificationsManager:(NotificationsManager *)notificationsManager
{ {
self = [super init]; self = [super init];
if (!self) { if (!self) {
@ -72,6 +76,7 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
_callBackgroundTask = UIBackgroundTaskInvalid; _callBackgroundTask = UIBackgroundTaskInvalid;
// TODO: consolidate notification tracking with NotificationsManager, which also maintains a list of notifications. // TODO: consolidate notification tracking with NotificationsManager, which also maintains a list of notifications.
_currentNotifications = [NSMutableArray array]; _currentNotifications = [NSMutableArray array];
_notificationsManager = notificationsManager;
OWSSingletonAssert(); OWSSingletonAssert();
@ -129,6 +134,7 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{ {
OWSAssert([NSThread isMainThread]);
DDLogInfo(@"%@ launched from local notification", self.tag); DDLogInfo(@"%@ launched from local notification", self.tag);
NSString *_Nullable threadId = notification.userInfo[Signal_Thread_UserInfo_Key]; NSString *_Nullable threadId = notification.userInfo[Signal_Thread_UserInfo_Key];
@ -138,6 +144,11 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
} else { } else {
OWSFail(@"%@ threadId was unexpectedly nil in %s", self.tag, __PRETTY_FUNCTION__); OWSFail(@"%@ threadId was unexpectedly nil in %s", self.tag, __PRETTY_FUNCTION__);
} }
// We only want to receive a single local notification per launch.
[application cancelAllLocalNotifications];
[self.currentNotifications removeAllObjects];
[self.notificationsManager clearAllNotifications];
} }
- (void)application:(UIApplication *)application - (void)application:(UIApplication *)application

Loading…
Cancel
Save