diff --git a/src/libs/Notification/PushNotification/ForegroundNotifications/index.android.js b/src/libs/Notification/PushNotification/ForegroundNotifications/index.android.js new file mode 100644 index 000000000000..0afc8fe10490 --- /dev/null +++ b/src/libs/Notification/PushNotification/ForegroundNotifications/index.android.js @@ -0,0 +1,15 @@ +import Airship from '@ua/react-native-airship'; +import shouldShowPushNotification from '../shouldShowPushNotification'; + +function configureForegroundNotifications() { + Airship.push.android.setForegroundDisplayPredicate((pushPayload) => Promise.resolve(shouldShowPushNotification(pushPayload))); +} + +function disableForegroundNotifications() { + Airship.push.android.setForegroundDisplayPredicate(() => Promise.resolve(false)); +} + +export default { + configureForegroundNotifications, + disableForegroundNotifications, +}; diff --git a/src/libs/Notification/PushNotification/configureForegroundNotifications/index.ios.js b/src/libs/Notification/PushNotification/ForegroundNotifications/index.ios.js similarity index 78% rename from src/libs/Notification/PushNotification/configureForegroundNotifications/index.ios.js rename to src/libs/Notification/PushNotification/ForegroundNotifications/index.ios.js index 88d94b4ee805..17ad1baaebe3 100644 --- a/src/libs/Notification/PushNotification/configureForegroundNotifications/index.ios.js +++ b/src/libs/Notification/PushNotification/ForegroundNotifications/index.ios.js @@ -1,7 +1,7 @@ import Airship, {iOS} from '@ua/react-native-airship'; import shouldShowPushNotification from '../shouldShowPushNotification'; -export default function configureForegroundNotifications() { +function configureForegroundNotifications() { // Set our default iOS foreground presentation to be loud with a banner // More info here https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate/1649518-usernotificationcenter Airship.push.iOS.setForegroundPresentationOptions([ @@ -15,3 +15,12 @@ export default function configureForegroundNotifications() { // Returning null keeps the default presentation. Returning [] uses no presentation (hides the notification). Airship.push.iOS.setForegroundPresentationOptionsCallback((pushPayload) => Promise.resolve(shouldShowPushNotification(pushPayload) ? null : [])); } + +function disableForegroundNotifications() { + Airship.push.iOS.setForegroundPresentationOptionsCallback(() => Promise.resolve([])); +} + +export default { + configureForegroundNotifications, + disableForegroundNotifications, +}; diff --git a/src/libs/Notification/PushNotification/configureForegroundNotifications/index.js b/src/libs/Notification/PushNotification/ForegroundNotifications/index.js similarity index 52% rename from src/libs/Notification/PushNotification/configureForegroundNotifications/index.js rename to src/libs/Notification/PushNotification/ForegroundNotifications/index.js index c6cb13a0b3b9..acb116f7bc43 100644 --- a/src/libs/Notification/PushNotification/configureForegroundNotifications/index.js +++ b/src/libs/Notification/PushNotification/ForegroundNotifications/index.js @@ -1,4 +1,7 @@ /** * Configures notification handling while in the foreground on iOS and Android. This is a no-op on other platforms. */ -export default function () {} +export default { + configureForegroundNotifications: () => {}, + disableForegroundNotifications: () => {}, +}; diff --git a/src/libs/Notification/PushNotification/configureForegroundNotifications/index.android.js b/src/libs/Notification/PushNotification/configureForegroundNotifications/index.android.js deleted file mode 100644 index 393072df3d12..000000000000 --- a/src/libs/Notification/PushNotification/configureForegroundNotifications/index.android.js +++ /dev/null @@ -1,6 +0,0 @@ -import Airship from '@ua/react-native-airship'; -import shouldShowPushNotification from '../shouldShowPushNotification'; - -export default function configureForegroundNotifications() { - Airship.push.android.setForegroundDisplayPredicate((pushPayload) => Promise.resolve(shouldShowPushNotification(pushPayload))); -} diff --git a/src/libs/Notification/PushNotification/index.native.js b/src/libs/Notification/PushNotification/index.native.js index 299af69873f9..7192ee66a791 100644 --- a/src/libs/Notification/PushNotification/index.native.js +++ b/src/libs/Notification/PushNotification/index.native.js @@ -6,7 +6,7 @@ import Log from '../../Log'; import NotificationType from './NotificationType'; import * as PushNotification from '../../actions/PushNotification'; import ONYXKEYS from '../../../ONYXKEYS'; -import configureForegroundNotifications from './configureForegroundNotifications'; +import ForegroundNotifications from './ForegroundNotifications'; let isUserOptedInToPushNotifications = false; Onyx.connect({ @@ -96,7 +96,7 @@ function init() { // Keep track of which users have enabled push notifications via an NVP. Airship.addListener(EventType.NotificationOptInStatus, refreshNotificationOptInStatus); - configureForegroundNotifications(); + ForegroundNotifications.configureForegroundNotifications(); } /** @@ -136,6 +136,7 @@ function deregister() { Airship.contact.reset(); Airship.removeAllListeners(EventType.PushReceived); Airship.removeAllListeners(EventType.NotificationResponse); + ForegroundNotifications.disableForegroundNotifications(); } /**