summary refs log tree commit diff
path: root/webclient/room/room-controller.js
diff options
context:
space:
mode:
authorMatthew Hodgson <matthew@matrix.org>2014-08-17 03:48:28 +0100
committerMatthew Hodgson <matthew@matrix.org>2014-08-17 03:48:28 +0100
commit60245c4f90f60dc7af79165cf074a4df57a02558 (patch)
tree0ceb74ee15def532e833d7f87c2052e13af7713b /webclient/room/room-controller.js
parentunbreak login sequence (which spuriously required a sydent server to be speci... (diff)
downloadsynapse-60245c4f90f60dc7af79165cf074a4df57a02558.tar.xz
implement html5 notifications. (have to be explicitly requested under Config)
Diffstat (limited to 'webclient/room/room-controller.js')
-rw-r--r--webclient/room/room-controller.js19
1 files changed, 18 insertions, 1 deletions
diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js
index 304b06c1f1..30f66de458 100644
--- a/webclient/room/room-controller.js
+++ b/webclient/room/room-controller.js
@@ -137,6 +137,23 @@ angular.module('RoomController', ['ngSanitize'])
     $scope.$on(eventHandlerService.MSG_EVENT, function(ngEvent, event, isLive) {
         if (isLive && event.room_id === $scope.room_id) {
             scrollToBottom();
+            
+            if (window.Notification) {
+                // FIXME: we should also notify based on a timer or other heuristics
+                // rather than the window being minimised
+                if (document.hidden) {
+                    var notification = new window.Notification(
+                        ($scope.members[event.user_id].displayname || event.user_id) +
+                        " (" + $scope.room_alias + ")",
+                    {
+                        "body": event.content.body,
+                        "icon": $scope.members[event.user_id].avatar_url,
+                    });
+                    $timeout(function() {
+                        notification.close();
+                    }, 5 * 1000);
+                }
+            }
         }
     });
     
@@ -154,7 +171,7 @@ angular.module('RoomController', ['ngSanitize'])
             paginate(MESSAGES_PER_PAGINATION);
         }
     };
-    
+        
     var paginate = function(numItems) {
         // console.log("paginate " + numItems);
         if ($scope.state.paginating) {