From 3e892d76f632f4a29d94afdd52eaf45bdf366bff Mon Sep 17 00:00:00 2001 From: mplorentz Date: Tue, 1 Sep 2026 15:59:30 -0400 Subject: [PATCH] Sync email settings only when changed --- src/app/mail/index.ts | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/app/mail/index.ts b/src/app/mail/index.ts index 27695bba..133e46c9 100644 --- a/src/app/mail/index.ts +++ b/src/app/mail/index.ts @@ -123,14 +123,22 @@ export class MailNotifications { sync() { return userSettingsValues.subscribe( throttle(500, async ({email, emailAddress, emailFrequency}) => { - const current = emailNotificationState.get() - if (email && emailAddress) { + const existing = await this._lookup() + if ( - !current.callback || - current.email !== emailAddress || - current.frequency !== emailFrequency + existing?.confirmed && + existing.email === emailAddress && + existing.frequency === emailFrequency ) { + emailNotificationState.set({ + key: existing.key, + callback: existing.callback, + email: existing.email, + frequency: existing.frequency, + error: undefined, + }) + } else { try { await this.register(emailAddress, emailFrequency) } catch { @@ -146,6 +154,18 @@ export class MailNotifications { ) } + async _lookup() { + const {pubkey} = User.require(app.get()) + + const res = await fetch( + `${buildUrl(EMAIL_NOTIFICATION_SERVER, "subscription", "email")}?pubkey=${pubkey}`, + ) + + if (!res.ok) return undefined + + return res.json() + } + _getSubscriptionIdentifier = (relay: string, key: string) => String(hash(relay + key + device.get() + "email"))