diff options
author | Kegan Dougal <kegan@matrix.org> | 2014-09-16 14:32:50 +0100 |
---|---|---|
committer | Kegan Dougal <kegan@matrix.org> | 2014-09-16 15:35:23 +0100 |
commit | 660364d6a7a4ad69bbb951990c20fc38d168e588 (patch) | |
tree | cb732865c5fed8b796528dc66d3c9885abc88511 | |
parent | Added a section on bing words if you enable desktop notifications. (diff) | |
download | synapse-660364d6a7a4ad69bbb951990c20fc38d168e588.tar.xz |
Move the notification logic out of an individual room controller and into the general event handler, so we can notify for >1 room.
Diffstat (limited to '')
-rw-r--r-- | webclient/components/matrix/event-handler-service.js | 20 | ||||
-rw-r--r-- | webclient/room/room-controller.js | 16 |
2 files changed, 19 insertions, 17 deletions
diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js index fc5a81617c..8783b9b1e0 100644 --- a/webclient/components/matrix/event-handler-service.js +++ b/webclient/components/matrix/event-handler-service.js @@ -27,7 +27,8 @@ Typically, this service will store events or broadcast them to any listeners if typically all the $on method would do is update its own $scope. */ angular.module('eventHandlerService', []) -.factory('eventHandlerService', ['matrixService', '$rootScope', '$q', function(matrixService, $rootScope, $q) { +.factory('eventHandlerService', ['matrixService', '$rootScope', '$q', '$timeout', 'mPresence', +function(matrixService, $rootScope, $q, $timeout, mPresence) { var ROOM_CREATE_EVENT = "ROOM_CREATE_EVENT"; var MSG_EVENT = "MSG_EVENT"; var MEMBER_EVENT = "MEMBER_EVENT"; @@ -137,6 +138,23 @@ angular.module('eventHandlerService', []) else { $rootScope.events.rooms[event.room_id].messages.push(event); } + + if (window.Notification) { + // Show notification when the window is hidden, or the user is idle + if (document.hidden || matrixService.presence.unavailable === mPresence.getState()) { + console.log("Displaying notification for "+JSON.stringify(event)); + var notification = new window.Notification( + ($rootScope.events.rooms[event.room_id].members[event.user_id].displayname || event.user_id) + + " (" + (matrixService.getRoomIdToAliasMapping(event.room_id) || event.room_id) + ")", // FIXME: don't leak room_ids here + { + "body": event.content.body, + "icon": $rootScope.events.rooms[event.room_id].members[event.user_id].avatar_url + }); + $timeout(function() { + notification.close(); + }, 5 * 1000); + } + } } else { $rootScope.events.rooms[event.room_id].messages.unshift(event); diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js index 4a91d298bc..4a1dfd6aac 100644 --- a/webclient/room/room-controller.js +++ b/webclient/room/room-controller.js @@ -139,22 +139,6 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput']) if (isLive && event.room_id === $scope.room_id) { scrollToBottom(); - - if (window.Notification) { - // Show notification when the window is hidden, or the user is idle - if (document.hidden || matrixService.presence.unavailable === mPresence.getState()) { - var notification = new window.Notification( - ($scope.members[event.user_id].displayname || event.user_id) + - " (" + ($scope.room_alias || $scope.room_id) + ")", // FIXME: don't leak room_ids here - { - "body": event.content.body, - "icon": $scope.members[event.user_id].avatar_url - }); - $timeout(function() { - notification.close(); - }, 5 * 1000); - } - } } }); |