diff --git a/native/push/android.js b/native/push/android.js index dda474e0b..8fae27f7e 100644 --- a/native/push/android.js +++ b/native/push/android.js @@ -1,70 +1,70 @@ // @flow import { NativeModules, NativeEventEmitter } from 'react-native'; import { mergePrefixIntoBody } from 'lib/shared/notif-utils.js'; type CommAndroidNotificationsModuleType = { +removeAllActiveNotificationsForThread: (threadID: string) => void, +getInitialNotification: () => Promise, +createChannel: ( channelID: string, name: string, importance: number, description: ?string, ) => void, +getConstants: () => { +NOTIFICATIONS_IMPORTANCE_HIGH: number, ... }, +setBadge: (count: number) => void, +removeAllDeliveredNotifications: () => void, +hasPermission: () => Promise, +getToken: () => Promise, - ... + +NOTIFICATIONS_IMPORTANCE_HIGH: string, }; export type AndroidForegroundMessage = { +body: string, +title: string, +threadID: string, +prefix?: string, +messageInfos: ?string, }; const { CommAndroidNotificationsEventEmitter } = NativeModules; const CommAndroidNotifications: CommAndroidNotificationsModuleType = NativeModules.CommAndroidNotifications; const androidNotificationChannelID = 'default'; function handleAndroidMessage( message: AndroidForegroundMessage, updatesCurrentAsOf: number, handleIfActive?: ( threadID: string, texts: { body: string, title: ?string }, ) => boolean, ) { const { title, prefix, threadID } = message; let { body } = message; ({ body } = mergePrefixIntoBody({ body, title, prefix })); if (handleIfActive) { const texts = { title, body }; const isActive = handleIfActive(threadID, texts); if (isActive) { return; } } } function getCommAndroidNotificationsEventEmitter(): NativeEventEmitter<{ commAndroidNotificationsToken: [string], commAndroidNotificationsForegroundMessage: [AndroidForegroundMessage], commAndroidNotificationsNotificationOpened: [AndroidForegroundMessage], }> { return new NativeEventEmitter(CommAndroidNotificationsEventEmitter); } export { androidNotificationChannelID, handleAndroidMessage, getCommAndroidNotificationsEventEmitter, CommAndroidNotifications, }; diff --git a/native/push/ios.js b/native/push/ios.js index 5d0841362..ba99a04ef 100644 --- a/native/push/ios.js +++ b/native/push/ios.js @@ -1,83 +1,85 @@ // @flow import { NativeModules, NativeEventEmitter } from 'react-native'; import type { CoreIOSNotificationData, CoreIOSNotificationDataWithRequestIdentifier, } from './comm-ios-notification.js'; type PushPermissions = { alert?: boolean, badge?: boolean, sound?: boolean }; type CommIOSNotificationsModuleType = { +requestPermissions: () => void, +checkPermissions: () => PushPermissions, +consumeBackgroundQueue: () => void, +setBadgesCount: (count: number) => void, +removeAllDeliveredNotifications: () => void, +removeDeliveredNotifications: (identifiers: $ReadOnlyArray) => void, +getDeliveredNotifications: ( callback: ( notifications: $ReadOnlyArray, ) => void, ) => void, +completeNotif: (id: string, fetchResult: string) => void, +getConstants: () => { [string]: string }, // required since CommIOSNotifications subclasses RCTEventEmitter +addListener: (eventName: string) => void, +removeListeners: (count: number) => void, - ... + +FETCH_RESULT_NO_DATA: string, + +FETCH_RESULT_NO_DATA: string, + +FETCH_RESULT_FAILED: string, }; const CommIOSNotifications: CommIOSNotificationsModuleType = NativeModules.CommIOSNotifications; let currentlyActive = false; let firstRun = true; async function requestIOSPushPermissions(missingDeviceToken: boolean) { let permissionNeeded = firstRun || missingDeviceToken; firstRun = false; if (!permissionNeeded) { const permissions: PushPermissions = await CommIOSNotifications.checkPermissions(); permissionNeeded = permissionMissing(permissions); } if (permissionNeeded) { if (currentlyActive) { return; } currentlyActive = true; await CommIOSNotifications.requestPermissions(); } CommIOSNotifications.consumeBackgroundQueue(); } function iosPushPermissionResponseReceived() { currentlyActive = false; } function permissionMissing(permissions: PushPermissions) { return !permissions.alert || !permissions.badge || !permissions.sound; } function getCommIOSNotificationsEventEmitter(): NativeEventEmitter< $ReadOnly<{ remoteNotificationsRegistered: [{ +deviceToken: ?string }], remoteNotificationsRegistrationFailed: [void], notificationReceivedForeground: [CoreIOSNotificationData], notificationOpened: [CoreIOSNotificationData], }>, > { return new NativeEventEmitter(CommIOSNotifications); } export { requestIOSPushPermissions, iosPushPermissionResponseReceived, CommIOSNotifications, getCommIOSNotificationsEventEmitter, };