Skip to content
Permalink
Browse files

Merge remote-tracking branch 'upstream/master'

  • Loading branch information...
toBeOfUse committed Jun 22, 2019
2 parents df05847 + 70221f5 commit d46dcd48c15efbe17b7678ce1840012de23d6e57
@@ -0,0 +1,89 @@
const nodemailer = require("nodemailer");
const nodemailerHbs = require('nodemailer-express-handlebars');
const path = require('path');
const schedule = require('node-schedule');
const moment = require('moment');
const auth = require(global.appRoot + '/config/auth.js');

// create reusable transporter object using the default SMTP transport
transporter = nodemailer.createTransport({
host: "box.raphaelkabo.com",
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: 'updates@sweet.sh',
pass: auth.mailServer
}
});

nodemailerHbsOptions = {
viewEngine: {
extName: ".handlebars",
partialsDir: global.appRoot + "/views/emails",
defaultLayout: false // <----- added this
},
viewPath: global.appRoot + "/views/emails",
extName: ".handlebars"
};

transporter.use('compile', nodemailerHbs(nodemailerHbsOptions));

async function sendUpdateEmail(type){

email = {};
if (type == "daily") {
email.subject = "sweet daily update 🍭"
} else if (type == "weekly") {
email.subject = "sweet weekly update 🍭"
} else {
return;
}

User.find({
$or: [
{ 'settings.digestEmailFrequency': 'daily' },
{ 'settings.digestEmailFrequency': 'weekly' }
]
})
.then(users => {
users.forEach(async function(user) {
// Check if current time on server is equivalent to 08:00 in the user's timezone
if (moment().utcOffset(user.settings.timezone).isSame(moment("08:00","HH:mm"),"hour")) {
const unreadNotifications = user.notifications.filter(n => n.seen == false);
if (unreadNotifications && unreadNotifications.length != 0){
// send mail with defined transport object
let info = await transporter.sendMail({
from: '"sweet 🍬" <updates@sweet.sh>', // sender address
to: user.email,
subject: email.subject,
template: "update",
context: {
title: 'sweet',
content: [
'Hi <strong>@' + user.username + '</strong>!',
'Here\'s what went down since you last visted sweet:'
],
notifications: unreadNotifications,
action: {
url: 'https://sweet.sh',
text: 'Visit sweet'
},
signoff: '— sweet x'
}
});
console.log("Update email sent to ",user.username,":", info.messageId);
}
}
})
})
}

var sendDailyEmail = schedule.scheduleJob('0 * * * *', function(){ // Every hour
sendUpdateEmail('daily').catch(console.error);
});

var sendWeeklyEmail = schedule.scheduleJob('0 0-23 * * 0', function(){ // Every hour on Sunday
sendUpdateEmail('weekly').catch(console.error);
});

module.exports.sendUpdateEmail = sendUpdateEmail;
@@ -51,13 +51,15 @@ var userSchema = new mongoose.Schema({
websiteParsed: String,
location: String,
settings: {
timezone: { type: String, default: "+00:00" },
profileVisibility: { type: String, default: "invisible" },
newPostPrivacy: { type: String, default: "public" },
imageQuality: { type: String, default: "standard" },
homeTagTimelineSorting: { type: String, default: "fluid" },
userTimelineSorting: { type: String, default: "chronological" },
communityTimelineSorting: { type: String, default: "fluid" },
flashRecentComments: { type: Boolean, default: true },
digestEmailFrequency: { type: String, default: "off" }
},
notifications: [notificationSchema],
communities: [{ type: Schema.Types.ObjectId, ref: 'Community' }],
@@ -337,8 +337,10 @@ module.exports = function (app, passport) {
_id: req.user._id
}, {
$set: {
'settings.timezone': updatedSettings.timezone,
'settings.profileVisibility': updatedSettings.profileVisibility,
'settings.newPostPrivacy': updatedSettings.newPostPrivacy,
'settings.digestEmailFrequency': updatedSettings.digestEmailFrequency,
'settings.imageQuality': updatedSettings.imageQuality,
'settings.homeTagTimelineSorting': updatedSettings.homeTagTimelineSorting,
'settings.userTimelineSorting': updatedSettings.userTimelineSorting,
@@ -663,6 +663,9 @@ module.exports = function (app) {
//construct the query that will retrieve the posts we want. basically just coming up with criteria to pass to Post.find

if (req.params.context == "home") {
console.log("========= HOME DEBUG =========")
console.log(req.user)
console.log(req.user.settings)
//on the home page, we're looking for posts (and boosts) created by users we follow as well as posts in communities that we're in.
var matchPosts = {
'$or': [{
@@ -887,6 +890,9 @@ module.exports = function (app) {
}
//generate some arrays containing usernames that will be put in "boosted by" labels
if (req.isAuthenticated() && (req.params.context != "community")) {
console.log("======== BOOSTED BY LABEL DEBUG ========")
console.log(req.user)
console.log(req.isAuthenticated())
var followedBoosters = [];
var notFollowingBoosters = [];
var youBoosted = false;

Some generated files are not rendered by default. Learn more.

@@ -35,6 +35,8 @@
"mongoose": "^5.4.19",
"morgan": "^1.9.1",
"node-schedule": "^1.3.2",
"nodemailer": "^6.2.1",
"nodemailer-express-handlebars": "^3.0.0",
"passport": "^0.4.0",
"passport-local": "^1.0.0",
"request": "^2.88.0",
@@ -346,6 +346,10 @@ h1, h2, h3, h4, h5, h6 {
font-family: 'Ubuntu', serif;
}

#settingsForm h4 {
color: #ce1717;
}

/* .post-action-button {
width: 60px;
text-align: left;
@@ -132,13 +132,12 @@ app.on('SIGINT', function () {

global.appRoot = path.resolve(__dirname);



// routes ======================================================================
helper = require('./app/utilityFunctionsMostlyText.js');
require('./app/statisticsTracker.js')(app, mongoose);
require('./app/personalAccountActions.js')(app, passport);
require('./app/notifier.js')
var emailer = require('./app/emailer.js')
require('./app/inhabitingCommunities.js')(app, passport);
require('./app/viewingSweet.js')(app);
require('./app/postingToSweet.js')(app);

0 comments on commit d46dcd4

Please sign in to comment.
You can’t perform that action at this time.