Use modelService to access room member power levels rather than RoomController.

This commit is contained in:
Kegan Dougal 2014-11-14 11:29:50 +00:00
parent 974206ebe1
commit 49a1b4262d
3 changed files with 4 additions and 48 deletions

View File

@ -41,6 +41,7 @@ angular.module('modelService', [])
this.room_id = room_id; this.room_id = room_id;
this.old_room_state = new RoomState(); this.old_room_state = new RoomState();
this.current_room_state = new RoomState(); this.current_room_state = new RoomState();
this.now = this.current_room_state; // makes html access shorter
this.events = []; // events which can be displayed on the UI. TODO move? this.events = []; // events which can be displayed on the UI. TODO move?
}; };
Room.prototype = { Room.prototype = {
@ -125,7 +126,7 @@ angular.module('modelService', [])
// normalise power levels: find the max first. // normalise power levels: find the max first.
var maxPowerLevel = 0; var maxPowerLevel = 0;
for (var user_id in event.content) { for (var user_id in event.content) {
if (!event.content.hasOwnProperty(user_id)) continue; if (!event.content.hasOwnProperty(user_id) || user_id === "hsob_ts") continue; // XXX hsob_ts on some old rooms :(
maxPowerLevel = Math.max(maxPowerLevel, event.content[user_id]); maxPowerLevel = Math.max(maxPowerLevel, event.content[user_id]);
} }
// set power level f.e room member // set power level f.e room member

View File

@ -182,14 +182,6 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'a
updatePresence(event); updatePresence(event);
} }
}); });
$scope.$on(eventHandlerService.POWERLEVEL_EVENT, function(ngEvent, event, isLive) {
if (isLive && event.room_id === $scope.room_id) {
for (var user_id in event.content) {
updateUserPowerLevel(user_id);
}
}
});
$scope.memberCount = function() { $scope.memberCount = function() {
return Object.keys($scope.members).length; return Object.keys($scope.members).length;
@ -359,40 +351,6 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'a
} }
}; };
var updateUserPowerLevel = function(user_id) {
var member = $scope.members[user_id];
if (member) {
member.powerLevel = eventHandlerService.getUserPowerLevel($scope.room_id, user_id);
normaliseMembersPowerLevels();
}
};
// Normalise users power levels so that the user with the higher power level
// will have a bar covering 100% of the width of his avatar
var normaliseMembersPowerLevels = function() {
// Find the max power level
var maxPowerLevel = 0;
for (var i in $scope.members) {
if (!$scope.members.hasOwnProperty(i)) continue;
var member = $scope.members[i];
if (member.powerLevel) {
maxPowerLevel = Math.max(maxPowerLevel, member.powerLevel);
}
}
// Normalized them on a 0..100% scale to be use in css width
if (maxPowerLevel) {
for (var i in $scope.members) {
if (!$scope.members.hasOwnProperty(i)) continue;
var member = $scope.members[i];
member.powerLevelNorm = (member.powerLevel * 100) / maxPowerLevel;
}
}
};
$scope.send = function() { $scope.send = function() {
var input = $('#mainInput').val(); var input = $('#mainInput').val();
@ -621,9 +579,6 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'a
for (var i = 0; i < response.data.chunk.length; i++) { for (var i = 0; i < response.data.chunk.length; i++) {
var chunk = response.data.chunk[i]; var chunk = response.data.chunk[i];
updateMemberList(chunk); updateMemberList(chunk);
// Add his power level
updateUserPowerLevel(chunk.user_id);
} }
// Arm list timing update timer // Arm list timing update timer

View File

@ -132,12 +132,12 @@
ng-click="$parent.goToUserPage(member.id)" ng-click="$parent.goToUserPage(member.id)"
ng-src="{{member.avatar_url || 'img/default-profile.png'}}" ng-src="{{member.avatar_url || 'img/default-profile.png'}}"
alt="{{ member.displayname || member.id.substr(0, member.id.indexOf(':')) }}" alt="{{ member.displayname || member.id.substr(0, member.id.indexOf(':')) }}"
title="{{ member.id }} - power: {{ member.powerLevel }}" title="{{ member.id }} - power: {{ room.now.members[member.id].power_level }}"
width="80" height="80"/> width="80" height="80"/>
<!-- <div class="userPowerLevel" ng-style="{'width': member.powerLevelNorm +'%'}"></div> --> <!-- <div class="userPowerLevel" ng-style="{'width': member.powerLevelNorm +'%'}"></div> -->
</div> </div>
<div class="userName"> <div class="userName">
<pie-chart ng-show="member.powerLevelNorm" data="[ (member.powerLevelNorm + 0), (100 - member.powerLevelNorm) ]"></pie-chart> <pie-chart ng-show="room.now.members[member.id].power_level_norm" data="[ (room.now.members[member.id].power_level_norm + 0), (100 - room.now.members[member.id].power_level_norm) ]"></pie-chart>
{{ member.id | mUserDisplayName:room_id:true }} {{ member.id | mUserDisplayName:room_id:true }}
<span ng-show="member.last_active_ago" style="color: #aaa">({{ member.last_active_ago + (now - member.last_updated) | duration }})</span> <span ng-show="member.last_active_ago" style="color: #aaa">({{ member.last_active_ago + (now - member.last_updated) | duration }})</span>
</div> </div>