diff options
author | Kegan Dougal <kegan@matrix.org> | 2014-08-15 11:31:13 +0100 |
---|---|---|
committer | Kegan Dougal <kegan@matrix.org> | 2014-08-15 14:06:56 +0100 |
commit | 5dbceaf5a40a7e90a4aca1a1612fa9ea13290a02 (patch) | |
tree | afe6432266ad80f95b31390370df5278c931bf76 /webclient/room/room-controller.js | |
parent | Added event stream service which neatly blobs together requests / state for t... (diff) | |
download | synapse-5dbceaf5a40a7e90a4aca1a1612fa9ea13290a02.tar.xz |
Added event handler service which.. handles events. More specifically, it $broadcasts events depending on their type, and does processing on events (shuffling keys, adding events to $rootScope so displays will automatically update, sending delivery receipts, and so on). Some of this logic was previously contained in the RoomController, which fails the moment you add >1 room into the mix, hence requiring a Service to handle events, rather than having each individual controller maintain their part of the world.
Diffstat (limited to '')
-rw-r--r-- | webclient/room/room-controller.js | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js index 3f69a12c23..301d3d6447 100644 --- a/webclient/room/room-controller.js +++ b/webclient/room/room-controller.js @@ -15,8 +15,8 @@ limitations under the License. */ angular.module('RoomController', []) -.controller('RoomController', ['$scope', '$http', '$timeout', '$routeParams', '$location', 'matrixService', 'eventStreamService', - function($scope, $http, $timeout, $routeParams, $location, matrixService, eventStreamService) { +.controller('RoomController', ['$scope', '$http', '$timeout', '$routeParams', '$location', 'matrixService', 'eventStreamService', 'eventHandlerService', + function($scope, $http, $timeout, $routeParams, $location, matrixService, eventStreamService, eventHandlerService) { 'use strict'; var MESSAGES_PER_PAGINATION = 10; $scope.room_id = $routeParams.room_id; @@ -42,34 +42,28 @@ angular.module('RoomController', []) },0); }; - var parseChunk = function(chunks, appendToStart) { - for (var i = 0; i < chunks.length; i++) { - var chunk = chunks[i]; - if (chunk.room_id == $scope.room_id && chunk.type == "m.room.message") { - if ("membership_target" in chunk.content) { - chunk.user_id = chunk.content.membership_target; - } - if (appendToStart) { - $scope.messages.unshift(chunk); - } - else { - $scope.messages.push(chunk); - scrollToBottom(); - } - } - else if (chunk.room_id == $scope.room_id && chunk.type == "m.room.member") { - updateMemberList(chunk); - } - else if (chunk.type === "m.presence") { - updatePresence(chunk); - } + $scope.$on(eventHandlerService.MSG_EVENT, function(ngEvent, event, isLive) { + if (isLive) { + $scope.messages.push(event); + scrollToBottom(); } - }; + else { + $scope.messages.unshift(event); + } + }); + + $scope.$on(eventHandlerService.MEMBER_EVENT, function(ngEvent, event, isLive) { + updateMemberList(event); + }); + + $scope.$on(eventHandlerService.PRESENCE_EVENT, function(ngEvent, event, isLive) { + updatePresence(event); + }); var paginate = function(numItems) { matrixService.paginateBackMessages($scope.room_id, $scope.state.earliest_token, numItems).then( function(response) { - parseChunk(response.data.chunk, true); + eventHandlerService.handleEvents(response.data.chunk, false); $scope.state.earliest_token = response.data.end; if (response.data.chunk.length < MESSAGES_PER_PAGINATION) { // no more messages to paginate :( @@ -89,8 +83,8 @@ angular.module('RoomController', []) console.log("Got response from "+$scope.state.events_from+" to "+response.data.end); $scope.state.events_from = response.data.end; $scope.feedback = ""; - - parseChunk(response.data.chunk, false); + + eventHandlerService.handleEvents(response.data.chunk, true); if ($scope.stopPoll) { console.log("Stopping polling."); |