diff options
Diffstat (limited to 'webclient/components')
-rw-r--r-- | webclient/components/matrix/event-handler-service.js | 12 | ||||
-rw-r--r-- | 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<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]); + } } }; |