-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[User Model] Notification permission and PushSubscription observer updates #1532
[User Model] Notification permission and PushSubscription observer updates #1532
Conversation
… to be created via addEventListener methods
… PushSubscription and Notification permission observers
Notification listeners to be handled by EventManager
Remove set setEventHandler since there can now be multiple listeners
Additional nit: clean up unused import
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 6 of 12 files at r2, all commit messages.
Reviewable status: 6 of 12 files reviewed, 10 unresolved discussions (waiting on @emawby, @jennantilla, and @shepherd-l)
MIGRATION_GUIDE.md
line 381 at r2 (raw file):
- Changing app IDs is not supported. - Any `User` namespace calls must be invoked **after** initialization. Example: `OneSignal.User.addTag("tag", "2")` - In the iOS SDK, the user state is only refreshed from the server when a new session is started (cold start or backgrounded for over 30 seconds) or when the user is logged in. This is by design.
Also true on Android, may not be documented in the migration guide.
android/src/main/java/com/geektime/rnonesignalandroid/RNOneSignal.java
line 361 at r2 (raw file):
sendEvent("OneSignal-notificationWillDisplayInForeground", RNUtils.convertHashMapToWritableMap( RNUtils.convertNotificationEventToMap(event)));
convert notification will display event to map (so not to confuse with the notification click event).
android/src/main/java/com/geektime/rnonesignalandroid/RNOneSignal.java
line 506 at r2 (raw file):
sendEvent("OneSignal-subscriptionChanged", RNUtils.convertHashMapToWritableMap( RNUtils.convertOnSubscriptionChangedToMap(pushSubscription)));
Pass original event with current and previous
ios/RCTOneSignal/RCTOneSignal.h
line 8 at r2 (raw file):
#endif @interface RCTOneSignal : NSObject <OSPushSubscriptionObserver, OSNotificationPermissionObserver, OSInAppMessageLifecycleListener, OSInAppMessageClickListener, OSNotificationClickListener>
Notification Foreground Lifecycle once that one is moved to RCTOneSignal
ios/RCTOneSignal/RCTOneSignalEventEmitter.m
line 271 at r2 (raw file):
RCT_EXPORT_METHOD(addNotificationForegroundLifecycleListener) { [OneSignal.Notifications addForegroundLifecycleListener:self];
Modify to use [RCTOneSignal sharedInstance] as well
ios/RCTOneSignal/RCTOneSignalEventEmitter.m
line 271 at r2 (raw file):
} RCT_EXPORT_METHOD(clearAllNotifications) {
Did you mean to remove clearAllNotifications?
src/events/EventManager.ts
line 35 at r2 (raw file):
private RNOneSignal: NativeModule; private oneSignalEventEmitter: NativeEventEmitter; private eventHandlerArrayMap: Map<string, Array<(event: any) => void>>;
eventListenerArrayMap
Code quote:
eventHandlerArrayMap
src/events/EventManager.ts
line 75 at r2 (raw file):
* @returns void */ clearEventHandler(eventName: string, handler: any) {
removeEventListener to be clearer that we are not clearing all the listeners
Change clearEventHandler to removeEventListener and EventHandler to EventListener
…ions for notification click
Description
One Line Summary
Update the Notification permission observer and PushSubscription observer to be called by
addEventListener
methods.Details
Motivation
Align the Typescript methods to addEventListener established convention.
Scope
permissionChange
toaddEventListener
andremoveEventListener
methods on Notifications namespace, removed oldaddPermissionObserver
andremovePermissionObserver
methods.addObserver
andremoveObserver
methods from PushSubscription namespace withaddEventListener
andremoveEventListener
for event typechange
Testing
Manual testing
Manually tested on an Pixel 4 simulator running Android 13 and iPhone 14 running iOS 16.4. Confirmed these new methods successfully add and remove the observers for Notification permission and PushSubscription.
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is