2016-04-01 12:38:50 +09:00
|
|
|
// import Email from 'meteor/nova:email';
|
|
|
|
|
|
|
|
Telescope.notifications = {};
|
|
|
|
|
2016-04-08 10:09:19 +09:00
|
|
|
Telescope.createNotification = (userIds, notificationName, data) => {
|
2016-04-01 12:38:50 +09:00
|
|
|
|
2016-04-08 10:09:19 +09:00
|
|
|
// if userIds is not an array, wrap it in one
|
|
|
|
if (!Array.isArray(userIds)) userIds = [userIds];
|
2016-04-01 12:38:50 +09:00
|
|
|
|
2016-04-08 10:09:19 +09:00
|
|
|
userIds.forEach(userId => {
|
|
|
|
|
|
|
|
const user = Users.findOne(userId);
|
|
|
|
const notification = Telescope.notifications[notificationName];
|
|
|
|
const properties = notification.properties(data);
|
|
|
|
const subject = notification.subject(properties);
|
|
|
|
const html = Telescope.email.buildTemplate(Telescope.email.getTemplate(notification.emailTemplate)(properties));
|
|
|
|
|
|
|
|
Telescope.email.send(Users.getEmail(user), subject, html);
|
|
|
|
});
|
2016-04-01 12:38:50 +09:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-04-04 14:39:08 +09:00
|
|
|
if (typeof Telescope.settings.collection !== "undefined") {
|
|
|
|
Telescope.settings.collection.addField({
|
2016-04-01 12:38:50 +09:00
|
|
|
fieldName: 'emailNotifications',
|
|
|
|
fieldSchema: {
|
|
|
|
type: Boolean,
|
|
|
|
optional: true,
|
|
|
|
defaultValue: true,
|
|
|
|
autoform: {
|
|
|
|
group: 'notifications',
|
|
|
|
instructions: 'Enable email notifications for new posts and new comments (requires restart).'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|