summary refs log tree commit diff
path: root/webclient/room/room-controller.js
diff options
context:
space:
mode:
authorEmmanuel ROHEE <erohee@amdocs.com>2014-09-17 14:38:33 +0200
committerEmmanuel ROHEE <erohee@amdocs.com>2014-09-17 14:38:33 +0200
commitb3a0961c6c0c60ca566675efb152252220f42d0a (patch)
tree7e78461d763824fad6553de8053409cc49f86a2a /webclient/room/room-controller.js
parentSYWEB-7: Up & down keys let user step through the history as per readline or ... (diff)
downloadsynapse-b3a0961c6c0c60ca566675efb152252220f42d0a.tar.xz
SYWEB-7: Use sessionStorage to make per-room history survives when the user navigates through rooms
Diffstat (limited to 'webclient/room/room-controller.js')
-rw-r--r--webclient/room/room-controller.js18
1 files changed, 17 insertions, 1 deletions
diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js
index 15056b947a..45f2422c90 100644
--- a/webclient/room/room-controller.js
+++ b/webclient/room/room-controller.js
@@ -738,7 +738,10 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
         // Make recents highlight the current room
         $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(
             function(response) {
                 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
+    // 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;