Merge pull request #31 from brettcs/email-copyediting

update: Improve email text.
This commit is contained in:
John McLear 2017-08-31 09:27:12 +01:00 committed by GitHub
commit 25a7c37395

View file

@ -4,7 +4,8 @@
async = require('../../src/node_modules/async'), async = require('../../src/node_modules/async'),
check = require('validator').check, check = require('validator').check,
email = require('emailjs'), email = require('emailjs'),
settings = require('../../src/node/utils/Settings'); settings = require('../../src/node/utils/Settings'),
util = require('util');
// Settings -- EDIT THESE IN settings.json not here.. // Settings -- EDIT THESE IN settings.json not here..
var pluginSettings = settings.ep_email_notifications; var pluginSettings = settings.ep_email_notifications;
@ -22,6 +23,8 @@ var timers = {};
// Connect to the email server -- This might not be the ideal place to connect but it stops us having lots of connections // Connect to the email server -- This might not be the ideal place to connect but it stops us having lots of connections
var server = email.server.connect(emailServer); var server = email.server.connect(emailServer);
var emailFooter = "\nYou can unsubscribe from these emails in the pad's Settings window.\n";
exports.padUpdate = function (hook_name, _pad) { exports.padUpdate = function (hook_name, _pad) {
if (areParamsOk == false) return false; if (areParamsOk == false) return false;
@ -41,6 +44,11 @@ exports.padUpdate = function (hook_name, _pad) {
} }
}; };
padUrl = function(padId, fmt) {
fmt = fmt || "%s";
return util.format(fmt, urlToPads + padId);
}
exports.notifyBegin = function(padId){ exports.notifyBegin = function(padId){
console.warn("Getting pad email stuff for "+padId); console.warn("Getting pad email stuff for "+padId);
db.get("emailSubscription:" + padId, function(err, recipients){ // get everyone we need to email db.get("emailSubscription:" + padId, function(err, recipients){ // get everyone we need to email
@ -54,7 +62,7 @@ exports.notifyBegin = function(padId){
if(!userIsOnPad && onStart){ if(!userIsOnPad && onStart){
console.debug("Emailing "+recipient +" about a new begin update"); console.debug("Emailing "+recipient +" about a new begin update");
server.send({ server.send({
text: "Your pad at "+urlToPads+padId +" is being edited, we're just emailing you let you know :)", text: "This pad is now being edited:\n" + padUrl(padId, " <%s>\n") + emailFooter,
from: fromName+ "<"+fromEmail+">", from: fromName+ "<"+fromEmail+">",
to: recipient, to: recipient,
subject: "Someone started editing "+padId subject: "Someone started editing "+padId
@ -75,8 +83,7 @@ exports.notifyBegin = function(padId){
} }
exports.notifyEnd = function(padId){ exports.notifyEnd = function(padId){
// get the modified contents... // TODO: get the modified contents to include in the email
var changesToPad = "Functionality does not exist";
db.get("emailSubscription:" + padId, function(err, recipients){ // get everyone we need to email db.get("emailSubscription:" + padId, function(err, recipients){ // get everyone we need to email
if(recipients){ if(recipients){
@ -90,7 +97,7 @@ exports.notifyEnd = function(padId){
if(!userIsOnPad && onEnd){ if(!userIsOnPad && onEnd){
console.debug("Emailing "+recipient +" about a pad finished being updated"); console.debug("Emailing "+recipient +" about a pad finished being updated");
server.send({ server.send({
text: "Your pad at "+urlToPads+padId +" has finished being edited, we're just emailing you let you know :) \n\n The changes look like this: \n" + changesToPad, text: "This pad is done being edited:\n" + padUrl(padId, " <%s>\n") + emailFooter,
from: fromName+ "<"+fromEmail+">", from: fromName+ "<"+fromEmail+">",
to: recipient, to: recipient,
subject: "Someone finished editing "+padId subject: "Someone finished editing "+padId