diff options
author | Kegan Dougal <kegan@matrix.org> | 2014-08-15 15:40:37 +0100 |
---|---|---|
committer | Kegan Dougal <kegan@matrix.org> | 2014-08-15 17:42:11 +0100 |
commit | 02e45da895133ebe80866b1374ad86ab64cc7fb9 (patch) | |
tree | 9c68b8bdfd2f6bf01bcb2b995f48e25042c76a66 | |
parent | Document that /rooms/:room_id/members/list yields profile and presence inform... (diff) | |
download | synapse-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)
-rw-r--r-- | webclient/components/matrix/event-handler-service.js | 19 | ||||
-rw-r--r-- | webclient/rooms/rooms-controller.js | 25 | ||||
-rw-r--r-- | webclient/rooms/rooms.html | 4 |
3 files changed, 32 insertions, 16 deletions
diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js index f7411fd80a..b8529895fe 100644 --- a/webclient/components/matrix/event-handler-service.js +++ b/webclient/components/matrix/event-handler-service.js @@ -33,23 +33,24 @@ angular.module('eventHandlerService', []) var PRESENCE_EVENT = "PRESENCE_EVENT"; $rootScope.events = { - rooms: {}, // will contain roomId: { messages:[], members:[] } + rooms: {}, // will contain roomId: { messages:[], members:{userid1: event} } }; var initRoom = function(room_id) { - console.log("Creating new handler entry for " + room_id); - $rootScope.events.rooms[room_id] = {}; - $rootScope.events.rooms[room_id].messages = []; - $rootScope.events.rooms[room_id].members = []; + if (!(room_id in $rootScope.events.rooms)) { + console.log("Creating new handler entry for " + room_id); + $rootScope.events.rooms[room_id] = {}; + $rootScope.events.rooms[room_id].messages = []; + $rootScope.events.rooms[room_id].members = {}; + } } var handleMessage = function(event, isLiveEvent) { if ("membership_target" in event.content) { event.user_id = event.content.membership_target; } - if (!(event.room_id in $rootScope.events.rooms)) { - initRoom(event.room_id); - } + + initRoom(event.room_id); if (isLiveEvent) { $rootScope.events.rooms[event.room_id].messages.push(event); @@ -67,6 +68,8 @@ angular.module('eventHandlerService', []) }; var handleRoomMember = function(event, isLiveEvent) { + initRoom(event.room_id); + $rootScope.events.rooms[event.room_id].members[event.user_id] = event; $rootScope.$broadcast(MEMBER_EVENT, event, isLiveEvent); }; 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; diff --git a/webclient/rooms/rooms.html b/webclient/rooms/rooms.html index 5974bd940c..8edeb13ced 100644 --- a/webclient/rooms/rooms.html +++ b/webclient/rooms/rooms.html @@ -61,9 +61,9 @@ <h3>My rooms</h3> - <div class="rooms" ng-repeat="room in rooms"> + <div class="rooms" ng-repeat="(rm_id, room) in rooms"> <div> - <a href="#/room/{{ room.room_id }}" >{{ room.room_alias }}</a> + <a href="#/room/{{ rm_id }}" >{{ room.room_alias }}</a> {{room.membership === 'invite' ? ' (invited)' : ''}} </div> </div> <br/> |