0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-11-03 05:08:59 +01:00

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

View file

@ -738,7 +738,10 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
// Make recents highlight the current room // Make recents highlight the current room
$scope.recentsSelectedRoomID = $scope.room_id; $scope.recentsSelectedRoomID = $scope.room_id;
// Get the up-to-date the current member list // Init the history for this room
history.init();
// Get the up-to-date the current member list
matrixService.getMemberList($scope.room_id).then( matrixService.getMemberList($scope.room_id).then(
function(response) { function(response) {
for (var i = 0; i < response.data.chunk.length; i++) { for (var i = 0; i < response.data.chunk.length; i++) {
@ -851,6 +854,8 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
}; };
// Manage history of typed messages // 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 = { var history = {
// The list of typed messages. Index 0 is the more recents // The list of typed messages. Index 0 is the more recents
data: [], data: [],
@ -861,10 +866,21 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
// The message the user has started to type before going into the history // The message the user has started to type before going into the history
typingMessage: undefined, 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 // Store a message in the history
push: function(message) { push: function(message) {
this.data.unshift(message); this.data.unshift(message);
// Update the session storage
sessionStorage.setItem("history_" + $scope.room_id, JSON.stringify(this.data));
// Reset history position // Reset history position
this.position = -1; this.position = -1;
this.typingMessage = undefined; this.typingMessage = undefined;