adding webpush'
This commit is contained in:
@@ -1,10 +1,18 @@
|
||||
const nodemailer = require("nodemailer");
|
||||
const DBGetter = require("./mongoDB.js");
|
||||
const { Expo } = require('expo-server-sdk');
|
||||
const webPush = require('web-push');
|
||||
|
||||
const sendWebNotification = async (subscription, title, body) => {
|
||||
const payload = JSON.stringify({
|
||||
title,
|
||||
body
|
||||
});
|
||||
webPush.sendNotification(subscription, payload);
|
||||
}
|
||||
|
||||
const sendPushNotification = async (profileToken, body, data) => {
|
||||
if(!profileToken) return 0;
|
||||
if (!profileToken) return 0;
|
||||
let expo = new Expo();
|
||||
|
||||
// Create the messages that you want to send to clients
|
||||
@@ -376,6 +384,7 @@ const Notifications = {
|
||||
}
|
||||
const notifBody = `${senderProfile.profile.firstName} post in your profile`;
|
||||
sendPushNotification(profile.token, notifBody, {});
|
||||
sendWebNotification(profile.webSubscription, notifBody, message)
|
||||
DB.addNotification(toProfileId, notifBody, post._id, null, senderProfile._id);
|
||||
return youGotANewPostTemplate(profile, user.username, senderProfile, message);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user