mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Use modelService to access room member power levels rather than RoomController.
This commit is contained in:
parent
974206ebe1
commit
49a1b4262d
@ -41,6 +41,7 @@ angular.module('modelService', [])
|
||||
this.room_id = room_id;
|
||||
this.old_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?
|
||||
};
|
||||
Room.prototype = {
|
||||
@ -125,7 +126,7 @@ angular.module('modelService', [])
|
||||
// normalise power levels: find the max first.
|
||||
var maxPowerLevel = 0;
|
||||
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]);
|
||||
}
|
||||
// set power level f.e room member
|
||||
|
@ -182,14 +182,6 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'a
|
||||
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() {
|
||||
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() {
|
||||
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++) {
|
||||
var chunk = response.data.chunk[i];
|
||||
updateMemberList(chunk);
|
||||
|
||||
// Add his power level
|
||||
updateUserPowerLevel(chunk.user_id);
|
||||
}
|
||||
|
||||
// Arm list timing update timer
|
||||
|
@ -132,12 +132,12 @@
|
||||
ng-click="$parent.goToUserPage(member.id)"
|
||||
ng-src="{{member.avatar_url || 'img/default-profile.png'}}"
|
||||
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"/>
|
||||
<!-- <div class="userPowerLevel" ng-style="{'width': member.powerLevelNorm +'%'}"></div> -->
|
||||
</div>
|
||||
<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 }}
|
||||
<span ng-show="member.last_active_ago" style="color: #aaa">({{ member.last_active_ago + (now - member.last_updated) | duration }})</span>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user