summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmmanuel ROHEE <erohee@amdocs.com>2014-09-10 16:46:06 +0200
committerEmmanuel ROHEE <erohee@amdocs.com>2014-09-10 16:46:06 +0200
commit811716592c71657a80b181b664639d19f9d1988e (patch)
tree2b20e24bbbb1f9b799430e6f9f37614f97f0ea78
parentMember event: store use the the latest one (diff)
downloadsynapse-811716592c71657a80b181b664639d19f9d1988e.tar.xz
Made users count auto updating. Do show it if the info is not available (ex:user has not joined the room yet)
-rw-r--r--webclient/recents/recents-controller.js38
-rw-r--r--webclient/recents/recents.html4
2 files changed, 30 insertions, 12 deletions
diff --git a/webclient/recents/recents-controller.js b/webclient/recents/recents-controller.js
index aedc7b7a49..5cf74cad4e 100644
--- a/webclient/recents/recents-controller.js
+++ b/webclient/recents/recents-controller.js
@@ -48,6 +48,9 @@ angular.module('RecentsController', ['matrixService', 'matrixFilter', 'eventHand
                 if ($rootScope.rooms[event.room_id]) {
                     $rootScope.rooms[event.room_id].lastMsg = event;
                 }
+                
+                // Update room users count
+                $rootScope.rooms[event.room_id].numUsersInRoom = getUsersCountInRoom(event.room_id);
             }
         });
         $rootScope.$on(eventHandlerService.MSG_EVENT, function(ngEvent, event, isLive) {
@@ -67,6 +70,29 @@ angular.module('RecentsController', ['matrixService', 'matrixFilter', 'eventHand
         });
     };
     
+    /**
+     * Compute the room users number, ie the number of members who has joined the room.
+     * @param {String} room_id the room id
+     * @returns {undefined | Number} the room users number if available
+     */
+    var getUsersCountInRoom = function(room_id) {
+        var memberCount;
+        
+        var room = $rootScope.events.rooms[room_id];
+        if (room) {
+            memberCount = 0;
+            
+            for (var i in room.members) {
+                var member = room.members[i];
+                
+                if ("join" === member.membership) {
+                    memberCount = memberCount + 1;
+                }
+            }
+        }
+        
+        return memberCount;
+    }
 
     $scope.onInit = function() {
         // Init recents list only once
@@ -92,17 +118,7 @@ angular.module('RecentsController', ['matrixService', 'matrixFilter', 'eventHand
                         $rootScope.rooms[room.room_id].lastMsg = room.messages.chunk[0];
                     }
                     
-                    
-                    var numUsersInRoom = 0;
-                    if (room.state) {
-                        for (var j=0; j<room.state.length; j++) {
-                            var stateEvent = room.state[j];
-                            if (stateEvent.type == "m.room.member" && stateEvent.content.membership == "join") {
-                                numUsersInRoom += 1;
-                            }
-                        }
-                    }
-                    $rootScope.rooms[room.room_id].numUsersInRoom = numUsersInRoom;
+                    $rootScope.rooms[room.room_id].numUsersInRoom = getUsersCountInRoom(room.room_id);
                 }
 
                 // From now, update recents from the stream
diff --git a/webclient/recents/recents.html b/webclient/recents/recents.html
index 4726b61cb3..d6bea52cbe 100644
--- a/webclient/recents/recents.html
+++ b/webclient/recents/recents.html
@@ -9,7 +9,9 @@
                     {{ room.room_id | mRoomName }}
                 </td>
                 <td class="recentsRoomSummaryTS">
-                    {{ room.numUsersInRoom || '1' }} {{ room.numUsersInRoom == 1 ? 'user' : 'users' }}
+                    <span ng-show="undefined !== room.numUsersInRoom">
+                        {{ room.numUsersInRoom || '1' }} {{ room.numUsersInRoom == 1 ? 'user' : 'users' }}                     
+                    </span>
                 </td>
                 <td class="recentsRoomSummaryTS">
                     {{ (room.lastMsg.ts) | date:'MMM d HH:mm' }}