Skip to content
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

Merged
merged 29 commits into from
Jul 24, 2023

Conversation

jennantilla
Copy link
Contributor

@jennantilla jennantilla commented Jul 1, 2023

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

  • Added an additional notification event type permissionChange to addEventListener and removeEventListener methods on Notifications namespace, removed old addPermissionObserver and removePermissionObserver methods.
  • Replaced addObserver and removeObserver methods from PushSubscription namespace with addEventListener and removeEventListener for event type change

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

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

src/events/EventManager.ts Outdated Show resolved Hide resolved
src/events/EventManager.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@nan-li nan-li left a 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
@nan-li nan-li self-requested a review July 21, 2023 22:58
@jennantilla jennantilla changed the base branch from user_model_beta2/prettier_fix to major_release_5.0.0 July 24, 2023 22:52
@jennantilla jennantilla merged commit 4c0daca into major_release_5.0.0 Jul 24, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants