mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-15 00:43:51 +01:00
s/eventHandlerService.getUsersCountInRoom/modelService.getUserCountInRoom/g
This commit is contained in:
parent
4d922a0f9b
commit
fbf8003237
5 changed files with 61 additions and 65 deletions
|
@ -523,29 +523,8 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
|
||||||
}
|
}
|
||||||
|
|
||||||
return lastMessage;
|
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;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -284,6 +284,29 @@ angular.module('modelService', [])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return powerLevel;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -40,7 +40,7 @@ angular.module('RecentsController')
|
||||||
}
|
}
|
||||||
// Count users here
|
// Count users here
|
||||||
// TODO: Compute it directly in eventHandlerService
|
// TODO: Compute it directly in eventHandlerService
|
||||||
room.recent.numUsersInRoom = eventHandlerService.getUsersCountInRoom(room_id);
|
room.recent.numUsersInRoom = modelService.getUserCountInRoom(room_id);
|
||||||
|
|
||||||
filtered.push(room);
|
filtered.push(room);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,45 +26,5 @@ describe('EventHandlerService', function() {
|
||||||
scope = $rootScope;
|
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);
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -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);
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue