I am working on making a profanity filter type plugin that disallows certain words from being posted.
I'm hooking on to these hooks and returning an error if profanity exists in the data.
{ "hook": "filter:topic.create", "method": "profanityHook" },
{ "hook": "filter:topic.reply", "method": "profanityHook" },
{ "hook": "filter:post.edit", "method": "profanityHook" },
{ "hook": "filter:post.save", "method": "profanityHook" }
and here's how my hook works:
profanityHook:function(data,next){
if (!data){
return next(null,data);//no data no profanity lol
}
//check content
if (data.content){
if(hasProfanity(data.content)){
return next(new Error('Profanity found'),data);
};
}
//check topic title
if (data.topic && data.topic.title){
if( hasProfanity(data.topic.title) ){
return next(new Error('Profanity found'),data);
}
}
//all ok I guess
return next(null,data);
}
So here's the problem: if there's profanity in the post, but not in the topic title, the topic still gets created with 0 posts in it.
So, how can I stop the topic from being created with 0 posts?