Parse /initialSync data and populate the new data structures.

pull/11/head
Kegan Dougal 2014-10-31 14:50:31 +00:00
parent 2aa79f4fbe
commit 394f77c3ff
2 changed files with 33 additions and 4 deletions

View File

@ -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) {

View File

@ -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]);
}
}
};