fix(push): reinstalled app replaces its old subscription; devices listed and removable
MindSift CI & Docker Release / Build, Test in Container & Push (push) Failing after 2m8s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
sandrodachandClaude Opus 5.5 committed 2026-10-31 11:59:40 +01:00
1 parent f76b0f34ff
commit 5b636b66e2
9 files changed
+123 -14

No files matched your search

+35 -1
View File
@@ -64,7 +64,40 @@ export async function enablePush(): Promise<void> {
throw new Error('Der Browser hat die Anmeldung beim Push-Dienst abgelehnt (Berechtigung blockiert oder Push-Dienst nicht erreichbar)');
}
}
await api.subscribePush(sub.toJSON(), deviceName());
// The address this browser registered before is dead once it has a new one (e.g. after reinstalling
// the app): the server drops it right away instead of counting it as another device
const previous = readStoredEndpoint();
await api.subscribePush(sub.toJSON(), deviceName(), previous && previous !== sub.endpoint ? previous : undefined);
storeEndpoint(sub.endpoint);
}
const ENDPOINT_KEY = 'mindsift_push_endpoint';
function readStoredEndpoint(): string | null {
try {
return localStorage.getItem(ENDPOINT_KEY);
} catch {
return null;
}
}
function storeEndpoint(endpoint: string | null): void {
try {
if (endpoint) localStorage.setItem(ENDPOINT_KEY, endpoint);
else localStorage.removeItem(ENDPOINT_KEY);
} catch {
// storage blocked: the dead device is removed on the next push instead
}
}
/** Removes one of the own devices (e.g. an old installation) on the server. */
export async function removePushDevice(endpoint: string): Promise<void> {
const here = await currentPushSubscription();
if (here?.endpoint === endpoint) {
await disablePush();
return;
}
await api.unsubscribePush(endpoint);
}
export async function disablePush(): Promise<void> {
@@ -73,4 +106,5 @@ export async function disablePush(): Promise<void> {
const endpoint = sub.endpoint;
await sub.unsubscribe().catch(() => false);
await api.unsubscribePush(endpoint).catch(() => {});
storeEndpoint(null);
}