From 2822240d0f70521523c9559589e6aa25bcbe2852 Mon Sep 17 00:00:00 2001 From: 0xsysr3ll <0xsysr3ll@pm.me> Date: Wed, 3 Dec 2025 21:38:36 +0100 Subject: [PATCH] fix(webpush): cleanup is too agressive - avoid removing active subscriptions Signed-off-by: 0xsysr3ll <0xsysr3ll@pm.me> --- server/routes/user/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/routes/user/index.ts b/server/routes/user/index.ts index 36ac48f73..9860d0adf 100644 --- a/server/routes/user/index.ts +++ b/server/routes/user/index.ts @@ -25,7 +25,7 @@ import { getHostname } from '@server/utils/getHostname'; import { Router } from 'express'; import gravatarUrl from 'gravatar-url'; import { findIndex, sortBy } from 'lodash'; -import { In } from 'typeorm'; +import { In, Not } from 'typeorm'; import userSettingsRoutes from './usersettings'; const router = Router(); @@ -227,12 +227,16 @@ router.post< // Clean up old subscriptions from the same device (userAgent) for this user // iOS can silently refresh endpoints, leaving stale subscriptions in the database + // Only clean up if we're creating a new subscription (not updating an existing one) if (req.body.userAgent) { const staleSubscriptions = await userPushSubRepository.find({ relations: { user: true }, where: { userAgent: req.body.userAgent, user: { id: req.user?.id }, + // Only remove subscriptions with different endpoints (stale ones) + // Keep subscriptions that might be from different browsers/tabs + endpoint: Not(req.body.endpoint), }, });