Skip to content

Commit 374dc78

Browse files
committed
Polishing
1 parent 8911188 commit 374dc78

File tree

6 files changed

+10
-14
lines changed

6 files changed

+10
-14
lines changed

.changeset/strange-crabs-tell.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
---
66

77
Add `getToken(options:{serviceWorkerRegistration, vapidKey})`,`onBackgroundMessage`.
8-
Deprecate `setBackgroundHandler`, `onTokenRefresh`, `useVapidKey`, `useServiceWorker`, `getToken`.
8+
Deprecate `setBackgroundMessageHandler`, `onTokenRefresh`, `useVapidKey`, `useServiceWorker`, `getToken`.
99

1010
Add Typing `MessagePayload`, `NotificationPayload`, `FcmOptions`.

packages/installations/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
"@firebase/app-types": "0.x"
4545
},
4646
"dependencies": {
47-
"@firebase/app": "^0.6.7",
48-
"@firebase/component": "0.1.15",
4947
"@firebase/installations-types": "0.3.4",
5048
"@firebase/util": "0.2.50",
5149
"@firebase/component": "0.1.16",

packages/messaging/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"@firebase/util": "0.2.50",
3333
"@firebase/component": "0.1.16",
3434
"idb": "3.0.2",
35-
"tslib": "1.11.1"
35+
"tslib": "^1.11.1"
3636
},
3737
"devDependencies": {
3838
"rollup": "2.21.0",

packages/messaging/src/controllers/sw-controller.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ describe('SwController', () => {
288288
const bgMessageHandlerSpy = spy();
289289
const showNotificationSpy = spy(self.registration, 'showNotification');
290290

291-
swController.setBackgroundMessageHandler(bgMessageHandlerSpy);
291+
swController.onBackgroundMessage(bgMessageHandlerSpy);
292292

293293
await callEventListener(
294294
makeEvent('push', {

packages/messaging/src/controllers/sw-controller.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ export class SwController implements FirebaseMessaging, FirebaseService {
8686
* must be shown. The callback will be given the data from the push message.
8787
*/
8888
setBackgroundMessageHandler(callback: BgMessageHandler): void {
89+
this.isOnBackgroundMessageUsed = false;
90+
8991
if (!callback || typeof callback !== 'function') {
9092
throw ERROR_FACTORY.create(ErrorCode.INVALID_BG_HANDLER);
9193
}
@@ -173,7 +175,7 @@ export class SwController implements FirebaseMessaging, FirebaseService {
173175
if (!internalPayload) {
174176
console.debug(
175177
TAG +
176-
'failed to get parse MessagePayload from the PushEvent. Skip handling the push.'
178+
'failed to get parsed MessagePayload from the PushEvent. Skip handling the push.'
177179
);
178180
return;
179181
}
@@ -191,6 +193,8 @@ export class SwController implements FirebaseMessaging, FirebaseService {
191193
isNotificationShown = true;
192194
}
193195

196+
// MessagePayload is only passed to `onBackgroundMessage`. Skip passing MessagePayload for
197+
// the legacy `setBackgroundMessageHandler` to preserve the SDK behaviors.
194198
if (
195199
isNotificationShown === true &&
196200
this.isOnBackgroundMessageUsed === false

packages/messaging/src/controllers/window-controller.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,9 @@ export class WindowController implements FirebaseMessaging, FirebaseService {
120120
}
121121

122122
async updateVapidKey(vapidKey?: string | undefined): Promise<void> {
123-
if (!!this.vapidKey && !!vapidKey && this.vapidKey !== vapidKey) {
123+
if (!!vapidKey) {
124124
this.vapidKey = vapidKey;
125-
}
126-
127-
if (!this.vapidKey && !!vapidKey) {
128-
this.vapidKey = vapidKey;
129-
}
130-
131-
if (!this.vapidKey && !vapidKey) {
125+
} else if (!this.vapidKey) {
132126
this.vapidKey = DEFAULT_VAPID_KEY;
133127
}
134128
}

0 commit comments

Comments
 (0)