Fix Mail.sync to only fire when the user saves, or when contents are loaded from disk
All checks were successful
CI / lint-check-build (pull_request) Successful in 4m9s

This commit is contained in:
mplorentz 2026-09-21 11:54:19 -04:00
parent ce8920123f
commit b90a20424e

View file

@ -216,9 +216,21 @@ export class MailNotifications {
}
sync() {
return userSettingsValues.subscribe(
throttle(500, async ({email, emailAddress, emailFrequency}) => {
if (email && emailAddress) {
let reconciledPubkey: string | undefined
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 {
@ -226,11 +238,7 @@ export class MailNotifications {
}
await this.enable()
} else {
await this.disable()
}
}),
)
})
}
_getSubscriptionIdentifier = async (relay: string, key: string) => {