diff --git a/src/app/mail/index.ts b/src/app/mail/index.ts index 133e46c9..f11550f4 100644 --- a/src/app/mail/index.ts +++ b/src/app/mail/index.ts @@ -28,7 +28,7 @@ export class MailNotifications { let authEvent try { - authEvent = await $signer.sign(await makeHttpAuth(EMAIL_NOTIFICATION_SERVER, "POST")) + authEvent = await $signer.sign(await makeHttpAuth(EMAIL_NOTIFICATION_SERVER, "PUT")) } catch (e) { emailNotificationState.set({error: "Failed to create authentication. Check your signer."}) throw new Error("Failed to sign NIP-98 auth", {cause: e}) @@ -39,7 +39,7 @@ export class MailNotifications { let res try { res = await fetch(buildUrl(EMAIL_NOTIFICATION_SERVER, "subscription", "email"), { - method: "POST", + method: "PUT", body: JSON.stringify({email, frequency, pubkey: $user.pubkey}), headers: {Authorization: authHeader, "Content-Type": "application/json"}, }) @@ -124,26 +124,10 @@ export class MailNotifications { return userSettingsValues.subscribe( throttle(500, async ({email, emailAddress, emailFrequency}) => { if (email && emailAddress) { - const existing = await this._lookup() - - if ( - 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 { - return - } + try { + await this.register(emailAddress, emailFrequency) + } catch { + return } await this.enable() @@ -154,18 +138,6 @@ 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"))