<commit_before>"use strict";

var debug = require('debug')('OSMBC:notification:messageFilter');


function UserConfigFilter(user,receiver){
  debug('UserConfigFilter');
  this.user = user;
  this.receiver = receiver;
}

UserConfigFilter.prototype.updateArticle = function ucfUpdateArticle(user,article,change,cb) {
  debug('UserConfigFilter.prototype.updateArticle');
  var sendMail = false;

  // check Collection
  if (this.user.mailNewCollection == "true") {
    if (change.collection && change.collection != article.collection) {
      sendMail = true;
      debug("Mail sent because new Collection");
    }
  }
  if (this.user.mailAllComment == "true") {
    if (change.comment && change.comment != article.comment) {
      sendMail = true;
      debug("Mail send because changed comment");
    }
  }
  var userList = [];
  if (this.user.mailComment) userList = this.user.mailComment;
  for (var i=0;i<userList.length;i++) {
    if (change.comment && change.comment.search(new RegExp("@"+userList[i],"i"))>=0) {
      sendMail = true; 
      debug("Mail send because comment for @"+userList[i]);
    }
  }
  if (!sendMail) return cb();
  this.receiver.updateArticle(user,article,change,cb);
};

UserConfigFilter.prototype.addComment = function ucfAddComment(user,article,comment,cb) {
  debug('UserConfigFilter.prototype.addComment');
  var sendMail = false;

  // check Collection
  if (this.user.mailAllComment == "true") {
    sendMail = true;
  }
  var userList = [];
  if (this.user.mailComment) userList = this.user.mailComment;
  for (var i=0;i<userList.length;i++) {

    if (comment.search(new RegExp("@"+userList[i]+"\\b","i"))>=0) {
      sendMail = true;
      debug("Mail send because comment for @"+userList[i]);
    }
  }
  if (!sendMail) return cb();
  this.receiver.addComment(user,article,comment,cb);
};

UserConfigFilter.prototype.editComment = function ucfEditComment(user,article,index,comment,cb) {
  debug('UserConfigFilter.prototype.addComment');
  var sendMail = false;

  // check Collection
  if (this.user.mailAllComment == "true") {
    sendMail = true;
  }
  var userList = [];
  if (this.user.mailComment) userList = this.user.mailComment;
  for (var i=0;i<userList.length;i++) {
    if (comment.search(new RegExp("@"+userList[i]+"\\b","i"))>=0) {
      sendMail = true;
      debug("Mail send because comment for @"+userList[i]);
    }
  }
  if (!sendMail) return cb();
  this.receiver.editComment(user,article,index,comment,cb);
};<commit_msg>Inform user with mail about comment changes, if user is mentioned in "some" comment. Main change for #549<commit_after>"use strict";

var debug = require('debug')('OSMBC:notification:messageFilter');


function UserConfigFilter(user,receiver){
  debug('UserConfigFilter');
  this.user = user;
  this.receiver = receiver;
}

UserConfigFilter.prototype.updateArticle = function ucfUpdateArticle(user,article,change,cb) {
  debug('UserConfigFilter.prototype.updateArticle');
  var sendMail = false;

  // check Collection
  if (this.user.mailNewCollection == "true") {
    if (change.collection && change.collection != article.collection) {
      sendMail = true;
      debug("Mail sent because new Collection");
    }
  }
  if (this.user.mailAllComment == "true") {
    if (change.comment && change.comment != article.comment) {
      sendMail = true;
      debug("Mail send because changed comment");
    }
  }
  var userList = [];
  if (this.user.mailComment) userList = this.user.mailComment;
  for (var i=0;i<userList.length;i++) {
    if (change.comment && change.comment.search(new RegExp("@"+userList[i],"i"))>=0) {
      sendMail = true; 
      debug("Mail send because comment for @"+userList[i]);
    }
  }
  if (!sendMail) return cb();
  this.receiver.updateArticle(user,article,change,cb);
};

UserConfigFilter.prototype.addComment = function ucfAddComment(user,article,comment,cb) {
  debug('UserConfigFilter.prototype.addComment');
  var sendMail = false;

  // check Collection
  if (this.user.mailAllComment == "true") {
    sendMail = true;
  }
  let checkComment = comment;
  var userList = [];
  if (this.user.mailComment) userList = this.user.mailComment;

  // if mailCommentGeneral search for mention in all comments of an article
  // and if user has written one comment in the list, so he has to be informed to.

  if (this.user.mailCommentGeneral) {
    checkComment = null;
    article.commentList.forEach(function doPush(item){
      if (checkComment) checkComment = checkComment + "###"; else checkComment = "";
      checkComment = checkComment + item.text;

      if (item.user == user.OSMUser) sendMail = true;
    });
  }
  for (var i=0;i<userList.length;i++) {

    if (checkComment.search(new RegExp("@"+userList[i]+"\\b","i"))>=0) {
      sendMail = true;
      debug("Mail send because comment for @"+userList[i]);
    }
  }
  if (!sendMail) return cb();
  this.receiver.addComment(user,article,comment,cb);
};

UserConfigFilter.prototype.editComment = function ucfEditComment(user,article,index,comment,cb) {
  debug('UserConfigFilter.prototype.addComment');
  var sendMail = false;

  // check Collection
  if (this.user.mailAllComment == "true") {
    sendMail = true;
  }
  let checkComment = comment;
  var userList = [];
  if (this.user.mailComment) userList = this.user.mailComment;

  // if mailCommentGeneral search for mention in all comments of an article
  // and if user has written one comment in the list, so he has to be informed to.

  if (this.user.mailCommentGeneral) {
    checkComment = null;
    article.commentList.forEach(function doPush(item){
      if (checkComment) checkComment = checkComment + "###"; else checkComment = "";
      checkComment = checkComment + item.text;

      if (item.user == user.OSMUser) sendMail = true;
    });
  }
  if (this.user.mailComment) userList = this.user.mailComment;
  for (var i=0;i<userList.length;i++) {
    if (comment.search(new RegExp("@"+userList[i]+"\\b","i"))>=0) {
      sendMail = true;
      debug("Mail send because comment for @"+userList[i]);
    }
  }
  if (!sendMail) return cb();
  this.receiver.editComment(user,article,index,comment,cb);
};
{'fraction_non_alphanumeric': 0.1490228013029316, 'fraction_numerical': 0.0024429967426710096, 'mean_word_length': 3.9845779220779223, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5809595', 'n_tokens_mistral': 1954, 'n_tokens_neox': 1925, 'n_words': 429}