Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactoring to fix a couple codacy issues #746

Merged
merged 1 commit into from
Jul 26, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 35 additions & 23 deletions lib/pushnotify.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ function init(env, ctx) {
// declare local constants for time differences
var TIME_2_MINS_S = 120
, TIME_15_MINS_S = 15 * 60
, TIME_15_MINS_MS = TIME_15_MINS_S * 1000
, TIME_30_MINS_MS = 30 * 60 * 1000
;

Expand All @@ -24,8 +23,8 @@ function init(env, ctx) {

pushnotify.emitNotification = function emitNotification (notify) {
if (notify.clear) {
if (ctx.pushover) { cancelPushoverNotifications(); }
if (ctx.maker) { sendMakerAllClear(notify); }
cancelPushoverNotifications();
sendMakerAllClear(notify);
return;
}

Expand All @@ -48,8 +47,8 @@ function init(env, ctx) {

recentlySent.set(key, notify, 30);

if (ctx.pushover) { sendPushoverNotifications(notify); }
if (ctx.maker) { sendMakerEvent(notify); }
sendPushoverNotifications(notify);
sendMakerEvent(notify);

};

Expand All @@ -65,21 +64,28 @@ function init(env, ctx) {
};

function cancelPushoverNotifications ( ) {
var receiptKeys = receipts.keys();

_.forEach(receiptKeys, function eachKey (receipt) {
ctx.pushover.cancelWithReceipt(receipt, function cancelCallback (err) {
if (err) {
console.error('error canceling receipt, err: ', err);
} else {
console.info('got a receipt cancel response');
}
if (ctx.pushover) {
var receiptKeys = receipts.keys();

_.forEach(receiptKeys, function eachKey(receipt) {
ctx.pushover.cancelWithReceipt(receipt, function cancelCallback(err) {
if (err) {
console.error('error canceling receipt, err: ', err);
} else {
console.info('got a receipt cancel response');
}
});
receipts.del(receipt);
});
receipts.del(receipt);
});
}
}

function sendPushoverNotifications (notify) {

if (!ctx.pushover) {
return;
}

var msg = {
expire: TIME_15_MINS_S
, title: notify.title
Expand Down Expand Up @@ -118,16 +124,22 @@ function init(env, ctx) {
}

function sendMakerAllClear (notify) {
ctx.maker.sendAllClear(notify, function makerCallback (err, result) {
if (err) {
console.error('unable to send maker allclear', err);
} else if (result && result.sent) {
console.info('sent maker allclear');
}
});
if (ctx.maker) {
ctx.maker.sendAllClear(notify, function makerCallback (err, result) {
if (err) {
console.error('unable to send maker allclear', err);
} else if (result && result.sent) {
console.info('sent maker allclear');
}
});
}
}

function sendMakerEvent (notify) {
if (!ctx.maker) {
return;
}

var event = {
name: notify.eventName || notify.plugin.name
, level: levels.toLowerCase(notify.level)
Expand Down