From 02e45da895133ebe80866b1374ad86ab64cc7fb9 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Fri, 15 Aug 2014 15:40:37 +0100 Subject: [PATCH] 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) --- .../matrix/event-handler-service.js | 19 ++++++++------ webclient/rooms/rooms-controller.js | 25 ++++++++++++++----- 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; iMy rooms -
+
- {{ room.room_alias }} + {{ room.room_alias }} {{room.membership === 'invite' ? ' (invited)' : ''}}