<commit_before>const INVALID = 'INVALID';

function trigger(user, api, message) {
  // get threadID
  var threadID = message.threadID;
  getThreadUsers(threadID, api, function(info) {
    // get username info
    var nicks = info.nicknames;
    var users = info.participantIDs;
    var threadName = info.name;

    // check nicknames
    for (var id in nicks) {
      if (nicks[id] == user) {
        ping(message.senderID, id, threadName, api);
        return;
      }
    }

    // check real names
    getIDFromName(user, users, threadID, api, function(userID) {
      if (userID != INVALID) {
        ping(message.senderID, userID, threadName, api);
        return;
      }
    });
  });
}

function getThreadUsers(threadID, api, callback) {
  api.getThreadInfo(threadID, function(err, info) {
    callback(info);
  });
}

function getIDFromName(user, users, threadID, api, callback) {
  if (!user) return callback(INVALID);
  api.getUserID(user, function(err, data) {
    if (err) return console.log(err);
    for (var id in data) {
      for (var userID in users) {
        if (data[id].userID == users[userID]) return callback(users[userID]);
      }
    }
    return callback(INVALID);
  });
}

function ping(pingerID, pingeeID, threadName, api) {
  // get pinger name
  api.getUserInfo(pingerID, function(err, obj) {
    if (err) return console.error(err);
    msg = {
      body: obj[pingerID].firstName + ' has pinged you in ' + threadName + '!'
    };
    // send notification
    api.sendMessage(msg, pingeeID);
  });
}

module.exports = {
  trigger: trigger
}<commit_msg>Only show threadname in ping alert if convo has a name<commit_after>const INVALID = 'INVALID';

function trigger(user, api, message) {
  // get threadID
  var threadID = message.threadID;
  getThreadUsers(threadID, api, function(info) {
    // get username info
    var nicks = info.nicknames;
    var users = info.participantIDs;
    var threadName = info.name;

    // check nicknames
    for (var id in nicks) {
      if (nicks[id] == user) {
        ping(message.senderID, id, threadName, api);
        return;
      }
    }

    // check real names
    getIDFromName(user, users, threadID, api, function(userID) {
      if (userID != INVALID) {
        ping(message.senderID, userID, threadName, api);
        return;
      }
    });
  });
}

function getThreadUsers(threadID, api, callback) {
  api.getThreadInfo(threadID, function(err, info) {
    callback(info);
  });
}

function getIDFromName(user, users, threadID, api, callback) {
  if (!user) return callback(INVALID);
  api.getUserID(user, function(err, data) {
    if (err) return console.log(err);
    for (var id in data) {
      for (var userID in users) {
        if (data[id].userID == users[userID]) return callback(users[userID]);
      }
    }
    return callback(INVALID);
  });
}

function ping(pingerID, pingeeID, threadName, api) {
  // get pinger name
  api.getUserInfo(pingerID, function(err, obj) {
    if (err) return console.error(err);
    var msg;
    if (threadName && threadName != '') {
      msg = {
        body: obj[pingerID].firstName + ' has pinged you in ' + threadName + '!'
      };
    } else {
      msg = {
        body: obj[pingerID].firstName + ' has pinged you!'
      };
    }
    // send notification
    api.sendMessage(msg, pingeeID);
  });
}

module.exports = {
  trigger: trigger
}
{'fraction_non_alphanumeric': 0.13430180847909873, 'fraction_numerical': 0.0, 'mean_word_length': 2.7995495495495497, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6109615', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1107, 'n_words': 282}