mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Made users count auto updating. Do show it if the info is not available (ex:user has not joined the room yet)
This commit is contained in:
parent
30bfa911fc
commit
811716592c
@ -48,6 +48,9 @@ angular.module('RecentsController', ['matrixService', 'matrixFilter', 'eventHand
|
|||||||
if ($rootScope.rooms[event.room_id]) {
|
if ($rootScope.rooms[event.room_id]) {
|
||||||
$rootScope.rooms[event.room_id].lastMsg = event;
|
$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) {
|
$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() {
|
$scope.onInit = function() {
|
||||||
// Init recents list only once
|
// 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];
|
$rootScope.rooms[room.room_id].lastMsg = room.messages.chunk[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$rootScope.rooms[room.room_id].numUsersInRoom = getUsersCountInRoom(room.room_id);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// From now, update recents from the stream
|
// From now, update recents from the stream
|
||||||
|
@ -9,7 +9,9 @@
|
|||||||
{{ room.room_id | mRoomName }}
|
{{ room.room_id | mRoomName }}
|
||||||
</td>
|
</td>
|
||||||
<td class="recentsRoomSummaryTS">
|
<td class="recentsRoomSummaryTS">
|
||||||
|
<span ng-show="undefined !== room.numUsersInRoom">
|
||||||
{{ room.numUsersInRoom || '1' }} {{ room.numUsersInRoom == 1 ? 'user' : 'users' }}
|
{{ room.numUsersInRoom || '1' }} {{ room.numUsersInRoom == 1 ? 'user' : 'users' }}
|
||||||
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="recentsRoomSummaryTS">
|
<td class="recentsRoomSummaryTS">
|
||||||
{{ (room.lastMsg.ts) | date:'MMM d HH:mm' }}
|
{{ (room.lastMsg.ts) | date:'MMM d HH:mm' }}
|
||||||
|
Loading…
Reference in New Issue
Block a user