summary refs log tree commit diff
path: root/webclient/room
diff options
context:
space:
mode:
authorEmmanuel ROHEE <erohee@amdocs.com>2014-09-05 17:52:11 +0200
committerEmmanuel ROHEE <erohee@amdocs.com>2014-09-05 17:52:11 +0200
commit12a23f01b4d2b4a9a10b3db5373d092136e9a772 (patch)
treeaa85bfb9ec3422376937888b8c9ae5f8b1d08964 /webclient/room
parentdoc: kick can take a reason arg (diff)
downloadsynapse-12a23f01b4d2b4a9a10b3db5373d092136e9a772.tar.xz
autoscroll down(if the scroller was already at the bottom) when receiving member events
Diffstat (limited to '')
-rw-r--r--webclient/room/room-controller.js31
1 files changed, 18 insertions, 13 deletions
diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js
index 905a0723d8..2267283fb8 100644
--- a/webclient/room/room-controller.js
+++ b/webclient/room/room-controller.js
@@ -42,23 +42,24 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
     $scope.imageURLToSend = "";
     $scope.userIDToInvite = "";
     
-    var scrollToBottom = function() {
+    var scrollToBottom = function(force) {
         console.log("Scrolling to bottom");
-        $timeout(function() {
-            var objDiv = document.getElementById("messageTableWrapper");
-            objDiv.scrollTop = objDiv.scrollHeight;
-        }, 0);
+        
+        // Do not autoscroll to the bottom to display the new event if the user is not at the bottom.
+        // Exception: in case where the event is from the user, we want to force scroll to the bottom
+        var objDiv = document.getElementById("messageTableWrapper");
+        if ((objDiv.offsetHeight + objDiv.scrollTop >= objDiv.scrollHeight) || force) {
+            
+            $timeout(function() {
+                objDiv.scrollTop = objDiv.scrollHeight;
+            }, 0);
+        }
     };
 
     $scope.$on(eventHandlerService.MSG_EVENT, function(ngEvent, event, isLive) {
         if (isLive && event.room_id === $scope.room_id) {
-
-            // Do not autoscroll to the bottom to display this new event if the user is not at the bottom.
-            // Exception: if the event is from the user, scroll to the bottom
-            var objDiv = document.getElementById("messageTableWrapper");
-            if ( (objDiv.offsetHeight + objDiv.scrollTop >= objDiv.scrollHeight) || event.user_id === $scope.state.user_id) {
-                scrollToBottom();
-            }
+            
+            scrollToBottom();
 
             if (window.Notification) {
                 // Show notification when the user is idle
@@ -80,6 +81,7 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
     
     $scope.$on(eventHandlerService.MEMBER_EVENT, function(ngEvent, event, isLive) {
         if (isLive) {
+            scrollToBottom();
             updateMemberList(event);
         }
     });
@@ -288,6 +290,8 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
             return;
         }
         
+        scrollToBottom(true);
+        
         var promise;
         var isCmd = false;
         
@@ -614,7 +618,8 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
     };
 
     $scope.sendImage = function(url, body) {
-
+        scrollToBottom(true);
+        
         matrixService.sendImageMessage($scope.room_id, url, body).then(
             function() {
                 console.log("Image sent");