SYWEB-7: Use sessionStorage to make per-room history survives when the user navigates through rooms

This commit is contained in:
Emmanuel ROHEE 2014-09-17 14:38:33 +02:00
parent d9a9a47075
commit b3a0961c6c
1 changed files with 17 additions and 1 deletions

View File

@ -738,6 +738,9 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
// Make recents highlight the current room
$scope.recentsSelectedRoomID = $scope.room_id;
// Init the history for this room
history.init();
// Get the up-to-date the current member list
matrixService.getMemberList($scope.room_id).then(
function(response) {
@ -851,6 +854,8 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
};
// Manage history of typed messages
// History is saved in sessionStoratge so that it survives when the user
// navigates through the rooms and when it refreshes the page
var history = {
// The list of typed messages. Index 0 is the more recents
data: [],
@ -861,10 +866,21 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
// The message the user has started to type before going into the history
typingMessage: undefined,
// Init/load data for the current room
init: function() {
var data = sessionStorage.getItem("history_" + $scope.room_id);
if (data) {
this.data = JSON.parse(data);
}
},
// Store a message in the history
push: function(message) {
this.data.unshift(message);
// Update the session storage
sessionStorage.setItem("history_" + $scope.room_id, JSON.stringify(this.data));
// Reset history position
this.position = -1;
this.typingMessage = undefined;