diff --git a/app/index.html b/app/index.html
index e6745b5..91e50c4 100644
--- a/app/index.html
+++ b/app/index.html
@@ -19,6 +19,7 @@
+
diff --git a/app/js/app.js b/app/js/app.js
index a895e9c..efa4ede 100644
--- a/app/js/app.js
+++ b/app/js/app.js
@@ -2,13 +2,14 @@
var EiskaltApp = angular.module('EiskaltApp', ['ngRoute', 'ngStorage', 'ngSanitize', 'luegg.directives', 'ui.bootstrap',
'angularBootstrapNavTree', 'UpdateCheck', 'EiskaltRPC', 'EiskaltFilters',
- 'EiskaltDirectives']);
+ 'EiskaltDirectives', 'DesktopNotification']);
EiskaltApp.value('settings', {
version: '0.5.2',
localStorageVersion: 2,
updateUrl: 'https://api.github.com/repos/kraiz/icecult/releases',
chatMessagesKept: 250,
+ notificationTimeout: 5000,
refresh: {
hashAndRatio: 5000,
chat: 3000,
diff --git a/app/js/controllers/hubs.js b/app/js/controllers/hubs.js
index a920f91..f13f708 100644
--- a/app/js/controllers/hubs.js
+++ b/app/js/controllers/hubs.js
@@ -19,7 +19,7 @@ EiskaltApp.controller('HubsCtrl', function ($scope, EiskaltRPC) {
};
});
-EiskaltApp.controller('HubCtrl', function ($scope, $interval, $localStorage, settings, EiskaltRPC) {
+EiskaltApp.controller('HubCtrl', function ($scope, $interval, $localStorage, settings, EiskaltRPC, DesktopNotification) {
EiskaltRPC.GetHubUserList($scope.hub.huburl).success(function (users) {
$scope.users = [];
angular.forEach(users, function (user) {
@@ -40,7 +40,10 @@ EiskaltApp.controller('HubCtrl', function ($scope, $interval, $localStorage, set
}
$scope.refreshChat = function () {
EiskaltRPC.GetChatPub($scope.hub.huburl).success(function (messages) {
- Array.prototype.push.apply($scope.$storage.chatlog[$scope.hub.huburl], messages);
+ if (messages.length > 0) {
+ DesktopNotification.notifyChat($scope.hub, messages);
+ Array.prototype.push.apply($scope.$storage.chatlog[$scope.hub.huburl], messages);
+ }
});
};
$scope.refreshChat();
diff --git a/app/js/services/notify.js b/app/js/services/notify.js
new file mode 100644
index 0000000..67ad2f5
--- /dev/null
+++ b/app/js/services/notify.js
@@ -0,0 +1,43 @@
+'use strict';
+
+angular.module('DesktopNotification', []).factory('DesktopNotification', function ($window, settings) {
+
+ var notify = function (title, text) {
+ // no support
+ if (!("Notification" in window)) return;
+ // request permission if not granted nor denied
+ if (Notification.permission !== "granted" && Notification.permission !== 'denied') {
+ Notification.requestPermission(function (permission) {
+ notify(title, text);
+ });
+ return;
+ }
+ // if granted, notify!
+ if (Notification.permission === "granted") {
+ var notification = new Notification(title, {body: text});
+ notification.onclick = function() {
+ $window.focus();
+ };
+ notification.onshow = function() {
+ $window.setTimeout(function() {
+ notification.close()
+ }, settings.notificationTimeout);
+ };
+ }
+ };
+
+ var notifyChat = function(hub, messages) {
+ if (document.hidden) {
+ notify(
+ hub.hubname,
+ messages.map(function(msg) {
+ return msg.nick + ': ' + msg.text
+ }).join('\n')
+ );
+ }
+ };
+
+ return {
+ notifyChat: notifyChat
+ }
+});