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
All checks were successful
CI / lint-check-build (pull_request) Successful in 4m9s
This commit is contained in:
parent
ce8920123f
commit
b90a20424e
1 changed files with 22 additions and 14 deletions
|
|
@ -216,21 +216,29 @@ export class MailNotifications {
|
||||||
}
|
}
|
||||||
|
|
||||||
sync() {
|
sync() {
|
||||||
return userSettingsValues.subscribe(
|
let reconciledPubkey: string | undefined
|
||||||
throttle(500, async ({email, emailAddress, emailFrequency}) => {
|
|
||||||
if (email && emailAddress) {
|
|
||||||
try {
|
|
||||||
await this.register(emailAddress, emailFrequency)
|
|
||||||
} catch {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.enable()
|
return userSettingsValues.subscribe(async ({email, emailAddress, emailFrequency}) => {
|
||||||
} else {
|
const $pubkey = app.get().user?.pubkey
|
||||||
await this.disable()
|
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) => {
|
_getSubscriptionIdentifier = async (relay: string, key: string) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue