WEB-29: Improve room page content loading

InitialSync: load the 30 last messages of each room so that a full page of messages can be displayed without additionnal request
pull/10/head
Emmanuel ROHEE 2014-09-16 15:03:07 +02:00
parent f4094c5eb3
commit 45592ccdfd
3 changed files with 26 additions and 8 deletions

View File

@ -329,13 +329,29 @@ angular.module('eventHandlerService', [])
},
// Handle messages from /initialSync or /messages
handleRoomMessages: function(room_id, messages, isLiveEvents) {
handleRoomMessages: function(room_id, messages, isLiveEvents, dir) {
initRoom(room_id);
this.handleEvents(messages.chunk, isLiveEvents);
// Store how far back we've paginated
// This assumes the paginations requests are contiguous and in reverse chronological order
$rootScope.events.rooms[room_id].pagination.earliest_token = messages.end;
var events = messages.chunk;
// Handles messages according to their time order
if (dir && 'b' === dir) {
// paginateBackMessages requests messages to be in reverse chronological order
for (var i=0; i<events.length; i++) {
this.handleEvent(events[i], isLiveEvents, isLiveEvents);
}
// Store how far back we've paginated
$rootScope.events.rooms[room_id].pagination.earliest_token = messages.end;
}
else {
// InitialSync returns messages in chronological order
for (var i=events.length - 1; i>=0; i--) {
this.handleEvent(events[i], isLiveEvents, isLiveEvents);
}
// Store where to start pagination
$rootScope.events.rooms[room_id].pagination.earliest_token = messages.start;
}
},
handleInitialSyncDone: function(initialSyncData) {

View File

@ -104,8 +104,10 @@ angular.module('eventStreamService', [])
settings.isActive = true;
var deferred = $q.defer();
// Initial sync: get all information and the last message of all rooms of the user
matrixService.initialSync(1, false).then(
// Initial sync: get all information and the last 30 messages of all rooms of the user
// 30 messages should be enough to display a full page of messages in a room
// without requiring to make an additional request
matrixService.initialSync(30, false).then(
function(response) {
var rooms = response.data.rooms;
for (var i = 0; i < rooms.length; ++i) {

View File

@ -235,7 +235,7 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
matrixService.paginateBackMessages($scope.room_id, $rootScope.events.rooms[$scope.room_id].pagination.earliest_token, numItems).then(
function(response) {
eventHandlerService.handleRoomMessages($scope.room_id, response.data, false);
eventHandlerService.handleRoomMessages($scope.room_id, response.data, false, 'b');
if (response.data.chunk.length < MESSAGES_PER_PAGINATION) {
// no more messages to paginate. this currently never gets turned true again, as we never
// expire paginated contents in the current implementation.