-
-
Notifications
You must be signed in to change notification settings - Fork 201
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
feat: decouple push logic to be platform agnostic #5120
base: main
Are you sure you want to change the base?
feat: decouple push logic to be platform agnostic #5120
Conversation
…form agnostic this controller was ties to web, and was not compatible for react-native. We now have moves the logic that touches firebase and browser built-ins to an isolated file, and expect platforms to inject this into the controller This breaks the controller and forces the platform to inject how push notifications should be received and clicked
reduces complexity that the platform needs to write.
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
@@ -67,6 +67,16 @@ | |||
"default": "./dist/NotificationServicesPushController/index.cjs" | |||
} | |||
}, | |||
"./push-services/web": { |
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.
exposing new subpath exports to differ between web and mobile specific helpers.
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.
This can be done iteratively. We have done web, since there was existing code that we refactored and gutted from this controller.
We will do Mobile after PoC'ing this and seeing if there is value from it.
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.
Also to note that these subpaths are fully isolated and not used anywhere, so they should be tree-shakeable for bundle splitting.
However specific modules for web/mobile might run into lavamoat issues... or maybe not... we'll see.
* determine the config used for push notification services | ||
*/ | ||
platform: 'extension' | 'mobile'; | ||
pushService: PushService; |
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.
The controller now must be initialised with this Push Service interface.
The /web/push-helpers
can assist extension when injecting.
We will see if we can do the same for mobile.
NotificationServicesPushControllerMessenger, | ||
} from '..'; | ||
|
||
export const buildPushPlatformNotificationsControllerMessenger = |
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.
This mock was lifted out of a test file, and exported, so it can be reused in other tests.
import { | ||
listenToPushNotificationsClicked, | ||
listenToPushNotificationsReceived, | ||
} from './push/push-web'; |
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.
In the initial design, we did a decent start at decoupling the webby parts from this controller (to make it agnostic). However the issue was we were directly importing and using the web module directly!
export function createSubscribeToPushNotifications(props: { | ||
onReceivedHandler: ( | ||
notification: Types.INotification, | ||
) => void | Promise<void>; | ||
onClickHandler: ( | ||
e: NotificationEvent, | ||
notification: Types.INotification, | ||
) => void; | ||
messenger: NotificationServicesPushControllerMessenger; | ||
}) { | ||
return async function (env: PushNotificationEnv) { |
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.
This is a scary interface, but see tests on how to use it.
- This is a func that returns a func (curried function), mostly since we need the return function to have the same interface for web and mobile so we can correctly inject it.
- The
props
we expose is to add some extra customisability from the platform. E.g. when you receive a notification what icon or thing show we show; when you click a notification, where should this navigate you to.- It allows the platform to take control of showing/interacting, but the core can still control publishing events; and when to invoke the methods the platform provides.
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.
A lot of word vomit here, I'll record a video once this has been PoC'ed and ready for review.
…ouple-push-logic-to-be-platform-agnostic
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
Explanation
Decouples web push notifications so that the controller is platform agnostic.
This controller was tied heavily to web, and was not compatible for mobile use (react-native). We have now isolated and moved the web specific code into a single file (
web/push-helpers.ts
), and we expect the platforms to inject the push service interface into the controller (which allows platforms to controller how to display push notifications and click on push notifications).This is a large restructuring and is a breaking change.
References
Changelog
@metamask/notification-services-controller
PushService
NotificationServicesPushController
config property to inject aPushService
interface during controller creation.@metamask/notification-services-controller/push-services/web
to help web platforms inject push-services into the push controller.Checklist