adding webpush'

This commit is contained in:
aeroreyna
2022-04-23 22:52:46 -07:00
parent 70fffbf55d
commit f7c016264b
5 changed files with 256 additions and 40 deletions

View File

@@ -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);
},