From 394f77c3ff2d849b4ec69595f40ebfcc84ed1d31 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Fri, 31 Oct 2014 14:50:31 +0000 Subject: [PATCH] Parse /initialSync data and populate the new data structures. --- .../matrix/event-handler-service.js | 12 +++++++++ webclient/components/matrix/model-service.js | 25 ++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js index 84b2a220e7..a8d89834ae 100644 --- a/webclient/components/matrix/event-handler-service.js +++ b/webclient/components/matrix/event-handler-service.js @@ -86,6 +86,18 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService } $rootScope.events.rooms[room_id].membership = room.membership; } + + // ========================================= + var __room = modelService.getRoom(room_id); + if (room) { // /initialSync data + __room.current_room_state.storeStateEvents(room.state); + __room.current_room_state.pagination_token = room.messages.end; + + __room.old_room_state.storeStateEvents(room.state); + __room.old_room_state.pagination_token = room.messages.start; + + __room.addMessages(room.messages.chunk); + } }; var resetRoomMessages = function(room_id) { diff --git a/webclient/components/matrix/model-service.js b/webclient/components/matrix/model-service.js index c10e5185ad..0ba23cb76a 100644 --- a/webclient/components/matrix/model-service.js +++ b/webclient/components/matrix/model-service.js @@ -31,10 +31,22 @@ angular.module('modelService', []) /***** Room Object *****/ var Room = function Room(room_id) { this.room_id = room_id; - this.old_room_state = RoomState(); - this.current_room_state = RoomState(); + this.old_room_state = new RoomState(); + this.current_room_state = new RoomState(); + this.messages = []; // events which can be displayed on the UI. TODO move? }; Room.prototype = { + addMessages: function addMessages(events, toFront) { + for (var i=0; i