diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 82e37075d..635a425b1 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -7,7 +7,6 @@ #import "DebugLogger.h" #import "HomeViewController.h" #import "MainAppContext.h" -#import "NotificationsManager.h" #import "OWS2FASettingsViewController.h" #import "OWSBackup.h" #import "OWSOrphanDataCleaner.h" diff --git a/Signal/src/UserInterface/Notifications/CallNotificationsAdapter.swift b/Signal/src/UserInterface/Notifications/CallNotificationsAdapter.swift index 124bae01d..25ea8edee 100644 --- a/Signal/src/UserInterface/Notifications/CallNotificationsAdapter.swift +++ b/Signal/src/UserInterface/Notifications/CallNotificationsAdapter.swift @@ -4,24 +4,21 @@ import Foundation +@objc +public protocol NotificationsAdaptee: NotificationsProtocol, OWSCallNotificationsAdaptee { } + +extension NotificationsManager: NotificationsAdaptee { } + /** * Present call related notifications to the user. */ @objc(OWSNotificationsAdapter) -public class NotificationsAdapter: NSObject { - - var adaptee: OWSCallNotificationsAdaptee { - // TODO: We may eventually want to use UserNotificationsAdaptee instead. - // - // We can't mix UILocalNotification (NotificationManager) with the UNNotifications - // Because registering message categories in one, clobbers the registered categories from the other - // We have to first port *all* the existing UINotification categories to UNNotifications - // which is a good thing to do, but in trying to limit the scope of changes that's been - // left out for now. - return AppEnvironment.shared.notificationsManager - } +public class NotificationsAdapter: NSObject, NotificationsProtocol { + private let adaptee: NotificationsAdaptee @objc public override init() { + self.adaptee = NotificationsManager() + super.init() SwiftSingletons.register(self) @@ -45,4 +42,20 @@ public class NotificationsAdapter: NSObject { adaptee.presentMissedCallBecauseOfNewIdentity(call: call, callerName: callerName) } + // MJK TODO DI contactsManager + public func notifyUser(for incomingMessage: TSIncomingMessage, in thread: TSThread, contactsManager: ContactsManagerProtocol, transaction: YapDatabaseReadTransaction) { + adaptee.notifyUser(for: incomingMessage, in: thread, contactsManager: contactsManager, transaction: transaction) + } + + public func notifyUser(for error: TSErrorMessage, thread: TSThread, transaction: YapDatabaseReadWriteTransaction) { + adaptee.notifyUser(for: error, thread: thread, transaction: transaction) + } + + public func notifyUser(forThreadlessErrorMessage error: TSErrorMessage, transaction: YapDatabaseReadWriteTransaction) { + adaptee.notifyUser(forThreadlessErrorMessage: error, transaction: transaction) + } + + public func clearAllNotifications() { + adaptee.clearAllNotifications() + } } diff --git a/Signal/src/ViewControllers/DebugUI/DebugUINotifications.swift b/Signal/src/ViewControllers/DebugUI/DebugUINotifications.swift index 4fd5dd2e5..9f70a28c4 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUINotifications.swift +++ b/Signal/src/ViewControllers/DebugUI/DebugUINotifications.swift @@ -10,11 +10,8 @@ class DebugUINotifications: DebugUIPage { // MARK: Dependencies - var notificationsManager: NotificationsManager { - return AppEnvironment.shared.notificationsManager - } var notificationsAdapter: NotificationsAdapter { - return AppEnvironment.shared.NotificationsAdapter + return AppEnvironment.shared.notificationsAdapter } var messageSender: MessageSender { return SSKEnvironment.shared.messageSender @@ -60,7 +57,7 @@ class DebugUINotifications: DebugUIPage { return } Logger.info("notifying user of incoming message") - strongSelf.notificationsManager.notifyUser(for: incomingMessage, in: thread, contactsManager: strongSelf.contactsManager, transaction: transaction) + strongSelf.notificationsAdapter.notifyUser(for: incomingMessage, in: thread, contactsManager: strongSelf.contactsManager, transaction: transaction) } } } diff --git a/Signal/src/call/CallService.swift b/Signal/src/call/CallService.swift index 4c7c8ba65..47b0b5ea5 100644 --- a/Signal/src/call/CallService.swift +++ b/Signal/src/call/CallService.swift @@ -402,7 +402,7 @@ private class SignalCallData: NSObject { } private var notificationsAdapter: NotificationsAdapter { - return AppEnvironment.shared.NotificationsAdapter + return AppEnvironment.shared.notificationsAdapter } // MARK: - Notifications diff --git a/Signal/src/environment/AppEnvironment.swift b/Signal/src/environment/AppEnvironment.swift index b5ebe4ad0..225d80660 100644 --- a/Signal/src/environment/AppEnvironment.swift +++ b/Signal/src/environment/AppEnvironment.swift @@ -37,14 +37,11 @@ import SignalMessaging @objc public var messageFetcherJob: MessageFetcherJob - @objc - public var notificationsManager: NotificationsManager - @objc public var accountManager: AccountManager @objc - public var NotificationsAdapter: NotificationsAdapter + public var notificationsAdapter: NotificationsAdapter @objc public var pushRegistrationManager: PushRegistrationManager @@ -66,7 +63,6 @@ import SignalMessaging self.callService = CallService() self.outboundCallInitiator = OutboundCallInitiator() self.messageFetcherJob = MessageFetcherJob() - self.notificationsManager = NotificationsManager() self.accountManager = AccountManager() self.notificationsAdapter = NotificationsAdapter() self.pushRegistrationManager = PushRegistrationManager() @@ -85,7 +81,7 @@ import SignalMessaging callService.createCallUIAdapter() // Hang certain singletons on SSKEnvironment too. - SSKEnvironment.shared.notificationsManager = notificationsManager + SSKEnvironment.shared.notificationsManager = notificationsAdapter SSKEnvironment.shared.callMessageHandler = callMessageHandler } } diff --git a/Signal/src/environment/SignalApp.h b/Signal/src/environment/SignalApp.h index ce8d4aec9..ebf2ae8a4 100644 --- a/Signal/src/environment/SignalApp.h +++ b/Signal/src/environment/SignalApp.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import "ConversationViewController.h" @@ -10,7 +10,6 @@ NS_ASSUME_NONNULL_BEGIN @class CallService; @class CallUIAdapter; @class HomeViewController; -@class NotificationsManager; @class OWSMessageFetcherJob; @class OWSNavigationController; @class OWSWebRTCCallMessageHandler; diff --git a/Signal/src/network/PushManager.m b/Signal/src/network/PushManager.m index 14d3a2e64..d880fb95c 100644 --- a/Signal/src/network/PushManager.m +++ b/Signal/src/network/PushManager.m @@ -1,10 +1,9 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import "PushManager.h" #import "AppDelegate.h" -#import "NotificationsManager.h" #import "Signal-Swift.h" #import "SignalApp.h" #import "ThreadUtil.h"