summary refs log tree commit diff
path: root/syweb/webclient/components
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/components
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/components')
-rw-r--r--syweb/webclient/components/matrix/recents-service.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/syweb/webclient/components/matrix/recents-service.js b/syweb/webclient/components/matrix/recents-service.js
new file mode 100644
index 0000000000..64d1ab93b4
--- /dev/null
+++ b/syweb/webclient/components/matrix/recents-service.js
@@ -0,0 +1,51 @@
+/*
+Copyright 2014 OpenMarket Ltd
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+'use strict';
+
+/*
+This service manages shared state between *instances* of recent lists. The
+recents controller will hook into this central service to get things like:
+- which rooms should be highlighted
+- which rooms have been binged
+- which room is currently selected
+- etc.
+This is preferable to polluting the $rootScope with recents specific info, and
+makes the dependency on this shared state *explicit*.
+*/
+angular.module('recentsService', [])
+.factory('recentsService', ['$rootScope', function($rootScope) {
+    // notify listeners when variables in the service are updated. We need to do
+    // this since we do not tie them to any scope.
+    var BROADCAST_SELECTED_ROOM_ID = "recentsService:BROADCAST_SELECTED_ROOM_ID";
+    var selectedRoomId = undefined;
+    
+    
+    return {
+        BROADCAST_SELECTED_ROOM_ID: BROADCAST_SELECTED_ROOM_ID,
+    
+        getSelectedRoomId: function() {
+            return selectedRoomId;
+        },
+        
+        setSelectedRoomId: function(room_id) {
+            selectedRoomId = room_id;
+            $rootScope.$broadcast(BROADCAST_SELECTED_ROOM_ID, room_id);
+        }
+    
+    };
+
+}]);