Brad, very simple code at its best and what I use on my site. Currently no unsubscribe at the moment, just haven’t gotten around too it.
comment.cfc (Entity)
property name=“isSubscribed” notnull=“true” ormtype=“boolean” default=“false” dbdefault=“0” index=“idx_contentComment,idx_subscribed”;
Custom Interceptor
//------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------
public void function cbui_onCommentPost(event, interceptData) eventPattern="^contentbox-ui" {
if(interceptData.comment.getCommentId() != “”) {
var comment = commentService.get(interceptData.comment.getCommentId());
comment.setIsSubscribed(event.getValue(‘blogSubscribe’, false));
commentService.save( comment );
if(!interceptData.moderationResults.moderated) {
sendMailNotifications(interceptData.comment.getCommentId());
}
}
}
//------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------
private void function sendMailNotifications(required string commentId) {
var comments = commentService.getAll(listToArray(arguments.commentID), “createdDate asc”);
var settings = settingService.getAllSettings(asStruct=true);
for(var comment in comments) {
// Todo: People can only subscribe with blog posts at the moment, there might be a switch added later.
if(comment.getrelatedContent().getContentType() == ‘entry’) {
var results = {};
var criteria = commentService.newCriteria();
criteria.eq(“isApproved”, javaCast(“boolean”, true));
criteria.eq(“isSubscribed”, javaCast(“boolean”, true));
criteria.eq(“relatedContent.contentID”, javaCast(“int”, comment.getrelatedContent().getContentId() ));
criteria.ne( “authorEmail”, comment.getAuthorEmail() );
criteria.withProjections(distinct = “authorEmail:email”);
results = criteria.list();
var bodyTokens = comment.getMemento();
bodyTokens[“commentURL”] = CBHelper.linkComment( comment );
bodyTokens[“contentURL”] = CBHelper.linkContent( comment.getRelatedContent() );
bodyTokens[“contentTitle”] = comment.getParentTitle();
for(var email in results) {
log.info(“Sending email for moderated Post Id: #comment.getCommentId()# - sending email out to #email#”);
var mail = mailservice.newMail(to = email,
from = settings.cb_site_outgoingEmail,
subject = “New comment made for post: #bodyTokens.contentTitle#”,
type = “html”,
bodyTokens = bodyTokens,
server = settings.cb_site_mail_server,
username = settings.cb_site_mail_username,
password = settings.cb_site_mail_password,
port = settings.cb_site_mail_smtp,
useTLS = settings.cb_site_mail_tls,
useSSL = settings.cb_site_mail_ssl);
mail.setBody( renderer.get().renderExternalView(view="/contentbox/email_templates/comment_notify") );
mailService.send( mail );
}
}
}
}
Custom CommentForm Plugin - That extends the original but changes the renderIt() to included text for moderation and the following.
#html.checkBox( name = "blogSubscribe", checked = event.getValue("blogSubscribe", false))#
#html.label( field = "test", content = "Subcribe to be notified of comments posted.", class="inline")#