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] Fix notification event types; click, willDisplay, and dismiss #1078

Merged
merged 5 commits into from
Aug 8, 2023

Conversation

jkasten2
Copy link
Member

@jkasten2 jkasten2 commented Aug 8, 2023

Description

1 Line Summary

Fix public SDK API field names and types for the notification event types; click, willDisplay, and dismiss

Details

Scope of changes summary

The changes are related to OSNotification and the places where it is used, in changing the fields it was discovered there is a lot of tight coupling with other things such as indexDb and webhooks. While they may seem unrelated changes to those were needed and refactored to a point to decouple them for the future.

OSNotification

This wasn't using the same field names as Android and iOS so corrected it to match and renamed it to an interface IOSNotification.

Notification Events:

  • click - This was using NotificationClickResult instead of NotificationClickEvent
  • dismiss - This didn't' have it's own event, introduced NotificationDismissEvent
  • foregroundWillDisplay - This had its own type already, but wasn't formatted correctly which was missed due to missing types

indexDb

Since IOSNotification changed as well as the format for events we introduced OSNotificationDatabaseSerializer.ts to convert the format to and from the database. This was done so no migration is needed, and also to decouple and future proof any changes to these classes.

  • This includes the the click handling, as well as clicks and receives for outcomes.

Webhooks

Since we added type where they were missing, executeWebhooks needed to be refactored as it was account for 3 different types of payloads; click, display, and dismiss. This was refactored into 3 different payload classes, again to decouple and future proof field changes.

Validation

Tests

Test on Chrome on macOS. Ensuring notifications are displayed and click handling directs to the correct URL.

Info

Checklist

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

Programming Checklist
Interfaces:

  • Don't use default export
  • New interfaces are in model files

Functions:

  • Don't use default export
  • All function signatures have return types
  • Helpers should not access any data but rather be given the data to operate on.

Typescript:

  • No Typescript warnings
  • Avoid silencing null/undefined warnings with the exclamation point

Other:

  • Iteration: refrain from using elem of array syntax. Prefer forEach or use map
  • Avoid using global OneSignal accessor for context if possible. Instead, we can pass it to function/constructor so that we don't call OneSignal.context

Screenshots

Info

Checklist

  • I have included screenshots/recordings of the intended results or explained why they are not needed

Related Tickets



This change is Reviewable

Changed OSNotification field names to match Android and iOS;
example id -> notificationId
Rename OSNotificationDataPayload -> OSMinifiedNotificationPayload
Logic for parsing was moved out of ServiceWorker.ts
Fixed the public types for these and interduced them as types where they
were missing.
Improved ClickedNotifications name to be PendingClickedNotifications
to make it clear these are events that are to be fired once conditions
are met.
We changed the OSNotification object format however we need to continue
serializing in the same format with indexDb. This is so existing event
after migrating to the new major version. Defining serializing mapping
like this ensures any future changes also don't break compiablity with
indexDb records going forward.
This was done for the same reasons as the last commit
The single executeWebhooks method was handlig 3 different events, each
with their own slightly different paload format. We split this out into
3 different classes to map the payloads. And agian, for the some reasons
as the other serializers / maps is to ensure the field name changes
don't cause breaking changes in the future.
@jkasten2 jkasten2 requested review from rgomezp and emawby August 8, 2023 21:35
*/
readonly launchURL?: string;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

newline

@@ -19,7 +24,7 @@ class AppState {
// default true
lastKnownOptedIn: boolean = true;

clickedNotifications: ClickedNotifications | undefined;
pendingNotificationClickEvents: PendingNotificationClickEvents | undefined;
}

export { AppState };
Copy link
Contributor

Choose a reason for hiding this comment

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

newline

export class OSWebhookSender {
async send(payload: IOSWebhookEventPayload): Promise<void> {
const webhookTargetUrl = await Database.get<string>('Options', `webhooks.${payload.event}`);
if (!webhookTargetUrl)
Copy link
Contributor

Choose a reason for hiding this comment

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

brackets

readonly url?: string;
}

export class NotificationClickForOpenHandlingSerializer {
Copy link
Member Author

Choose a reason for hiding this comment

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

add comment here to check the top of the file for more details.

  • This way you see hint in VS code / yoru IDE.

readonly url?: string;
}

export class NotificationClickForOpenHandlingSerializer {
Copy link
Member Author

Choose a reason for hiding this comment

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

Look into adding a test that checks to ensure this is being used to serialize data in and out of indexDb, checking that nothing is doing it directly.

@jkasten2 jkasten2 merged commit 92608b8 into user-model/v1 Aug 8, 2023
@jkasten2 jkasten2 deleted the user-model/fix-notification-event-types branch August 8, 2023 23:29
@jkasten2 jkasten2 mentioned this pull request Aug 16, 2023
13 tasks
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.

2 participants