mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-17 11:11:04 +01:00
refactor: reorganized socket.io admin modules
This commit is contained in:
69
src/socket.io/admin/email.js
Normal file
69
src/socket.io/admin/email.js
Normal file
@@ -0,0 +1,69 @@
|
||||
'use strict';
|
||||
|
||||
const async = require('async');
|
||||
const userDigest = require('../../user/digest');
|
||||
const userEmail = require('../../user/email');
|
||||
const notifications = require('../../notifications');
|
||||
const emailer = require('../../emailer');
|
||||
const utils = require('../../../public/src/utils');
|
||||
|
||||
const Email = module.exports;
|
||||
|
||||
Email.test = function (socket, data, callback) {
|
||||
const payload = {
|
||||
subject: '[[email:test-email.subject]]',
|
||||
};
|
||||
|
||||
switch (data.template) {
|
||||
case 'digest':
|
||||
userDigest.execute({
|
||||
interval: 'alltime',
|
||||
subscribers: [socket.uid],
|
||||
}, callback);
|
||||
break;
|
||||
|
||||
case 'banned':
|
||||
Object.assign(payload, {
|
||||
username: 'test-user',
|
||||
until: utils.toISOString(Date.now()),
|
||||
reason: 'Test Reason',
|
||||
});
|
||||
emailer.send(data.template, socket.uid, payload, callback);
|
||||
break;
|
||||
|
||||
case 'welcome':
|
||||
userEmail.sendValidationEmail(socket.uid, {
|
||||
force: 1,
|
||||
}, callback);
|
||||
break;
|
||||
|
||||
case 'notification':
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
notifications.create({
|
||||
type: 'test',
|
||||
bodyShort: '[[email:notif.test.short]]',
|
||||
bodyLong: '[[email:notif.test.long]]',
|
||||
nid: 'uid:' + socket.uid + ':test',
|
||||
path: '/',
|
||||
from: socket.uid,
|
||||
}, next);
|
||||
},
|
||||
function (notifObj, next) {
|
||||
emailer.send('notification', socket.uid, {
|
||||
path: notifObj.path,
|
||||
subject: utils.stripHTMLTags(notifObj.subject || '[[notifications:new_notification]]'),
|
||||
intro: utils.stripHTMLTags(notifObj.bodyShort),
|
||||
body: notifObj.bodyLong || '',
|
||||
notification: notifObj,
|
||||
showUnsubscribe: true,
|
||||
}, next);
|
||||
},
|
||||
], callback);
|
||||
break;
|
||||
|
||||
default:
|
||||
emailer.send(data.template, socket.uid, payload, callback);
|
||||
break;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user