mirror of
https://github.com/vale981/Vulcan
synced 2025-03-09 04:16:37 -04:00

Using jshint and and fixmyjs I went through and removed 220 trivial Javascript errors – mostly missing semicolons, and some properties that weren’t written in dot notation. You can view the diff of jshint’s output here: https://gist.github.com/christianbundy/7b37c51bb6f7c8d739e7/revisions
91 lines
No EOL
3.6 KiB
JavaScript
91 lines
No EOL
3.6 KiB
JavaScript
Notifications = new Meteor.Collection('notifications');
|
|
|
|
Notifications.allow({
|
|
insert: function(userId, doc){
|
|
// new notifications can only be created via a Meteor method
|
|
return false;
|
|
}
|
|
, update: canEditById
|
|
, remove: canEditById
|
|
});
|
|
|
|
getNotificationContents = function(notification, context){
|
|
// the same notifications can be displayed in multiple contexts: on-site in the sidebar, sent by email, etc.
|
|
var event = notification.event,
|
|
p = notification.properties,
|
|
context = typeof context === 'undefined' ? 'sidebar' : context,
|
|
userToNotify = Meteor.users.findOne(notification.userId);
|
|
|
|
|
|
switch(event){
|
|
case 'newReply':
|
|
var n = {
|
|
subject: 'Someone replied to your comment on "'+p.postHeadline+'"',
|
|
text: p.commentAuthorName+' has replied to your comment on "'+p.postHeadline+'": '+getPostCommentUrl(p.postId, p.commentId),
|
|
html: '<p><a href="'+getProfileUrlById(p.commentAuthorId)+'">'+p.commentAuthorName+'</a> has replied to your comment on "<a href="'+getPostCommentUrl(p.postId, p.commentId)+'" class="action-link">'+p.postHeadline+'</a>"</p>'
|
|
};
|
|
if(context == 'email')
|
|
n.html += '<p>'+p.commentExcerpt+'</p><a href="'+getPostCommentUrl(p.postId, p.commentId)+'" class="action-link">Read more</a>';
|
|
break;
|
|
|
|
case 'newComment':
|
|
var n = {
|
|
subject: 'A new comment on your post "'+p.postHeadline+'"',
|
|
text: 'You have a new comment by '+p.commentAuthorName+' on your post "'+p.postHeadline+'": '+getPostCommentUrl(p.postId, p.commentId),
|
|
html: '<p><a href="'+getProfileUrlById(p.commentAuthorId)+'">'+p.commentAuthorName+'</a> left a new comment on your post "<a href="'+getPostCommentUrl(p.postId, p.commentId)+'" class="action-link">'+p.postHeadline+'</a>"</p>'
|
|
};
|
|
if(context == 'email')
|
|
n.html += '<p>'+p.commentExcerpt+'</p><a href="'+getPostCommentUrl(p.postId, p.commentId)+'" class="action-link">Read more</a>';
|
|
break;
|
|
|
|
case 'newPost':
|
|
var n = {
|
|
subject: p.postAuthorName+' has created a new post: "'+p.postHeadline+'"',
|
|
text: p.postAuthorName+' has created a new post: "'+p.postHeadline+'" '+getPostUrl(p.postId),
|
|
html: '<a href="'+getProfileUrlById(p.postAuthorId)+'">'+p.postAuthorName+'</a> has created a new post: "<a href="'+getPostUrl(p.postId)+'" class="action-link">'+p.postHeadline+'</a>".'
|
|
};
|
|
break;
|
|
|
|
case 'accountApproved':
|
|
var n = {
|
|
subject: 'Your account has been approved.',
|
|
text: 'Welcome to '+getSetting('title')+'! Your account has just been approved.',
|
|
html: 'Welcome to '+getSetting('title')+'!<br/> Your account has just been approved. <a href="'+Meteor.absoluteUrl()+'">Start posting.</a>'
|
|
};
|
|
break;
|
|
|
|
case 'newUser':
|
|
var n = {
|
|
subject: 'New user: '+p.username,
|
|
text: 'A new user account has been created: '+p.profileUrl,
|
|
html: 'A new user account has been created: <a href="'+p.profileUrl+'">'+p.username+'</a>'
|
|
};
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
// if context is email, append unsubscribe link to all outgoing notifications
|
|
if(context == 'email'){
|
|
n.to = getEmail(userToNotify);
|
|
n.text = n.text + '\n\n Unsubscribe from all notifications: '+getUnsubscribeLink(userToNotify);
|
|
n.html = n.html + '<br/><br/><a href="'+getUnsubscribeLink(userToNotify)+'">Unsubscribe from all notifications</a>';
|
|
}
|
|
|
|
return n;
|
|
};
|
|
|
|
Meteor.methods({
|
|
markAllNotificationsAsRead: function() {
|
|
Notifications.update(
|
|
{userId: Meteor.userId()},
|
|
{
|
|
$set:{
|
|
read: true
|
|
}
|
|
},
|
|
{multi: true}
|
|
);
|
|
}
|
|
}); |