mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
creates or updates subscription only if their is a valid unsubscribe link
This commit is contained in:
parent
e7691e7c3e
commit
f28912728a
1 changed files with 19 additions and 17 deletions
|
|
@ -1,18 +1,18 @@
|
|||
import { MulticastMessage } from 'firebase-admin/messaging'
|
||||
import { createPubSubClient } from '../datalayer/pubsub'
|
||||
import { updatePage } from '../elastic/pages'
|
||||
import { Page } from '../elastic/types'
|
||||
import { NewsletterEmail } from '../entity/newsletter_email'
|
||||
import { UserDeviceToken } from '../entity/user_device_tokens'
|
||||
import { env } from '../env'
|
||||
import { ContentReader } from '../generated/graphql'
|
||||
import { analytics } from '../utils/analytics'
|
||||
import { SaveContext, saveEmail, SaveEmailInput } from './save_email'
|
||||
import { Page } from '../elastic/types'
|
||||
import { addLabelToPage } from './labels'
|
||||
import { saveSubscription } from './subscriptions'
|
||||
import { NewsletterEmail } from '../entity/newsletter_email'
|
||||
import { fetchFavicon } from '../utils/parser'
|
||||
import { updatePage } from '../elastic/pages'
|
||||
import { isBase64Image } from '../utils/helpers'
|
||||
import { fetchFavicon } from '../utils/parser'
|
||||
import { addLabelToPage } from './labels'
|
||||
import { updateReceivedEmail } from './received_emails'
|
||||
import { SaveContext, saveEmail, SaveEmailInput } from './save_email'
|
||||
import { saveSubscription } from './subscriptions'
|
||||
|
||||
export interface NewsletterMessage {
|
||||
from: string
|
||||
|
|
@ -75,16 +75,18 @@ export const saveNewsletterEmail = async (
|
|||
}
|
||||
}
|
||||
|
||||
// creates or updates subscription
|
||||
const subscriptionId = await saveSubscription({
|
||||
userId: newsletterEmail.user.id,
|
||||
name: data.author,
|
||||
newsletterEmail,
|
||||
unsubscribeMailTo: data.unsubMailTo,
|
||||
unsubscribeHttpUrl: data.unsubHttpUrl,
|
||||
icon: page.siteIcon,
|
||||
})
|
||||
console.log('subscription saved', subscriptionId)
|
||||
// creates or updates subscription only if their is a valid unsubscribe link
|
||||
if (data.unsubMailTo || data.unsubHttpUrl) {
|
||||
const subscriptionId = await saveSubscription({
|
||||
userId: newsletterEmail.user.id,
|
||||
name: data.author,
|
||||
newsletterEmail,
|
||||
unsubscribeMailTo: data.unsubMailTo,
|
||||
unsubscribeHttpUrl: data.unsubHttpUrl,
|
||||
icon: page.siteIcon,
|
||||
})
|
||||
console.log('subscription saved', subscriptionId)
|
||||
}
|
||||
|
||||
// adds newsletters label to page
|
||||
const result = await addLabelToPage(saveCtx, page.id, {
|
||||
|
|
|
|||
Loading…
Reference in a new issue