mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-05 00:14:18 +00:00
fix: show a notification even if building it fails
This commit is contained in:
@@ -187,4 +187,26 @@ describe('which login a push is for', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when building the notification goes wrong', () => {
|
||||
it('still shows one', async () => {
|
||||
const { push, shade } = loadWorker(() => ({ unreadTotal: 1, slot: 0, login: 'fp', email: mail('e1') }), {
|
||||
globals: { Notification: { get maxActions() { throw new Error('no such thing'); } } },
|
||||
});
|
||||
await push(delivery('a', 'e1'));
|
||||
expect(shade.size).toBe(1);
|
||||
});
|
||||
|
||||
it('shows one for a push that is no JSON at all', async () => {
|
||||
const { dispatch, shade } = loadWorker(() => null);
|
||||
await dispatch('push', { data: { json: () => { throw new SyntaxError('not JSON'); } } });
|
||||
expect(shade.size).toBe(1);
|
||||
});
|
||||
|
||||
it('shows one for a push without any data', async () => {
|
||||
const { dispatch, shade } = loadWorker(() => null);
|
||||
await dispatch('push', {});
|
||||
expect(shade.size).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
// -- end of cases --
|
||||
|
||||
+13
-1
@@ -604,7 +604,19 @@ async function handlePush(event) {
|
||||
? []
|
||||
: Object.keys(changed).filter((id) => changed[id] && typeof changed[id] === "object" && "EmailDelivery" in changed[id]);
|
||||
for (const accountId of withNewMail.length > 0 ? withNewMail : [named]) {
|
||||
await notifyAccount(accountId, emailIds, accountLabel);
|
||||
try {
|
||||
await notifyAccount(accountId, emailIds, accountLabel);
|
||||
} catch (_) {
|
||||
// Nothing above may cost the user the alert, or a browser its quota for
|
||||
// this site: see showWithoutAlert.
|
||||
await self.registration.showNotification(accountLabel ? `New mail (${accountLabel})` : "New mail", {
|
||||
body: "You have new mail",
|
||||
tag: "bulwark-mail:" + (accountId || "default"),
|
||||
icon: `${BASE_PATH}/api/pwa-icon/192`,
|
||||
badge: `${BASE_PATH}/api/pwa-icon/192`,
|
||||
data: { kind: "mail-list", accountId },
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user