fix: per-account push subscriptions so multi-account notifications work #298

This commit is contained in:
Linus Rath
2026-05-16 22:50:01 +02:00
parent 356abcfc2d
commit bb7e1c4538
4 changed files with 166 additions and 42 deletions
+14 -1
View File
@@ -98,6 +98,16 @@ async function handlePush(event) {
? payload.accountLabel
: "";
// JMAP StateChange wraps changes in { changed: { [accountId]: {...} } }.
// The relay forwards a single account's StateChange per push, so the first
// key is the one this notification is for. Without this the preview API
// would just fall back to the first signed-in slot and surface mail from
// the wrong account.
const changed = payload && payload.changed && typeof payload.changed === "object"
? payload.changed
: null;
const accountId = changed ? Object.keys(changed)[0] || "" : "";
// Best effort: ask the webmail to look up the latest unread email so we can
// build a useful notification. If the request fails (offline, session
// expired, server down) we fall back to a generic "New mail" so the user
@@ -105,7 +115,10 @@ async function handlePush(event) {
let preview = null;
let previewOk = false;
try {
const res = await fetch(`${BASE_PATH}/api/push/preview`, {
const previewUrl = accountId
? `${BASE_PATH}/api/push/preview?accountId=${encodeURIComponent(accountId)}`
: `${BASE_PATH}/api/push/preview`;
const res = await fetch(previewUrl, {
credentials: "include",
cache: "no-store",
});