| 150 | }; |
| 151 | |
| 152 | class PushHandler extends React.PureComponent<Props, State> { |
| 153 | state: State = { |
| 154 | inAppNotifProps: null, |
| 155 | }; |
| 156 | currentState: ?string = getCurrentLifecycleState(); |
| 157 | appStarted = 0; |
| 158 | androidNotificationsEventSubscriptions: Array<EventSubscription> = []; |
| 159 | androidNotificationsPermissionPromise: ?Promise<boolean> = undefined; |
| 160 | initialAndroidNotifHandled = false; |
| 161 | openThreadOnceReceived: Set<string> = new Set(); |
| 162 | lifecycleSubscription: ?EventSubscription; |
| 163 | iosNotificationEventSubscriptions: Array<EventSubscription> = []; |
| 164 | |
| 165 | componentDidMount() { |
| 166 | this.appStarted = Date.now(); |
| 167 | this.lifecycleSubscription = addLifecycleListener( |
| 168 | this.handleAppStateChange, |
| 169 | ); |
| 170 | this.onForeground(); |
| 171 | if (Platform.OS === 'ios') { |
| 172 | const commIOSNotificationsEventEmitter = |
| 173 | getCommIOSNotificationsEventEmitter(); |
| 174 | this.iosNotificationEventSubscriptions.push( |
| 175 | commIOSNotificationsEventEmitter.addListener( |
| 176 | CommIOSNotifications.getConstants() |
| 177 | .REMOTE_NOTIFICATIONS_REGISTERED_EVENT, |
| 178 | registration => |
| 179 | this.registerPushPermissions(registration?.deviceToken), |
| 180 | ), |
| 181 | commIOSNotificationsEventEmitter.addListener( |
| 182 | CommIOSNotifications.getConstants() |
| 183 | .REMOTE_NOTIFICATIONS_REGISTRATION_FAILED_EVENT, |
| 184 | this.failedToRegisterPushPermissionsIOS, |
| 185 | ), |
| 186 | commIOSNotificationsEventEmitter.addListener( |
| 187 | CommIOSNotifications.getConstants() |
| 188 | .NOTIFICATION_RECEIVED_FOREGROUND_EVENT, |
| 189 | this.iosForegroundNotificationReceived, |
| 190 | ), |
| 191 | commIOSNotificationsEventEmitter.addListener( |
| 192 | CommIOSNotifications.getConstants().NOTIFICATION_OPENED_EVENT, |
| 193 | this.iosNotificationOpened, |
| 194 | ), |
| 195 | commIOSNotificationsEventEmitter.addListener( |
| 196 | CommIOSNotifications.getConstants() |
| 197 | .NOTIFICATION_RECEIVED_BACKGROUND_EVENT, |
| 198 | this.iosBackgroundNotificationReceived, |
| 199 | ), |
| 200 | ); |
| 201 | } else if (Platform.OS === 'android') { |
| 202 | CommAndroidNotifications.createChannel( |
| 203 | androidNotificationChannelID, |
| 204 | 'Default', |
| 205 | CommAndroidNotifications.getConstants().NOTIFICATIONS_IMPORTANCE_HIGH, |
| 206 | 'Comm notifications channel', |
| 207 | ); |
| 208 | const commAndroidNotificationsEventEmitter = |
| 209 | getCommAndroidNotificationsEventEmitter(); |
nothing calls this directly
no test coverage detected