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] Rename notification event listeners #1765

Merged
merged 9 commits into from
Apr 25, 2023

Conversation

brismithers
Copy link
Contributor

@brismithers brismithers commented Apr 19, 2023

Description

One Line Summary

Rename notification event listeners based on new naming convention.

Details

  • Renamed all "handlers" to be either a "listener" or an "observer" depending on their purpose. All callbacks now have pattern "onXXXXXX" for each callback.
  • Make all notification listeners 0:* (some were 0:1)
  • Use the terminology "click" instead of "open".
  • Add IEventNotifier.hasSubscribers to determine if there are subscribers. A few implementing classes had to add this.
  • Replaced complete() pattern with preventDefault() pattern in NSE notification received callback and foreground onWillDisplay callback.
  • Add IDisplayableNotification and IDisplayableMutableNotification which adds a display() function to an INotification. This allows the manual display of a notification, when event.preventDefault() is called.
  • Internally, rework NotificationGenerationProcessor to accommodate preventDefault pattern. The notification is now constructed when the notification job is constructed and is never copied/altered until the end of its lifecycle.
  • Update example application for new naming conventions and patterns.
  • Update for new naming conventions and patterns

Motivation

A desire to align terminologies and naming conventions across the OneSignal SDKs.

Scope

This change is primarily a name change within the notifications module/namespace. There are some functional changes related to notification generation processing due to a programming pattern change (i.e. change from using complete() to using preventDefault()).

Testing

Unit testing

Existing unit tests related to notification generation were updated to new expected behavior. Mostly this involved adding new mock calls that were previously not required.

Manual testing

Ran the example app with both a NSE and a foreground lifecycle listener, checking for different variations and manually inspecting behavior:

  1. NSE calls event.preventDefault() and returns immediately -> Notification does not show
  2. NSE calls event.preventDefault() then sleeps for 40 seconds before returning -> Notification shows after 30 seconds.
  3. NSE calls event.notification.setExtender and alters the notification via extender -> Notification is shown, altered
  4. NSE calls event.preventDefault() then starts a thread which calls event.notification.display() after 10 seconds -> Notification shows after 10 seconds.
  5. NSE calls event.preventDefault() then starts a thread which calls event.notification.display() after 40 seconds -> Notification does not show.
  6. Foreground listener calls event.preventDefault() and returns immediately -> Notification does not show
  7. Foreground listener calls event.preventDefault() then sleeps for 40 seconds before returning -> Notification shows after 30 seconds.
  8. Foreground listener calls event.preventDefault() then starts a thread which calls event.notification.display() after 10 seconds -> Notification shows after 10 seconds.
  9. Foreground listener calls event.preventDefault() then starts a thread which calls event.notification.display() after 40 seconds -> Notification does not show.

I also confirmed the notification clicked listener and permission observer for appropriate behavior, though these were just name changes.

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

* Make all notification listeners 0:* (some were 0:1)
* Renamed all "handlers" to be either a "listener" or an "observer" depending on their purpose.  All callbacks now have pattern "onXXXXXX" for each callback.
* Use the terminology "click" instead of "open".
* Add IEventNotifier.hasSubscribers to determine if there are subscribers. A few implementing classes had to add this.
* Replaced `complete()` pattern with `preventDefault()` pattern in NSE notification received callback and foreground onWillDisplay callback.
* Add IDisplayableNotification and IDisplayableMutableNotification which adds a `display()` function to an INotification. This allows the manual display of a notification, when `event.preventDefault()` is called.
* Internally, rework NotificationGenerationProcessor to accommodate `preventDefault` pattern. The notification is now constructed when the notification job is constructed and is never copied/altered until the end of its lifecycle.
* Update example application for new naming conventions and patterns.
* Update for new naming conventions and patterns
Copy link
Contributor

@iAmWillShepherd iAmWillShepherd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had only a few nits that don't need to block this PR; however, a few points need to be addressed before I'm comfortable approving this. The note about the log should be applied to all files that make use of the format I specified although I only called it out once (this is my style in PR review to call something our once and avoid beating a dead 🐴 )

* in order to receive control during the lifecycle of the notification. This handler will *only* receive
* control when the application is in the foreground when the notification is received.
*
* @see [Foreground Notification Received Event | OneSignal Docs](https://documentation.onesignal.com/docs/sdk-notification-event-handlers#foreground-notification-received-event)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use our v11 docs which are here: https://dash.readme.com/project/onesignal/v11.0/docs/sdk-notification-event-handlers

Note that no one has provided a thorough review of these docs, and they may be wildly inaccurate or even incomplete.

brismithers and others added 6 commits April 20, 2023 09:38
…cations/IDisplayableNotification.kt

Co-authored-by: William Shepherd <williamrshepherd@gmail.com>
…cations/INotificationClickResult.kt

Co-authored-by: William Shepherd <williamrshepherd@gmail.com>
…cations/INotificationLifecycleListener.kt

Co-authored-by: William Shepherd <williamrshepherd@gmail.com>
…cations/INotificationServiceExtension.kt

Co-authored-by: William Shepherd <williamrshepherd@gmail.com>
…cations/IDisplayableNotification.kt

Co-authored-by: William Shepherd <williamrshepherd@gmail.com>
@brismithers
Copy link
Contributor Author

@iAmWillShepherd pushed up changes. Please let me know if you have additional feedback!

Copy link
Contributor

@iAmWillShepherd iAmWillShepherd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚢

@iAmWillShepherd
Copy link
Contributor

Renamed all "handlers" to be either a "listener" or an "observer" depending on their purpose. All callbacks now have pattern "onXXXXXX" for each callback.

Could you share your thought process on which term to use? At the moment, it's not clear what you mean by their purpose.

@brismithers
Copy link
Contributor Author

brismithers commented Apr 24, 2023

@iAmWillShepherd

Could you share your thought process on which term to use? At the moment, it's not clear what you mean by their purpose.

Realizing these terms are fuzzy in general, this is based on our team discussions to define as:

  • Listener: When you want to know when an event has occurred. As an example, you are listening for when a "Notification Clicked Event" has occurred.
  • Observer: When you want to know when the state of an object (or property within an object) has changed. As an example, you are observing the changes of the notification permission state on the device.

@brismithers brismithers merged commit ede53a0 into user-model/main Apr 25, 2023
@brismithers brismithers deleted the user-model/notification-events branch April 25, 2023 13:33
@emawby emawby mentioned this pull request May 1, 2023
jinliu9508 pushed a commit that referenced this pull request Jan 31, 2024
[User Model] Rename notification event listeners
jinliu9508 pushed a commit that referenced this pull request Jan 31, 2024
[User Model] Rename notification event listeners
jinliu9508 pushed a commit that referenced this pull request Feb 6, 2024
[User Model] Rename notification event listeners
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