summary refs log tree commit diff
path: root/webclient/room
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-08-15 17:50:27 +0100
committerErik Johnston <erik@matrix.org>2014-08-15 17:50:27 +0100
commit7f5c7ddea9db879e500a48b47ad4f782d2d8416b (patch)
tree3332c614902b5641451da530ac9d2a3bed538a15 /webclient/room
parentFix some of the tests to reflect changes in the storage layer. (diff)
parentGet presence for members when you enter a room (it was coming down but wasn't... (diff)
downloadsynapse-7f5c7ddea9db879e500a48b47ad4f782d2d8416b.tar.xz
Merge branch 'master' of github.com:matrix-org/synapse into sql_refactor
Diffstat (limited to 'webclient/room')
-rw-r--r--webclient/room/room-controller.js48
-rw-r--r--webclient/room/room.html6
2 files changed, 48 insertions, 6 deletions
diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js
index 0d54c6f4d8..1b921325b3 100644
--- a/webclient/room/room-controller.js
+++ b/webclient/room/room-controller.js
@@ -15,6 +15,32 @@ limitations under the License.
 */
 
 angular.module('RoomController', [])
+// FIXME move directives outta here!
+.directive("keepScroll", function(){
+  return {
+    controller : function($scope){
+      var element = 0;
+      this.setElement = function(el){
+        element = el;
+      }
+      this.addItem = function(item){
+        element.scrollTop = (element.scrollTop+item.clientHeight+1); //1px for margin
+      };
+    },
+    link : function(scope,el,attr, ctrl) {
+     ctrl.setElement(el[0]);
+    }
+  };
+})
+// FIXME move directives outta here!
+.directive("scrollItem", function(){
+  return{
+    require : "^keepScroll",
+    link : function(scope, el, att, scrCtrl){
+      scrCtrl.addItem(el[0]);
+    }
+  }
+})
 .controller('RoomController', ['$scope', '$http', '$timeout', '$routeParams', '$location', 'matrixService', 'eventStreamService', 'eventHandlerService',
                                function($scope, $http, $timeout, $routeParams, $location, matrixService, eventStreamService, eventHandlerService) {
    'use strict';
@@ -54,7 +80,14 @@ angular.module('RoomController', [])
         updatePresence(event);
     });
     
-    var paginate = function(numItems) {
+    $scope.paginateMore = function() {
+        if ($scope.state.can_paginate) {
+            console.log("Paginating more.");
+            paginate(MESSAGES_PER_PAGINATION, false);
+        }
+    };
+    
+    var paginate = function(numItems, toBottom) {
         matrixService.paginateBackMessages($scope.room_id, $scope.state.earliest_token, numItems).then(
             function(response) {
                 eventHandlerService.handleEvents(response.data.chunk, false);
@@ -63,6 +96,11 @@ angular.module('RoomController', [])
                     // no more messages to paginate :(
                     $scope.state.can_paginate = false;
                 }
+                
+                if (toBottom) {
+                    console.log("Scrolling to bottom");
+                    scrollToBottom();
+                }
             },
             function(error) {
                 console.log("Failed to paginateBackMessages: " + JSON.stringify(error));
@@ -73,6 +111,10 @@ angular.module('RoomController', [])
     var updateMemberList = function(chunk) {
         var isNewMember = !(chunk.target_user_id in $scope.members);
         if (isNewMember) {
+            if ("state" in chunk.content) {
+                chunk.presenceState = chunk.content.state;
+            }
+        
             $scope.members[chunk.target_user_id] = chunk;
             // get their display name and profile picture and set it to their
             // member entry in $scope.members. We HAVE to use $timeout with 0 delay 
@@ -181,7 +223,7 @@ angular.module('RoomController', [])
                     }
                 );
                 
-                paginate(MESSAGES_PER_PAGINATION);
+                paginate(MESSAGES_PER_PAGINATION, true);
             },
             function(reason) {
                 $scope.feedback = "Can't join room: " + reason;
@@ -223,6 +265,6 @@ angular.module('RoomController', [])
     };
     
     $scope.loadMoreHistory = function() {
-        paginate(MESSAGES_PER_PAGINATION);
+        paginate(MESSAGES_PER_PAGINATION, false);
     };
 }]);
diff --git a/webclient/room/room.html b/webclient/room/room.html
index 93917071d9..e2a4c221c6 100644
--- a/webclient/room/room.html
+++ b/webclient/room/room.html
@@ -20,9 +20,9 @@
         </table>
     </div>
     
-    <div class="messageTableWrapper">
-        <table class="messageTable">
-            <tr ng-repeat="msg in events.rooms[room_id].messages" ng-class="msg.user_id === state.user_id ? 'mine' : ''">
+    <div class="messageTableWrapper" keep-scroll>
+        <table class="messageTable" infinite-scroll="paginateMore()">
+            <tr ng-repeat="msg in events.rooms[room_id].messages" ng-class="msg.user_id === state.user_id ? 'mine' : ''" scroll-item>
                 <td class="leftBlock">
                     <div class="sender" ng-hide="events.rooms[room_id].messages[$index - 1].user_id === msg.user_id">{{ members[msg.user_id].displayname || msg.user_id }}</div>
                     <div class="timestamp">{{ msg.content.hsob_ts | date:'MMM d HH:mm:ss' }}</div>