diff options
-rw-r--r-- | syweb/webclient/components/matrix/model-service.js | 22 | ||||
-rw-r--r-- | syweb/webclient/room/room-controller.js | 67 | ||||
-rw-r--r-- | syweb/webclient/room/room.html | 4 |
3 files changed, 29 insertions, 64 deletions
diff --git a/syweb/webclient/components/matrix/model-service.js b/syweb/webclient/components/matrix/model-service.js index da71dac436..7d7a61cbf8 100644 --- a/syweb/webclient/components/matrix/model-service.js +++ b/syweb/webclient/components/matrix/model-service.js @@ -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 = { @@ -121,6 +122,25 @@ angular.module('modelService', []) else if (event.type === "m.room.aliases") { setRoomIdToAliasMapping(event.room_id, event.content.aliases[0]); } + else if (event.type === "m.room.power_levels") { + // normalise power levels: find the max first. + var maxPowerLevel = 0; + for (var user_id in event.content) { + 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 + var defaultPowerLevel = event.content.default === undefined ? 0 : event.content.default; + for (var user_id in this.members) { + if (!this.members.hasOwnProperty(user_id)) continue; + var rm = this.members[user_id]; + if (!rm) { + continue; + } + rm.power_level = event.content[user_id] === undefined ? defaultPowerLevel : event.content[user_id]; + rm.power_level_norm = (rm.power_level * 100) / maxPowerLevel; + } + } }, storeStateEvents: function storeState(events) { @@ -140,6 +160,8 @@ angular.module('modelService', []) /***** Room Member Object *****/ var RoomMember = function RoomMember() { this.event = {}; // the m.room.member event representing the RoomMember. + this.power_level_norm = 0; + this.power_level = 0; this.user = undefined; // the User }; diff --git a/syweb/webclient/room/room-controller.js b/syweb/webclient/room/room-controller.js index 67372a804f..83ed595966 100644 --- a/syweb/webclient/room/room-controller.js +++ b/syweb/webclient/room/room-controller.js @@ -15,8 +15,8 @@ limitations under the License. */ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'angular-peity']) -.controller('RoomController', ['$modal', '$filter', '$scope', '$timeout', '$routeParams', '$location', '$rootScope', 'matrixService', 'mPresence', 'eventHandlerService', 'mFileUpload', 'matrixPhoneService', 'MatrixCall', 'modelService', 'recentsService', 'commandsService', - function($modal, $filter, $scope, $timeout, $routeParams, $location, $rootScope, matrixService, mPresence, eventHandlerService, mFileUpload, matrixPhoneService, MatrixCall, modelService, recentsService, commandsService) { +.controller('RoomController', ['$modal', '$filter', '$scope', '$timeout', '$routeParams', '$location', '$rootScope', 'matrixService', 'mPresence', 'eventHandlerService', 'mFileUpload', 'matrixPhoneService', 'MatrixCall', 'modelService', 'recentsService', 'commandsService', 'mUserDisplayNameFilter', + function($modal, $filter, $scope, $timeout, $routeParams, $location, $rootScope, matrixService, mPresence, eventHandlerService, mFileUpload, matrixPhoneService, MatrixCall, modelService, recentsService, commandsService, mUserDisplayNameFilter) { 'use strict'; var MESSAGES_PER_PAGINATION = 30; var THUMBNAIL_SIZE = 320; @@ -162,24 +162,12 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'a $scope.state.waiting_for_joined_event = false; onInit3(); } - else if (event.state_key === $scope.state.user_id && "invite" !== event.membership && "join" !== event.membership) { - var user; - - if ($scope.members[event.user_id]) { - user = $scope.members[event.user_id].displayname; - } - if (user) { - user = user + " (" + event.user_id + ")"; - } - else { - user = event.user_id; - } - + else if (event.state_key === $scope.state.user_id && "invite" !== event.membership && "join" !== event.membership) { if ("ban" === event.membership) { - $scope.state.permission_denied = "You have been banned by " + user; + $scope.state.permission_denied = "You have been banned by " + mUserDisplayNameFilter(event.user_id); } else { - $scope.state.permission_denied = "You have been kicked by " + user; + $scope.state.permission_denied = "You have been kicked by " + mUserDisplayNameFilter(event.user_id); } } else { @@ -194,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; @@ -371,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(); @@ -633,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 diff --git a/syweb/webclient/room/room.html b/syweb/webclient/room/room.html index 17565f879b..ee7c9777a9 100644 --- a/syweb/webclient/room/room.html +++ b/syweb/webclient/room/room.html @@ -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> |