Skip to content

Commit

Permalink
fix a fucking bug
Browse files Browse the repository at this point in the history
  • Loading branch information
DesertsPan committed Sep 18, 2018
1 parent d800317 commit d6baa3b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
13 changes: 10 additions & 3 deletions cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const request = require('request');

function sendNotification(currentComment) {
// 发送博主通知邮件
mail.notice(currentComment);
if (currentComment.get('mail') !== process.env.BLOGGER_EMAIL) {
mail.notice(currentComment);
}
// AT评论通知
// 获取评论内容
var comm = currentComment.get('comment');
Expand All @@ -21,15 +23,20 @@ function sendNotification(currentComment) {
currentComment.set('rid', rid);
let query = new AV.Query('Comment');
query.get(rid).then(function (parentComment) {
mail.send(currentComment, parentComment);
if (parentComment.get('mail') && parentComment.get('mail') !== process.env.BLOGGER_EMAIL) {
mail.send(currentComment, parentComment);
} else {
console.log('被@者匿名,不会发送通知');
}

}, function (error) {
console.warn('获取@对象失败!');
});
}

AV.Cloud.afterSave('Comment', function (request) {
let currentComment = request.object;
sendNotification(currentComment);
return sendNotification(currentComment);
});

AV.Cloud.define('resend-mails', function(request) {
Expand Down
7 changes: 5 additions & 2 deletions utilities/send-mail.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ exports.notice = (comment) => {
if (error) {
return console.log(error);
}
console.log('博主通知邮件成功发送: %s', info.response);
currentComment.set('isNotified', true);
currentComment.save();
});
}

Expand All @@ -42,7 +45,7 @@ exports.send = (currentComment, parentComment)=> {
let NICK = currentComment.get('nick');
let COMMENT = currentComment.get('comment');
let PARENT_COMMENT = parentComment.get('comment');
let POST_URL = process.env.SITE_URL + currentComment.get('url') + '#' + comment.get('objectId');
let POST_URL = process.env.SITE_URL + currentComment.get('url') + '#' + currentComment.get('objectId');
let SITE_URL = process.env.SITE_URL;

let _subject = process.env.MAIL_SUBJECT || '${PARENT_NICK},您在『${SITE_NAME}』上的评论收到了回复';
Expand All @@ -61,7 +64,7 @@ exports.send = (currentComment, parentComment)=> {
if (error) {
return console.log(error);
}
console.log('邮件 %s 成功发送: %s', info.messageId, info.response);
console.log('AT通知邮件成功发送: %s', info.response);
currentComment.set('isNotified', true);
currentComment.save();
});
Expand Down

0 comments on commit d6baa3b

Please sign in to comment.