summary refs log tree commit diff
path: root/webclient/rooms/rooms-controller.js
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2014-08-15 15:40:37 +0100
committerKegan Dougal <kegan@matrix.org>2014-08-15 17:42:11 +0100
commit02e45da895133ebe80866b1374ad86ab64cc7fb9 (patch)
tree9c68b8bdfd2f6bf01bcb2b995f48e25042c76a66 /webclient/rooms/rooms-controller.js
parentDocument that /rooms/:room_id/members/list yields profile and presence inform... (diff)
downloadsynapse-02e45da895133ebe80866b1374ad86ab64cc7fb9.tar.xz
When new invites come down, update the My Rooms list. Added hacks to make the display name a bit nicer (/im/sync needs to return room aliases / membership events better)
Diffstat (limited to 'webclient/rooms/rooms-controller.js')
-rw-r--r--webclient/rooms/rooms-controller.js25
1 files changed, 19 insertions, 6 deletions
diff --git a/webclient/rooms/rooms-controller.js b/webclient/rooms/rooms-controller.js
index 2ce14e1d49..da79c23d55 100644
--- a/webclient/rooms/rooms-controller.js
+++ b/webclient/rooms/rooms-controller.js
@@ -16,11 +16,11 @@ limitations under the License.
 
 'use strict';
 
-angular.module('RoomsController', ['matrixService', 'mFileInput', 'mFileUpload'])
-.controller('RoomsController', ['$scope', '$location', 'matrixService', 'mFileUpload',
-                               function($scope, $location, matrixService, mFileUpload) {
+angular.module('RoomsController', ['matrixService', 'mFileInput', 'mFileUpload', 'eventHandlerService'])
+.controller('RoomsController', ['$scope', '$location', 'matrixService', 'mFileUpload', 'eventHandlerService',
+                               function($scope, $location, matrixService, mFileUpload, eventHandlerService) {
                                    
-    $scope.rooms = [];
+    $scope.rooms = {};
     $scope.public_rooms = [];
     $scope.newRoomId = "";
     $scope.feedback = "";
@@ -52,6 +52,18 @@ angular.module('RoomsController', ['matrixService', 'mFileInput', 'mFileUpload']
         linkedEmailList: matrixService.config().emailList // linked email list
     };
     
+    $scope.$on(eventHandlerService.MEMBER_EVENT, function(ngEvent, event, isLive) {
+        var config = matrixService.config();
+        if (event.target_user_id === config.user_id && event.content.membership === "invite") {
+            console.log("Invited to room " + event.room_id);
+            // FIXME push membership to top level key to match /im/sync
+            event.membership = event.content.membership;
+            // FIXME bodge a nicer name than the room ID for this invite.
+            event.room_alias = event.user_id + "'s room";
+            $scope.rooms[event.room_id] = event;
+        }
+    });
+    
     var assignRoomAliases = function(data) {
         for (var i=0; i<data.length; i++) {
             var alias = matrixService.getRoomIdToAliasMapping(data[i].room_id);
@@ -73,12 +85,13 @@ angular.module('RoomsController', ['matrixService', 'mFileInput', 'mFileUpload']
 
     $scope.refresh = function() {
         // List all rooms joined or been invited to
-        $scope.rooms = matrixService.rooms();
         matrixService.rooms().then(
             function(response) {
                 var data = assignRoomAliases(response.data);
                 $scope.feedback = "Success";
-                $scope.rooms = data;
+                for (var i=0; i<data.length; i++) {
+                    $scope.rooms[data[i].room_id] = data[i];
+                }
             },
             function(error) {
                 $scope.feedback = "Failure: " + error.data;