Email notifications: settings UI + mail adapter #4

Open
hudson wants to merge 27 commits from email-notifications into dev
Showing only changes of commit 3e892d76f6 - Show all commits

View file

@ -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"))