2020-03-03 16:33:13 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const userDigest = require('../../user/digest');
|
|
|
|
|
const userEmail = require('../../user/email');
|
|
|
|
|
const notifications = require('../../notifications');
|
|
|
|
|
const emailer = require('../../emailer');
|
2020-12-05 14:25:14 -07:00
|
|
|
const utils = require('../../utils');
|
2020-03-03 16:33:13 -05:00
|
|
|
|
|
|
|
|
const Email = module.exports;
|
|
|
|
|
|
2020-12-05 14:25:14 -07:00
|
|
|
Email.test = async function (socket, data) {
|
2020-03-03 16:33:13 -05:00
|
|
|
const payload = {
|
2021-03-02 12:30:37 -05:00
|
|
|
...(data.payload || {}),
|
2020-03-03 16:33:13 -05:00
|
|
|
subject: '[[email:test-email.subject]]',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
switch (data.template) {
|
2020-06-03 11:25:25 -04:00
|
|
|
case 'digest':
|
2020-12-05 14:25:14 -07:00
|
|
|
await userDigest.execute({
|
2020-06-03 11:25:25 -04:00
|
|
|
interval: 'alltime',
|
|
|
|
|
subscribers: [socket.uid],
|
2020-12-05 14:25:14 -07:00
|
|
|
});
|
2020-06-03 11:25:25 -04:00
|
|
|
break;
|
2020-03-03 16:33:13 -05:00
|
|
|
|
2020-06-03 11:25:25 -04:00
|
|
|
case 'banned':
|
|
|
|
|
Object.assign(payload, {
|
|
|
|
|
username: 'test-user',
|
|
|
|
|
until: utils.toISOString(Date.now()),
|
|
|
|
|
reason: 'Test Reason',
|
|
|
|
|
});
|
2020-12-05 14:25:14 -07:00
|
|
|
await emailer.send(data.template, socket.uid, payload);
|
2020-06-03 11:25:25 -04:00
|
|
|
break;
|
2020-03-03 16:33:13 -05:00
|
|
|
|
2020-06-03 11:25:25 -04:00
|
|
|
case 'welcome':
|
2020-12-05 14:25:14 -07:00
|
|
|
await userEmail.sendValidationEmail(socket.uid, {
|
2020-06-03 11:25:25 -04:00
|
|
|
force: 1,
|
2020-12-05 14:25:14 -07:00
|
|
|
});
|
2020-06-03 11:25:25 -04:00
|
|
|
break;
|
2020-03-03 16:33:13 -05:00
|
|
|
|
2020-12-05 14:25:14 -07:00
|
|
|
case 'notification': {
|
|
|
|
|
const notification = await notifications.create({
|
|
|
|
|
type: 'test',
|
|
|
|
|
bodyShort: '[[email:notif.test.short]]',
|
|
|
|
|
bodyLong: '[[email:notif.test.long]]',
|
2021-02-03 23:59:08 -07:00
|
|
|
nid: `uid:${socket.uid}:test`,
|
2020-12-05 14:25:14 -07:00
|
|
|
path: '/',
|
|
|
|
|
from: socket.uid,
|
|
|
|
|
});
|
|
|
|
|
await emailer.send('notification', socket.uid, {
|
|
|
|
|
path: notification.path,
|
|
|
|
|
subject: utils.stripHTMLTags(notification.subject || '[[notifications:new_notification]]'),
|
|
|
|
|
intro: utils.stripHTMLTags(notification.bodyShort),
|
|
|
|
|
body: notification.bodyLong || '',
|
|
|
|
|
notification,
|
|
|
|
|
showUnsubscribe: true,
|
|
|
|
|
});
|
|
|
|
|
} break;
|
2020-03-03 16:33:13 -05:00
|
|
|
|
2020-06-03 11:25:25 -04:00
|
|
|
default:
|
2020-12-05 14:25:14 -07:00
|
|
|
await emailer.send(data.template, socket.uid, payload);
|
2020-06-03 11:25:25 -04:00
|
|
|
break;
|
2020-03-03 16:33:13 -05:00
|
|
|
}
|
|
|
|
|
};
|