From 7caa72be4fc0ecc29a7cd58be729b07022b4ee40 Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Mon, 31 Aug 2026 23:00:20 +0200 Subject: [PATCH] fix(notifications): stop replacing a chosen UnifiedPush distributor on restart --- .../notifications/UnifiedPushTransport.test.ts | 6 +++--- .../settings/notifications/UnifiedPushTransport.ts | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/app/features/settings/notifications/UnifiedPushTransport.test.ts b/src/app/features/settings/notifications/UnifiedPushTransport.test.ts index ef513a962..a9abac66a 100644 --- a/src/app/features/settings/notifications/UnifiedPushTransport.test.ts +++ b/src/app/features/settings/notifications/UnifiedPushTransport.test.ts @@ -212,15 +212,15 @@ describe('UnifiedPush distributor state helpers', () => { expect(unifiedPushApi.setDistributor).toHaveBeenCalledOnce(); }); - it('replaces a stale selected distributor with the first available one', async () => { + it('never replaces an explicitly chosen distributor that the scan did not list', async () => { unifiedPushApi.setDistributor.mockResolvedValue(undefined); await expect( ensureUnifiedPushDistributorSelection( ['org.unifiedpush.distributor.ntfy', 'org.unifiedpush.distributor.nextpush'], 'org.unifiedpush.distributor.removed' ) - ).resolves.toBe('org.unifiedpush.distributor.ntfy'); - expect(unifiedPushApi.setDistributor).toHaveBeenCalledWith('org.unifiedpush.distributor.ntfy'); + ).resolves.toBe(''); + expect(unifiedPushApi.setDistributor).not.toHaveBeenCalled(); }); it('persists a selected distributor through the transport helper', async () => { diff --git a/src/app/features/settings/notifications/UnifiedPushTransport.ts b/src/app/features/settings/notifications/UnifiedPushTransport.ts index 37278d8a5..119cdde86 100644 --- a/src/app/features/settings/notifications/UnifiedPushTransport.ts +++ b/src/app/features/settings/notifications/UnifiedPushTransport.ts @@ -165,11 +165,13 @@ export async function ensureUnifiedPushDistributorSelection( distributors: string[], selectedDistributor: string ): Promise { - const distributor = - selectedDistributor && distributors.includes(selectedDistributor) - ? selectedDistributor - : distributors[0]; + if (selectedDistributor) { + if (!distributors.includes(selectedDistributor)) return ''; + await saveUnifiedPushDistributor(selectedDistributor); + return selectedDistributor; + } + const distributor = distributors[0]; if (!distributor) return ''; await saveUnifiedPushDistributor(distributor);