diff options
author | Kegan Dougal <kegan@matrix.org> | 2014-10-31 11:54:04 +0000 |
---|---|---|
committer | Kegan Dougal <kegan@matrix.org> | 2014-10-31 11:54:04 +0000 |
commit | 20cf0b7aeb42c49bce199206130b5498b0fc293c (patch) | |
tree | f5fc222e4aaff780e570bbd2ac38d60246f769d0 /webclient/components | |
parent | Add notification-service.js to handle binging/notifications. Shift logic to t... (diff) | |
download | synapse-20cf0b7aeb42c49bce199206130b5498b0fc293c.tar.xz |
Factor out notification logic.
Diffstat (limited to '')
-rw-r--r-- | webclient/components/matrix/event-handler-service.js | 25 | ||||
-rw-r--r-- | webclient/components/matrix/notification-service.js | 22 |
2 files changed, 29 insertions, 18 deletions
diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js index bcf805fc73..e63584510b 100644 --- a/webclient/components/matrix/event-handler-service.js +++ b/webclient/components/matrix/event-handler-service.js @@ -212,22 +212,15 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService roomTitle = event.room_id; } - var notification = new window.Notification( - displayname + - " (" + roomTitle + ")", - { - "body": message, - "icon": member ? member.avatar_url : undefined - }); - - notification.onclick = function() { - console.log("notification.onclick() room=" + event.room_id); - $rootScope.goToPage('room/' + (event.room_id)); - }; - - $timeout(function() { - notification.close(); - }, 5 * 1000); + notificationService.showNotification( + displayname + " (" + roomTitle + ")", + message, + member ? member.avatar_url : undefined, + function() { + console.log("notification.onclick() room=" + event.room_id); + $rootScope.goToPage('room/' + event.room_id); + } + ); } } } diff --git a/webclient/components/matrix/notification-service.js b/webclient/components/matrix/notification-service.js index 7821248846..9a911413c3 100644 --- a/webclient/components/matrix/notification-service.js +++ b/webclient/components/matrix/notification-service.js @@ -21,7 +21,7 @@ This service manages notifications: enabling, creating and showing them. This also contains 'bing word' logic. */ angular.module('notificationService', []) -.factory('notificationService', function($rootScope) { +.factory('notificationService', ['$timeout', function($timeout) { var getLocalPartFromUserId = function(user_id) { if (!user_id) { @@ -80,7 +80,25 @@ angular.module('notificationService', []) } } return false; + }, + + showNotification: function(title, body, icon, onclick) { + var notification = new window.Notification( + title, + { + "body": body, + "icon": icon + } + ); + + if (onclick) { + notification.onclick = onclick; + } + + $timeout(function() { + notification.close(); + }, 5 * 1000); } }; -}); +}]); |