fix(gui): read push messages delivered under data

This commit is contained in:
Juan Castro committed 2026-10-26 10:42:27 -04:00
1 parent 01de7af0ae
commit 1222878645
2 files changed
+11 -1

No files matched your search

+4 -1
View File
@@ -82,7 +82,10 @@ function readPushPayload (pushData) {
} catch ( _e ) {
return null;
}
let message = payload && typeof payload === 'object' ? payload.puter : null;
// Providers that only carry string data deliver it under `data`.
let message = payload && typeof payload === 'object'
? (payload.puter ?? payload.data?.puter)
: null;
if ( typeof message === 'string' ) {
try {
message = JSON.parse(message);
+7
View File
@@ -90,6 +90,13 @@ describe('service worker helpers', () => {
expect(context.readPushPayload(pushData({ puter: JSON.stringify(message) }))).toEqual(message);
});
it('reads the message from string data under `data.puter`', () => {
const message = { uid: 'n2', title: 'Hello' };
const payload = { data: { puter: JSON.stringify(message) }, from: '123', messageId: 'm1' };
expect(context.readPushPayload(pushData(payload))).toEqual(message);
expect(context.readPushPayload(pushData({ data: { other: 'x' } }))).toBeNull();
});
it('reads nothing from a missing, garbled or misplaced payload', () => {
expect(context.readPushPayload(null)).toBeNull();
expect(context.readPushPayload({ json: () => { throw new SyntaxError('bad'); } })).toBeNull();