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 Events #678

Merged
merged 22 commits into from
May 9, 2023
Merged

Conversation

emawby
Copy link
Contributor

@emawby emawby commented May 5, 2023

Description

One Line Summary

This is a large PR that includes changes to events across multiple features in the SDK.

Details

Privacy Consent - the new method names are:
consentRequired(boolean required) - set to require users to opt in to OneSignal data
consentGiven(boolean given) - set when the user has opted in/out to OneSignal data

Triggers
the addTrigger(s) methods now require values in the key value pair to be strings.

permissionNative
This is a new method that allows you to get the exact permission status for iOS devices (ephemeral, provisional, etc)

Live Activities
The enter and exit liveactivities methods have been moved to their own namespace.

OneSignal.LiveActivities.enter(String activityId, String token)
OneSignal.LiveActivities.exit(String activityId)

Notification Permission Observer
The OneSignalPermissionObserver permission changed function has been renamed and only a boolean is passed as a parameter.
onNotificationPermissionDidChange(boolean permission)

In App Message Lifecycle Events
Instead of four separate listeners apps now implement OneSignalInAppMessageLifecycleListener which has the four methods corresponding to the In App Message lifecycle.

void onWillDisplayInAppMessage(OSInAppMessageWillDisplayEvent event) {}
void onDidDisplayInAppMessage(OSInAppMessageDidDisplayEvent event) {}
void onWillDismissInAppMessage(OSInAppMessageWillDismissEvent event) {}
void onDidDismissInAppMessage(OSInAppMessageDidDismissEvent event) {}

Each event's parameter contains the OSInAppMessage corresponding to the event. (event.message)

The implementing class should call OneSignal.InAppMessages.addLifecycleListener(this);

In App Message Click Events
In App Message actions are now handled by implementing a OneSignalInAppMessageClickListener with the following function:
void onClickInAppMessage(OSInAppMessageClickEvent event)
The click event parameter has an OSInAppMessage and an OSInAppMessageClickResult.
The OSInAppMessageClickResult contains click's actionId and the url, if any, that was launched.

The implementing class should call OneSignal.InAppMessages.addClickListener(this);

Notification Will Display Events
The willShowInForegroundHandler is now the OneSsignalNotificationLifecycleListener which has the onWillDisplay function.
void onWillDisplayNotification(OSNotificationWillDisplayEvent event)
To prevent the notification from being displayed call event.preventDefault();
To then later display the notification call event.notification.display();

The implementing class should call OneSignal.Notifications.addLifecycleListener(this);

Notification Click Events
setNotificationOpenedHandler has been replaced with the OneSignalNotificationClickListener
void onClickNotification(OSNotificationClickEvent event)
The click event has the OSNotification that was clicked and a OSNotificationClickResult
The OSNotificationClickResult has the actionId and the url if any that was opened from the click.

The implementing class should call OneSignal.Notifications.addClickListener(this);

Push Subscription Observer
The OneSignalPushSubscriptionObserver class's function is now named onOSPushSubscriptionChange
void onOSPushSubscriptionChangedWithState(OSPushSubscriptionChangedState state)
The state parameter has a previous and a current OSPushSubscriptionState

Motivation

Update naming for user model api

Scope

In App Messages, Notifications, Subscriptions, Permissions, Privacy Consent

Testing

Manual testing

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

emawby added 5 commits May 3, 2023 13:10
@emawby emawby changed the base branch from main to user_model/main May 5, 2023 17:51
@fhboswell fhboswell requested review from fhboswell and removed request for fhboswell May 5, 2023 17:59
Copy link
Contributor

@fhboswell fhboswell left a comment

Choose a reason for hiding this comment

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

Looks good, didn't personally test.

Reviewed 29 of 29 files at r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @emawby)

@emawby emawby force-pushed the user_model/rename_events branch 5 times, most recently from e9f0440 to c7945fa Compare May 6, 2023 00:29
@emawby emawby force-pushed the user_model/rename_events branch from c7945fa to 6bef96b Compare May 6, 2023 00:53
In order to get preventDefault() and display() to work the bridge layer listener needs to call preventDefault() so that the notification does not display before the flutter listeners have had a chance to call preventDefault(). Once all of the flutter listeners have responded to the event, if none of them have called preventDefault then the bridge layer will call display().
@emawby emawby force-pushed the user_model/rename_events branch from 6bef96b to 679d712 Compare May 6, 2023 01:29
@emawby emawby requested review from jkasten2 and nan-li May 9, 2023 17:18
@emawby emawby requested review from shepherd-l and jennantilla May 9, 2023 17:18
Copy link
Member

@jkasten2 jkasten2 left a comment

Choose a reason for hiding this comment

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

Instead of using classes for events for dart I was thinking it would be better if these were Functions instead. This seems more of what Flutter developers would expect as this is they way their API mostly works too.

Example:

OneSignal.InAppMessages.addLifecycleListener(this);

Instead we have this in the dropbox paper:

OneSignal.InAppMessages.addWillDisplayListener((event) { });
OneSignal.InAppMessages.addDidDisplayListener((event) { });
OneSignal.InAppMessages.addWillDismissListener((event) { });
OneSignal.InAppMessages.addDidDismissListener((event) { });

Copy link
Contributor Author

@emawby emawby left a comment

Choose a reason for hiding this comment

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

Gotcha I have updated all of our events to use functions instead of classes.

Reviewable status: 16 of 29 files reviewed, all discussions resolved (waiting on @fhboswell, @jennantilla, @nan-li, and @shepherd-l)

@emawby emawby requested a review from jkasten2 May 9, 2023 19:43
Copy link
Member

@jkasten2 jkasten2 left a comment

Choose a reason for hiding this comment

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

The event changes look all good to me now!

@emawby emawby merged commit b8e01be into user_model/main May 9, 2023
@emawby emawby deleted the user_model/rename_events branch May 9, 2023 20:53
@emawby emawby mentioned this pull request May 9, 2023
nan-li pushed a commit that referenced this pull request Jan 31, 2024
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