summary refs log tree commit diff
path: root/webclient/components
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2014-10-31 14:50:31 +0000
committerKegan Dougal <kegan@matrix.org>2014-10-31 14:50:31 +0000
commit394f77c3ff2d849b4ec69595f40ebfcc84ed1d31 (patch)
treef50d3e63e7abb7cd12e3be9983084b21ba0a6164 /webclient/components
parentAdded model-service.js to store model data. (diff)
downloadsynapse-394f77c3ff2d849b4ec69595f40ebfcc84ed1d31.tar.xz
Parse /initialSync data and populate the new data structures.
Diffstat (limited to 'webclient/components')
-rw-r--r--webclient/components/matrix/event-handler-service.js12
-rw-r--r--webclient/components/matrix/model-service.js25
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<events.length; i++) {
+                if (toFront) {
+                    this.messages.unshift(events[i]);
+                }
+                else {
+                    this.messages.push(events[i]);
+                }
+            }
+        },
+        
         leave: function leave() {
             return matrixService.leave(this.room_id);
         }
@@ -46,7 +58,6 @@ angular.module('modelService', [])
         this.members = []; 
         // state events, the key is a compound of event type + state_key
         this.state_events = {}; 
-        // earliest token
         this.pagination_token = ""; 
     };
     RoomState.prototype = {
@@ -62,8 +73,14 @@ angular.module('modelService', [])
             return this.state_events[type + state_key];
         },
         
-        storeState: function storeState(event) {
+        storeStateEvent: function storeState(event) {
             this.state_events[event.type + event.state_key] = event;
+        },
+        
+        storeStateEvents: function storeState(events) {
+            for (var i=0; i<events.length; i++) {
+                this.storeStateEvent(events[i]);
+            }
         }
     };