summary refs log tree commit diff
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2014-11-17 09:33:22 +0000
committerKegan Dougal <kegan@matrix.org>2014-11-17 09:33:22 +0000
commitfbf800323786c878dbfdeea5d5cc474090d50931 (patch)
treed37f28ece6252080527e63ee36b6b53e5119a61f
parentdo *not* depend on external websites to host our JS - if nothing else, it mak... (diff)
downloadsynapse-fbf800323786c878dbfdeea5d5cc474090d50931.tar.xz
s/eventHandlerService.getUsersCountInRoom/modelService.getUserCountInRoom/g
-rw-r--r--syweb/webclient/components/matrix/event-handler-service.js25
-rw-r--r--syweb/webclient/components/matrix/model-service.js23
-rw-r--r--syweb/webclient/recents/recents-filter.js2
-rw-r--r--syweb/webclient/test/unit/event-handler-service.spec.js42
-rw-r--r--syweb/webclient/test/unit/model-service.spec.js34
5 files changed, 61 insertions, 65 deletions
diff --git a/syweb/webclient/components/matrix/event-handler-service.js b/syweb/webclient/components/matrix/event-handler-service.js
index 8a32d06696..a41aaa5778 100644
--- a/syweb/webclient/components/matrix/event-handler-service.js
+++ b/syweb/webclient/components/matrix/event-handler-service.js
@@ -523,29 +523,8 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
             }
 
             return lastMessage;
-        },
-        
-        /**
-         * 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
-         */
-        getUsersCountInRoom: function(room_id) {
-            var memberCount;
-
-            var room = modelService.getRoom(room_id);
-            memberCount = 0;
-            for (var i in room.current_room_state.members) {
-                if (!room.current_room_state.members.hasOwnProperty(i)) continue;
-
-                var member = room.current_room_state.members[i].event;
-
-                if ("join" === member.content.membership) {
-                    memberCount = memberCount + 1;
-                }
-            }
-
-            return memberCount;
         }
+        
+        
     };
 }]);
diff --git a/syweb/webclient/components/matrix/model-service.js b/syweb/webclient/components/matrix/model-service.js
index b4d59e7324..4f5d888b05 100644
--- a/syweb/webclient/components/matrix/model-service.js
+++ b/syweb/webclient/components/matrix/model-service.js
@@ -284,6 +284,29 @@ angular.module('modelService', [])
                 }
             }
             return powerLevel;
+        },
+        
+        /**
+         * 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
+         */
+        getUserCountInRoom: function(room_id) {
+            var memberCount;
+
+            var room = this.getRoom(room_id);
+            memberCount = 0;
+            for (var i in room.current_room_state.members) {
+                if (!room.current_room_state.members.hasOwnProperty(i)) continue;
+
+                var member = room.current_room_state.members[i].event;
+
+                if ("join" === member.content.membership) {
+                    memberCount = memberCount + 1;
+                }
+            }
+
+            return memberCount;
         }
     
     };
diff --git a/syweb/webclient/recents/recents-filter.js b/syweb/webclient/recents/recents-filter.js
index cfbc6f4bd8..00304f84dc 100644
--- a/syweb/webclient/recents/recents-filter.js
+++ b/syweb/webclient/recents/recents-filter.js
@@ -40,7 +40,7 @@ angular.module('RecentsController')
                 }
                 // Count users here
                 // TODO: Compute it directly in eventHandlerService
-                room.recent.numUsersInRoom = eventHandlerService.getUsersCountInRoom(room_id);
+                room.recent.numUsersInRoom = modelService.getUserCountInRoom(room_id);
 
                 filtered.push(room);
             }
diff --git a/syweb/webclient/test/unit/event-handler-service.spec.js b/syweb/webclient/test/unit/event-handler-service.spec.js
index c17cdb8715..5eb6fe10ab 100644
--- a/syweb/webclient/test/unit/event-handler-service.spec.js
+++ b/syweb/webclient/test/unit/event-handler-service.spec.js
@@ -26,45 +26,5 @@ describe('EventHandlerService', function() {
         scope = $rootScope;
     }));
 
-    it('should be able to get the number of joined users in a room', inject(
-    function(eventHandlerService) {
-        var roomId = "!foo:matrix.org";
-        // set mocked data
-        modelService.getRoom = function(roomId) {
-            return {
-                room_id: roomId,
-                current_room_state: {
-                    members: {
-                        "@adam:matrix.org": {
-                            event: {
-                                content: { membership: "join" },
-                                user_id: "@adam:matrix.org"
-                            }
-                        },
-                        "@beth:matrix.org": {
-                            event: {
-                                content: { membership: "invite" },
-                                user_id: "@beth:matrix.org"
-                            }
-                        },
-                        "@charlie:matrix.org": {
-                            event: {
-                                content: { membership: "join" },
-                                user_id: "@charlie:matrix.org"
-                            }
-                        },
-                        "@danice:matrix.org": {
-                            event: {
-                                content: { membership: "leave" },
-                                user_id: "@danice:matrix.org"
-                            }
-                        }
-                    }
-                }
-            };
-        }
-        
-        var num = eventHandlerService.getUsersCountInRoom(roomId);
-        expect(num).toEqual(2);
-    }));
+    
 });
diff --git a/syweb/webclient/test/unit/model-service.spec.js b/syweb/webclient/test/unit/model-service.spec.js
index 4639a6984c..d92930e2e0 100644
--- a/syweb/webclient/test/unit/model-service.spec.js
+++ b/syweb/webclient/test/unit/model-service.spec.js
@@ -193,4 +193,38 @@ describe('ModelService', function() {
 
         
     }));
+    
+    it('should be able to get the number of joined users in a room', inject(
+    function(modelService) {
+        var roomId = "!foo:matrix.org";
+        // set mocked data
+        var room = modelService.getRoom(roomId);
+        room.current_room_state.storeStateEvent({
+            content: { membership: "join" },
+            user_id: "@adam:matrix.org",
+            state_key: "@adam:matrix.org",
+            type: "m.room.member"
+        });
+        room.current_room_state.storeStateEvent({
+            content: { membership: "invite" },
+            user_id: "@adam:matrix.org",
+            state_key: "@beth:matrix.org",
+            type: "m.room.member"
+        });
+        room.current_room_state.storeStateEvent({
+            content: { membership: "join" },
+            user_id: "@charlie:matrix.org",
+            state_key: "@charlie:matrix.org",
+            type: "m.room.member"
+        });
+        room.current_room_state.storeStateEvent({
+            content: { membership: "leave" },
+            user_id: "@danice:matrix.org",
+            state_key: "@danice:matrix.org",
+            type: "m.room.member"
+        });
+        
+        var num = modelService.getUserCountInRoom(roomId);
+        expect(num).toEqual(2);
+    }));
 });