Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
feature: create a notification if the upcoming event starts within an…
Browse files Browse the repository at this point in the history
… hour. close #6
  • Loading branch information
sayanee committed May 31, 2015
1 parent 7f869e7 commit 5103c0f
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var ipc = require('ipc');
var notifier = require('node-notifier');
var shell = require('shell');
var CronJob = require('cron').CronJob;
var moment = require('moment-timezone');

function renderFeedback() {
var templateSource = document.getElementById('template-feedback').innerHTML;
Expand All @@ -21,18 +22,22 @@ function renderTemplate(type, data) {
resultsPlaceholder.innerHTML = template(data);
}

function createNotification(events) {
// TODO: if the upcoming event is in an hour, only then notify
// FIX: display separate notifications without replacing each other
events.forEach(function(event) {
function isWithinAnHour(startTime) {
moment(startTime, 'DD MMM YYYY, ddd, hh:mm a').isBefore(moment().add(1, 'hour'))
}

function createNotification(nextEvent) {
// if upcoming event starts within the next hour,
// create a notification
if (isWithinAnHour(nextEvent.formatted_time)) {
notifier.notify({
'title': event.name,
'message': 'by ' + event.group_name + ' on ' + event.formatted_time,
'title': nextEvent.name,
'message': 'by ' + nextEvent.group_name + ' on ' + nextEvent.formatted_time,
'icon': path.join(__dirname, 'logo.png'),
'wait': true,
'open': event.url
'open': nextEvent.url
});
})
}
}

function callAPI(type, willNotify){
Expand All @@ -42,7 +47,7 @@ function callAPI(type, willNotify){
var data = {};
data[type] = body[type].slice(0, 3);
if (type === 'events' && willNotify) {
createNotification(data[type]);
createNotification(data[type][0]);
}
data.website = config.website;
data.feedback = config.feedback;
Expand Down

0 comments on commit 5103c0f

Please sign in to comment.