summary refs log tree commit diff
path: root/syweb/webclient/recents/recents-controller.js
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2014-11-12 14:55:57 +0000
committerKegan Dougal <kegan@matrix.org>2014-11-12 14:57:36 +0000
commit96cd467cfa129acaf8814e574c7cc2a9a94459c5 (patch)
tree37daca99cdb5553903f4a76f5e942dab3376e79f /syweb/webclient/recents/recents-controller.js
parentDocument StateStore and use transactions (diff)
downloadsynapse-96cd467cfa129acaf8814e574c7cc2a9a94459c5.tar.xz
Add recents-service to store shared state between recents-controllers.
Remove the selectedRoomId from rootScope and instead store it in
recents-service. Add a broadcast to notify listeners (recents-controller)
to updates of this.
Diffstat (limited to 'syweb/webclient/recents/recents-controller.js')
-rw-r--r--syweb/webclient/recents/recents-controller.js15
1 files changed, 9 insertions, 6 deletions
diff --git a/syweb/webclient/recents/recents-controller.js b/syweb/webclient/recents/recents-controller.js
index 062d106018..78aeca128d 100644
--- a/syweb/webclient/recents/recents-controller.js
+++ b/syweb/webclient/recents/recents-controller.js
@@ -17,8 +17,8 @@
 'use strict';
 
 angular.module('RecentsController', ['matrixService', 'matrixFilter'])
-.controller('RecentsController', ['$rootScope', '$scope', 'eventHandlerService', 'modelService', 
-                               function($rootScope, $scope, eventHandlerService, modelService) {
+.controller('RecentsController', ['$rootScope', '$scope', 'eventHandlerService', 'modelService', 'recentsService',
+                               function($rootScope, $scope, eventHandlerService, modelService, recentsService) {
 
     // Expose the service to the view
     $scope.eventHandlerService = eventHandlerService;
@@ -31,8 +31,11 @@ angular.module('RecentsController', ['matrixService', 'matrixFilter'])
             // room_id: <number>
         };
     }
-
-    // $rootScope.recentsSelectedRoomID is used in the html, and is set by room-controller.
+    
+    $scope.recentsSelectedRoomID = recentsService.getSelectedRoomId();
+    $scope.$on(recentsService.BROADCAST_SELECTED_ROOM_ID, function(ngEvent, room_id) {
+        $scope.recentsSelectedRoomID = room_id;
+    });
     
     
     $scope.selectRoom = function(room) {
@@ -43,12 +46,12 @@ angular.module('RecentsController', ['matrixService', 'matrixFilter'])
     };
     
     $scope.$on(eventHandlerService.MSG_EVENT, function(ngEvent, event, isLive) {
-        if (isLive && event.room_id !== $rootScope.recentsSelectedRoomID) {
+        if (isLive && event.room_id !== $scope.recentsSelectedRoomID) {
             if (!$rootScope.unreadMessages[event.room_id]) {
                 $rootScope.unreadMessages[event.room_id] = 0;
             }
             $rootScope.unreadMessages[event.room_id] += 1;
-            console.log("sel="+$rootScope.recentsSelectedRoomID+" unread:"+JSON.stringify($rootScope.unreadMessages, undefined, 2));
+            console.log("sel="+$scope.recentsSelectedRoomID+" unread:"+JSON.stringify($rootScope.unreadMessages, undefined, 2));
         }
     });