From b90a20424e61976f6c25516825f98f34cdab1fb2 Mon Sep 17 00:00:00 2001 From: mplorentz Date: Mon, 21 Sep 2026 11:54:19 -0400 Subject: [PATCH] Fix Mail.sync to only fire when the user saves, or when contents are loaded from disk --- src/app/mail/index.ts | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/app/mail/index.ts b/src/app/mail/index.ts index 8649efa9..69b356b6 100644 --- a/src/app/mail/index.ts +++ b/src/app/mail/index.ts @@ -216,21 +216,29 @@ export class MailNotifications { } sync() { - return userSettingsValues.subscribe( - throttle(500, async ({email, emailAddress, emailFrequency}) => { - if (email && emailAddress) { - try { - await this.register(emailAddress, emailFrequency) - } catch { - return - } + let reconciledPubkey: string | undefined - await this.enable() - } else { - await this.disable() - } - }), - ) + return userSettingsValues.subscribe(async ({email, emailAddress, emailFrequency}) => { + const $pubkey = app.get().user?.pubkey + if (!$pubkey || reconciledPubkey === $pubkey) return + + // Wait for the real stored settings. userSettingsValues is projected from + // AppData and reads as the default (email: false, emailAddress: "") until + // that loads — acting on that would race the disk with a no-op. Only a + // truthy email comes from stored settings, so keep waiting until we see + // it (a user who has email off simply never reconciles, which is correct). + if (!email || !emailAddress) return + + reconciledPubkey = $pubkey + + try { + await this.register(emailAddress, emailFrequency) + } catch { + return + } + + await this.enable() + }) } _getSubscriptionIdentifier = async (relay: string, key: string) => {