Page MenuHomePhabricator

D6071.id20733.diff
No OneTemporary

D6071.id20733.diff

diff --git a/native/ios/Comm/AppDelegate.mm b/native/ios/Comm/AppDelegate.mm
--- a/native/ios/Comm/AppDelegate.mm
+++ b/native/ios/Comm/AppDelegate.mm
@@ -26,8 +26,8 @@
@end
#endif
+#import "CommIOSNotifications.h"
#import "Orientation.h"
-#import "RNNotifications.h"
#import <React/RCTConvert.h>
#import <React/RCTBridge+Private.h>
@@ -158,13 +158,13 @@
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
- [RNNotifications
+ [CommIOSNotifications
didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
- [RNNotifications didFailToRegisterForRemoteNotificationsWithError:error];
+ [CommIOSNotifications didFailToRegisterForRemoteNotificationsWithError:error];
}
// Required for the notification event. You must call the completion handler
@@ -184,8 +184,8 @@
return;
}
- [RNNotifications didReceiveRemoteNotification:notification
- fetchCompletionHandler:completionHandler];
+ [CommIOSNotifications didReceiveRemoteNotification:notification
+ fetchCompletionHandler:completionHandler];
}
- (BOOL)handleBackgroundNotification:(NSDictionary *)notification
@@ -202,33 +202,14 @@
comm::ThreadOperations::updateSQLiteUnreadStatus(threadID, false);
});
}
- [[UNUserNotificationCenter currentNotificationCenter]
- getDeliveredNotificationsWithCompletionHandler:^(
- NSArray<UNNotification *> *notifications) {
- for (UNNotification *notif in notifications) {
- if ([notification[@"notificationId"]
- isEqual:notif.request.content.userInfo[@"id"]]) {
- NSArray *identifiers =
- [NSArray arrayWithObjects:notif.request.identifier, nil];
- [[UNUserNotificationCenter currentNotificationCenter]
- removeDeliveredNotificationsWithIdentifiers:identifiers];
- }
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- completionHandler(UIBackgroundFetchResultNewData);
- });
- }];
+ [CommIOSNotifications
+ clearNotificationFromNotificationsCenter:notification[@"notificationId"]
+ completionHandler:completionHandler];
return YES;
}
return NO;
}
-// Required for the localNotification event.
-- (void)application:(UIApplication *)application
- didReceiveLocalNotification:(UILocalNotification *)notification {
- [RNNotifications didReceiveLocalNotification:notification];
-}
-
- (UIInterfaceOrientationMask)application:(UIApplication *)application
supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return [Orientation getOrientation];
diff --git a/native/push/ios.js b/native/push/ios.js
--- a/native/push/ios.js
+++ b/native/push/ios.js
@@ -1,6 +1,10 @@
// @flow
-import NotificationsIOS from 'react-native-notifications';
+import { NativeModules, NativeEventEmitter } from 'react-native';
+
+import type { RawIOSNotification } from './comm-ios-notification';
+
+const { CommIOSNotifications } = NativeModules;
type PushPermissions = { alert?: boolean, badge?: boolean, sound?: boolean };
@@ -12,7 +16,7 @@
firstRun = false;
if (!permissionNeeded) {
- const permissions: PushPermissions = await NotificationsIOS.checkPermissions();
+ const permissions: PushPermissions = await CommIOSNotifications.checkPermissions();
permissionNeeded = permissionMissing(permissions);
}
@@ -21,10 +25,10 @@
return;
}
currentlyActive = true;
- await NotificationsIOS.requestPermissions();
+ await CommIOSNotifications.requestPermissions();
}
- NotificationsIOS.consumeBackgroundQueue();
+ CommIOSNotifications.consumeBackgroundQueue();
}
function iosPushPermissionResponseReceived() {
@@ -35,4 +39,18 @@
return !permissions.alert || !permissions.badge || !permissions.sound;
}
-export { requestIOSPushPermissions, iosPushPermissionResponseReceived };
+function getCommIOSNotificationsEventEmitter(): NativeEventEmitter<{
+ remoteNotificationsRegistered: [{ +deviceToken: ?string }],
+ remoteNotificationsRegistrationFailed: [void],
+ notificationReceivedForeground: [RawIOSNotification],
+ notificationOpened: [RawIOSNotification],
+}> {
+ return new NativeEventEmitter(CommIOSNotifications);
+}
+
+export {
+ requestIOSPushPermissions,
+ iosPushPermissionResponseReceived,
+ CommIOSNotifications,
+ getCommIOSNotificationsEventEmitter,
+};
diff --git a/native/push/push-handler.react.js b/native/push/push-handler.react.js
--- a/native/push/push-handler.react.js
+++ b/native/push/push-handler.react.js
@@ -55,11 +55,17 @@
handleAndroidMessage,
androidBackgroundMessageTask,
} from './android';
+import {
+ CommIOSNotification,
+ type RawIOSNotification,
+} from './comm-ios-notification';
import { getFirebase } from './firebase';
import InAppNotif from './in-app-notif.react';
import {
requestIOSPushPermissions,
iosPushPermissionResponseReceived,
+ CommIOSNotifications,
+ getCommIOSNotificationsEventEmitter,
} from './ios';
LogBox.ignoreLogs([
@@ -103,6 +109,7 @@
+onPress: () => void,
},
};
+
class PushHandler extends React.PureComponent<Props, State> {
state: State = {
inAppNotifProps: null,
@@ -115,6 +122,7 @@
initialAndroidNotifHandled = false;
openThreadOnceReceived: Set<string> = new Set();
lifecycleSubscription: ?EventSubscription;
+ iosNotificationEventSubscriptions: Array<EventSubscription> = [];
componentDidMount() {
this.appStarted = Date.now();
@@ -123,21 +131,25 @@
);
this.onForeground();
if (Platform.OS === 'ios') {
- NotificationsIOS.addEventListener(
- 'remoteNotificationsRegistered',
- this.registerPushPermissions,
- );
- NotificationsIOS.addEventListener(
- 'remoteNotificationsRegistrationFailed',
- this.failedToRegisterPushPermissions,
- );
- NotificationsIOS.addEventListener(
- 'notificationReceivedForeground',
- this.iosForegroundNotificationReceived,
- );
- NotificationsIOS.addEventListener(
- 'notificationOpened',
- this.iosNotificationOpened,
+ const commIOSNotificationsEventEmitter = getCommIOSNotificationsEventEmitter();
+ this.iosNotificationEventSubscriptions.push(
+ commIOSNotificationsEventEmitter.addListener(
+ 'remoteNotificationsRegistered',
+ registration =>
+ this.registerPushPermissions(registration?.deviceToken),
+ ),
+ commIOSNotificationsEventEmitter.addListener(
+ 'remoteNotificationsRegistrationFailed',
+ this.failedToRegisterPushPermissions,
+ ),
+ commIOSNotificationsEventEmitter.addListener(
+ 'notificationReceivedForeground',
+ this.iosForegroundNotificationReceived,
+ ),
+ commIOSNotificationsEventEmitter.addListener(
+ 'notificationOpened',
+ this.iosNotificationOpened,
+ ),
);
} else if (Platform.OS === 'android') {
const firebase = getFirebase();
@@ -168,22 +180,10 @@
this.lifecycleSubscription.remove();
}
if (Platform.OS === 'ios') {
- NotificationsIOS.removeEventListener(
- 'remoteNotificationsRegistered',
- this.registerPushPermissions,
- );
- NotificationsIOS.removeEventListener(
- 'remoteNotificationsRegistrationFailed',
- this.failedToRegisterPushPermissions,
- );
- NotificationsIOS.removeEventListener(
- 'notificationReceivedForeground',
- this.iosForegroundNotificationReceived,
- );
- NotificationsIOS.removeEventListener(
- 'notificationOpened',
- this.iosNotificationOpened,
- );
+ for (const iosNotificationEventSubscription of this
+ .iosNotificationEventSubscriptions) {
+ iosNotificationEventSubscription.remove();
+ }
} else if (Platform.OS === 'android') {
if (this.androidTokenListener) {
this.androidTokenListener();
@@ -457,7 +457,8 @@
});
}
- iosForegroundNotificationReceived = notification => {
+ iosForegroundNotificationReceived = (rawNotification: RawIOSNotification) => {
+ const notification = new CommIOSNotification(rawNotification);
if (
notification.getData() &&
notification.getData().managedAps &&
@@ -488,7 +489,13 @@
if (notification.getData().title) {
({ title, body } = mergePrefixIntoBody(notification.getData()));
}
- this.showInAppNotification(threadID, body, title);
+ if (body) {
+ this.showInAppNotification(threadID, body, title);
+ } else {
+ console.log(
+ 'Non-rescind foreground notification without alert received!',
+ );
+ }
notification.finish(NotificationsIOS.FetchResult.NewData);
};
@@ -501,7 +508,8 @@
}
}
- iosNotificationOpened = notification => {
+ iosNotificationOpened = (rawNotification: RawIOSNotification) => {
+ const notification = new CommIOSNotification(rawNotification);
this.onPushNotifBootsApp();
const threadID = notification.getData().threadID;
if (!threadID) {

File Metadata

Mime Type
text/plain
Expires
Fri, Dec 20, 8:21 PM (16 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2682814
Default Alt Text
D6071.id20733.diff (9 KB)

Event Timeline