diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js index f248116914..d6a0600132 100644 --- a/webclient/components/matrix/event-handler-service.js +++ b/webclient/components/matrix/event-handler-service.js @@ -28,6 +28,7 @@ if typically all the $on method would do is update its own $scope. */ angular.module('eventHandlerService', []) .factory('eventHandlerService', ['matrixService', '$rootScope', '$q', function(matrixService, $rootScope, $q) { + var ROOM_CREATE_EVENT = "ROOM_CREATE_EVENT"; var MSG_EVENT = "MSG_EVENT"; var MEMBER_EVENT = "MEMBER_EVENT"; var PRESENCE_EVENT = "PRESENCE_EVENT"; @@ -48,7 +49,7 @@ angular.module('eventHandlerService', []) $rootScope.events.rooms[room_id].messages = []; $rootScope.events.rooms[room_id].members = {}; } - } + }; var resetRoomMessages = function(room_id) { if ($rootScope.events.rooms[room_id]) { @@ -56,6 +57,13 @@ angular.module('eventHandlerService', []) } }; + var handleRoomCreate = function(event, isLiveEvent) { + initRoom(event.room_id); + + // For now, we do not use the event data. Simply signal it to the app controllers + $rootScope.$broadcast(ROOM_CREATE_EVENT, event, isLiveEvent); + }; + var handleMessage = function(event, isLiveEvent) { initRoom(event.room_id); @@ -110,6 +118,7 @@ angular.module('eventHandlerService', []) }; return { + ROOM_CREATE_EVENT: ROOM_CREATE_EVENT, MSG_EVENT: MSG_EVENT, MEMBER_EVENT: MEMBER_EVENT, PRESENCE_EVENT: PRESENCE_EVENT, @@ -118,6 +127,9 @@ angular.module('eventHandlerService', []) handleEvent: function(event, isLiveEvent) { switch(event.type) { + case "m.room.create": + handleRoomCreate(event, isLiveEvent); + break; case "m.room.message": handleMessage(event, isLiveEvent); break; @@ -140,7 +152,7 @@ angular.module('eventHandlerService', []) console.log(JSON.stringify(event, undefined, 4)); break; } - if (event.type.indexOf('m.call.') == 0) { + if (event.type.indexOf('m.call.') === 0) { handleCallEvent(event, isLiveEvent); } }, diff --git a/webclient/home/home-controller.js b/webclient/home/home-controller.js index 847918d5dc..f4ce3053ea 100644 --- a/webclient/home/home-controller.js +++ b/webclient/home/home-controller.js @@ -17,8 +17,8 @@ limitations under the License. 'use strict'; angular.module('HomeController', ['matrixService', 'eventHandlerService', 'RecentsController']) -.controller('HomeController', ['$scope', '$location', 'matrixService', - function($scope, $location, matrixService) { +.controller('HomeController', ['$scope', '$location', 'matrixService', 'eventHandlerService', + function($scope, $location, matrixService, eventHandlerService) { $scope.config = matrixService.config(); $scope.public_rooms = []; @@ -72,7 +72,6 @@ angular.module('HomeController', ['matrixService', 'eventHandlerService', 'Recen response.data.room_id); matrixService.createRoomIdToAliasMapping( response.data.room_id, response.data.room_alias); - refresh(); }, function(error) { $scope.feedback = "Failure: " + error.data; @@ -133,6 +132,14 @@ angular.module('HomeController', ['matrixService', 'eventHandlerService', 'Recen } ); + // Listen to room creation event in order to update the public rooms list + $scope.$on(eventHandlerService.ROOM_CREATE_EVENT, function(ngEvent, event, isLive) { + if (isLive) { + // As we do not know if this room is public, do a full list refresh + refresh(); + } + }); + refresh(); }; }]); diff --git a/webclient/recents/recents-controller.js b/webclient/recents/recents-controller.js index 947bd29de3..d7d3bf4053 100644 --- a/webclient/recents/recents-controller.js +++ b/webclient/recents/recents-controller.js @@ -47,6 +47,11 @@ angular.module('RecentsController', ['matrixService', 'eventHandlerService']) $scope.rooms[event.room_id].lastMsg = event; } }); + $scope.$on(eventHandlerService.ROOM_CREATE_EVENT, function(ngEvent, event, isLive) { + if (isLive) { + $scope.rooms[event.room_id] = event; + } + }); };