mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
revert push notification
This commit is contained in:
parent
a81442d936
commit
4dad4a6fa3
3 changed files with 56 additions and 51 deletions
|
|
@ -1,17 +1,19 @@
|
|||
import express from 'express'
|
||||
import { analytics } from '../../utils/analytics'
|
||||
import { initModels } from '../../server'
|
||||
import { kx } from '../../datalayer/knex_config'
|
||||
import { setClaims } from '../../datalayer/helpers'
|
||||
import { sendEmail } from '../../utils/sendEmail'
|
||||
import { env, homePageURL } from '../../env'
|
||||
import { MulticastMessage } from 'firebase-admin/messaging'
|
||||
import { setClaims } from '../../datalayer/helpers'
|
||||
import { kx } from '../../datalayer/knex_config'
|
||||
import { createPubSubClient } from '../../datalayer/pubsub'
|
||||
import { updatePage } from '../../elastic/pages'
|
||||
import { UserDeviceToken } from '../../entity/user_device_tokens'
|
||||
import { env, homePageURL } from '../../env'
|
||||
import { ContentReader } from '../../generated/graphql'
|
||||
import { DataModels } from '../../resolvers/types'
|
||||
import { updatePage } from '../../elastic/pages'
|
||||
import { createPubSubClient } from '../../datalayer/pubsub'
|
||||
import { initModels } from '../../server'
|
||||
import { getPagesWithReminder, PageReminder } from '../../services/reminders'
|
||||
import { getDeviceTokensByUserId } from '../../services/user_device_tokens'
|
||||
import { analytics } from '../../utils/analytics'
|
||||
import { sendEmail } from '../../utils/sendEmail'
|
||||
import { sendMulticastPushNotifications } from '../../utils/sendNotification'
|
||||
|
||||
interface PageToNotify {
|
||||
title: string
|
||||
|
|
@ -106,19 +108,19 @@ export function remindersServiceRouter() {
|
|||
to: user.email,
|
||||
})
|
||||
|
||||
// // send push notifications
|
||||
// const deviceTokens = await getDeviceTokensByUserId(userId)
|
||||
// if (deviceTokens && deviceTokens.length > 0) {
|
||||
// const message = messageForPages(pageReminders, deviceTokens)
|
||||
// await sendMulticastPushNotifications(userId, message, 'reminder')
|
||||
// }
|
||||
//
|
||||
// if (!deviceTokens) {
|
||||
// console.log('Device tokens not set:', userId)
|
||||
//
|
||||
// res.status(400).send('Device token Not Found')
|
||||
// return
|
||||
// }
|
||||
// send push notifications
|
||||
const deviceTokens = await getDeviceTokensByUserId(userId)
|
||||
if (deviceTokens && deviceTokens.length > 0) {
|
||||
const message = messageForPages(pageReminders, deviceTokens)
|
||||
await sendMulticastPushNotifications(userId, message, 'reminder')
|
||||
}
|
||||
|
||||
if (!deviceTokens) {
|
||||
console.log('Device tokens not set:', userId)
|
||||
|
||||
res.status(400).send('Device token Not Found')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
await updateRemindersStatus(models, userId, pagesToUnarchive, remindAt)
|
||||
|
|
|
|||
|
|
@ -9,9 +9,11 @@ import { ContentReader } from '../generated/graphql'
|
|||
import { analytics } from '../utils/analytics'
|
||||
import { isBase64Image } from '../utils/helpers'
|
||||
import { fetchFavicon } from '../utils/parser'
|
||||
import { sendMulticastPushNotifications } from '../utils/sendNotification'
|
||||
import { addLabelToPage } from './labels'
|
||||
import { SaveContext, saveEmail, SaveEmailInput } from './save_email'
|
||||
import { saveSubscription } from './subscriptions'
|
||||
import { getDeviceTokensByUserId } from './user_device_tokens'
|
||||
|
||||
export interface NewsletterMessage {
|
||||
email: string
|
||||
|
|
@ -93,19 +95,19 @@ export const saveNewsletterEmail = async (
|
|||
})
|
||||
console.log('newsletter label added:', result)
|
||||
|
||||
// // sends push notification
|
||||
// const deviceTokens = await getDeviceTokensByUserId(newsletterEmail.user.id)
|
||||
// if (!deviceTokens) {
|
||||
// console.log('Device tokens not set:', newsletterEmail.user.id)
|
||||
// return true
|
||||
// }
|
||||
//
|
||||
// const multicastMessage = messageForLink(page, deviceTokens)
|
||||
// await sendMulticastPushNotifications(
|
||||
// newsletterEmail.user.id,
|
||||
// multicastMessage,
|
||||
// 'newsletter'
|
||||
// )
|
||||
// sends push notification
|
||||
const deviceTokens = await getDeviceTokensByUserId(newsletterEmail.user.id)
|
||||
if (!deviceTokens) {
|
||||
console.log('Device tokens not set:', newsletterEmail.user.id)
|
||||
return true
|
||||
}
|
||||
|
||||
const multicastMessage = messageForLink(page, deviceTokens)
|
||||
await sendMulticastPushNotifications(
|
||||
newsletterEmail.user.id,
|
||||
multicastMessage,
|
||||
'newsletter'
|
||||
)
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import axios, { AxiosResponse } from 'axios'
|
|||
import { filterPage } from './filter'
|
||||
import { getAuthToken, PubSubData } from './index'
|
||||
import { setLabels } from './label'
|
||||
import { NotificationData, sendNotification } from './notification'
|
||||
import { archivePage, markPageAsRead } from './page'
|
||||
|
||||
export enum RuleActionType {
|
||||
|
|
@ -140,25 +141,25 @@ export const triggerActions = async (
|
|||
filteredPage.readingProgressPercent < 100 &&
|
||||
actionPromises.push(markPageAsRead(apiEndpoint, authToken, data.id))
|
||||
)
|
||||
// case RuleActionType.SendNotification: {
|
||||
// const data: NotificationData = {
|
||||
// title: 'New page added to your library',
|
||||
// body: filteredPage.title,
|
||||
// image: filteredPage.image || undefined,
|
||||
// }
|
||||
case RuleActionType.SendNotification: {
|
||||
const data: NotificationData = {
|
||||
title: 'New page added to your library',
|
||||
body: filteredPage.title,
|
||||
image: filteredPage.image || undefined,
|
||||
}
|
||||
|
||||
// const params = action.params
|
||||
// if (params.length > 0) {
|
||||
// const param = JSON.parse(params[0]) as NotificationData
|
||||
// data.body = param.body || data.body
|
||||
// data.title = param.title || data.title
|
||||
// data.image = param.image || data.image
|
||||
// }
|
||||
const params = action.params
|
||||
if (params.length > 0) {
|
||||
const param = JSON.parse(params[0]) as NotificationData
|
||||
data.body = param.body || data.body
|
||||
data.title = param.title || data.title
|
||||
data.image = param.image || data.image
|
||||
}
|
||||
|
||||
// return actionPromises.push(
|
||||
// sendNotification(apiEndpoint, authToken, data)
|
||||
// )
|
||||
// }
|
||||
return actionPromises.push(
|
||||
sendNotification(apiEndpoint, authToken, data)
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue