All files divert.js

100% Statements 9/9
100% Branches 3/3
100% Functions 3/3
100% Lines 8/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 384x                 5x                   4x 3x 2x   1x                     4x 2x    
const diverted = {};
 
/**
 * Returns the indexed key for the user
 * @method getDivertedKey
 * @param  {String}  platform          the platform the user is on
 * @param  {String}  platformId        the users id on the given platform
 * @return {String}                    the users diversion key
 */
const getDivertedKey = (platform, platformId) => `${platform}-${platformId}`;
 
/**
 * Diverts a bot from sending messages if the user
 * specified is tag to not have messages sent or processed
 * @method divert
 * @param  {String}  platform          the platform the user is on
 * @param  {String}  platformId        the users id on the given platform
 * @param  {Boolean} [divertUser=true] should the user diverted
 */
export const divert = (platform, platformId, divertUser = true) => {
  if (divertUser) {
    diverted[getDivertedKey(platform, platformId)] = divertUser;
  } else {
    delete diverted[getDivertedKey(platform, platformId)];
  }
};
 
/**
 * Returns whether or not the user is diverted
 * @method isDiverted
 * @param  {String}  platform          the platform the user is on
 * @param  {String}  platformId        the users id on the given platform
 * @return {Boolean}                   is the user diverted
 */
export const isDiverted = (platform, platformId) => (
  !!diverted[getDivertedKey(platform, platformId)]
);