summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmmanuel ROHEE <erohee@amdocs.com>2014-09-03 15:18:57 +0200
committerEmmanuel ROHEE <erohee@amdocs.com>2014-09-03 15:20:09 +0200
commit4c7da89219894ed565992a4209a23ddcbfa42a33 (patch)
treebb654b1a839ff28eb139a3ad248e8257603b10f4
parentAdded /deop $user_id (diff)
downloadsynapse-4c7da89219894ed565992a4209a23ddcbfa42a33.tar.xz
Do not define power level limits in setUserPowerLevel. Update the function to be used as a resetUserPowerLevel
-rw-r--r--webclient/components/matrix/matrix-service.js36
-rw-r--r--webclient/room/room-controller.js2
2 files changed, 3 insertions, 35 deletions
diff --git a/webclient/components/matrix/matrix-service.js b/webclient/components/matrix/matrix-service.js
index eadbb03d9e..6c7f6d366f 100644
--- a/webclient/components/matrix/matrix-service.js
+++ b/webclient/components/matrix/matrix-service.js
@@ -523,20 +523,14 @@ angular.module('matrixService', [])
         },
             
         /**
-         * Change the power level of a user
+         * Change or reset the power level of a user
          * @param {String} room_id the room id
          * @param {String} user_id the user id
          * @param {Number} powerLevel a value between 0 and 10
+         *    If undefined, the user power level will be reset, ie he will use the default room user power level
          * @returns {promise} an $http promise
          */
         setUserPowerLevel: function(room_id, user_id, powerLevel) {
-            // Sanity check
-            if (powerLevel < 0 || 10 < powerLevel) {
-                // Format the error as is it was sent by the server
-                var deferred = $q.defer();
-                deferred.reject({data:{error: "Invalid powerLevel: " + powerLevel}});
-                return deferred.promise;
-            }
             
             // Hack: currently, there is no home server API so do it by hand by updating
             // the current m.room.power_levels of the room and send it to the server
@@ -555,32 +549,6 @@ angular.module('matrixService', [])
             var deferred = $q.defer();
             deferred.reject({data:{error: "Invalid room: " + room_id}});
             return deferred.promise;
-        },
-            
-        /**
-         * reset the power level of a user so that he will use the room default power level
-         * @param {String} room_id the room id
-         * @param {String} user_id the user id
-         * @returns {promise} an $http promise
-         */
-        resetUserPowerLevel: function(room_id, user_id) {
-            // Hack: currently, there is no home server API so do it by hand by updating
-            // the current m.room.power_levels of the room and send it to the server
-            var room = $rootScope.events.rooms[room_id];
-            if (room && room["m.room.power_levels"]) {
-                var content = angular.copy(room["m.room.power_levels"].content);
-                delete content[user_id];
-                
-                var path = "/rooms/$room_id/state/m.room.power_levels";
-                path = path.replace("$room_id", encodeURIComponent(room_id));
-                
-                return doRequest("PUT", path, undefined, content);
-            }
-            
-            // The room does not exist or does not contain power_levels data
-            var deferred = $q.defer();
-            deferred.reject({data:{error: "Invalid room: " + room_id}});
-            return deferred.promise;
         }
 
     };
diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js
index ab8b35961c..77e93e8930 100644
--- a/webclient/room/room-controller.js
+++ b/webclient/room/room-controller.js
@@ -311,7 +311,7 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput'])
                     // Reset the power level of an user
                     if (2 === args.length) {
                         var user_id = args[1];
-                        promise = matrixService.resetUserPowerLevel($scope.room_id, user_id);
+                        promise = matrixService.setUserPowerLevel($scope.room_id, user_id, undefined);
                     }
                     break;
             }