summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmmanuel ROHEE <erohee@amdocs.com>2014-09-03 14:12:56 +0200
committerEmmanuel ROHEE <erohee@amdocs.com>2014-09-03 14:12:56 +0200
commit4b85c5f52ca5a87fa998d70db81d9f158aa90ada (patch)
tree6e7185b8468d36eb31694701e0f3fbab111684ab
parentUpdated feedback api docs and fixed feedback content template bug (diff)
downloadsynapse-4b85c5f52ca5a87fa998d70db81d9f158aa90ada.tar.xz
Added /op $user_id $powerLevel
-rw-r--r--webclient/components/matrix/event-handler-service.js8
-rw-r--r--webclient/components/matrix/matrix-service.js40
-rw-r--r--webclient/room/room-controller.js18
3 files changed, 59 insertions, 7 deletions
diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js
index d6a0600132..908a9fe2b5 100644
--- a/webclient/components/matrix/event-handler-service.js
+++ b/webclient/components/matrix/event-handler-service.js
@@ -32,6 +32,7 @@ angular.module('eventHandlerService', [])
     var MSG_EVENT = "MSG_EVENT";
     var MEMBER_EVENT = "MEMBER_EVENT";
     var PRESENCE_EVENT = "PRESENCE_EVENT";
+    var POWERLEVEL_EVENT = "POWERLEVEL_EVENT";
     var CALL_EVENT = "CALL_EVENT";
 
     var InitialSyncDeferred = $q.defer();
@@ -107,10 +108,8 @@ angular.module('eventHandlerService', [])
     var handlePowerLevels = function(event, isLiveEvent) {
         initRoom(event.room_id);
 
-       $rootScope.events.rooms[event.room_id][event.type] = event;
-
-        //TODO
-        //$rootScope.$broadcast(PRESENCE_EVENT, event, isLiveEvent);
+        $rootScope.events.rooms[event.room_id][event.type] = event;
+        $rootScope.$broadcast(POWERLEVEL_EVENT, event, isLiveEvent);
     };
 
     var handleCallEvent = function(event, isLiveEvent) {
@@ -122,6 +121,7 @@ angular.module('eventHandlerService', [])
         MSG_EVENT: MSG_EVENT,
         MEMBER_EVENT: MEMBER_EVENT,
         PRESENCE_EVENT: PRESENCE_EVENT,
+        POWERLEVEL_EVENT: POWERLEVEL_EVENT,
         CALL_EVENT: CALL_EVENT,
         
     
diff --git a/webclient/components/matrix/matrix-service.js b/webclient/components/matrix/matrix-service.js
index 869c1f731d..bedabe6286 100644
--- a/webclient/components/matrix/matrix-service.js
+++ b/webclient/components/matrix/matrix-service.js
@@ -263,7 +263,7 @@ angular.module('matrixService', [])
 
         // get a list of public rooms on your home server
         publicRooms: function() {
-            var path = "/publicRooms"
+            var path = "/publicRooms";
             return doRequest("GET", path);
         },
         
@@ -319,7 +319,7 @@ angular.module('matrixService', [])
 
         // hit the Identity Server for a 3PID request.
         linkEmail: function(email, clientSecret, sendAttempt) {
-            var path = "/_matrix/identity/api/v1/validate/email/requestToken"
+            var path = "/_matrix/identity/api/v1/validate/email/requestToken";
             var data = "clientSecret="+clientSecret+"&email=" + encodeURIComponent(email)+"&sendAttempt="+sendAttempt;
             var headers = {};
             headers["Content-Type"] = "application/x-www-form-urlencoded";
@@ -520,6 +520,42 @@ angular.module('matrixService', [])
                 }
             }
             return powerLevel;
+        },
+            
+        // 
+        /**
+         * Change 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
+         * @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
+            var room = $rootScope.events.rooms[room_id];
+            if (room && room["m.room.power_levels"]) {
+                var content = angular.copy(room["m.room.power_levels"].content);
+                content[user_id] = powerLevel;
+                
+                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: "Invalied room: " + room_id}});
+            return deferred.promise;
         }
 
     };
diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js
index 13bddc5451..d96241b863 100644
--- a/webclient/room/room-controller.js
+++ b/webclient/room/room-controller.js
@@ -85,6 +85,14 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput'])
             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;
@@ -278,7 +286,6 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput'])
                 case "/ban":
                     // Ban the user id from the room
                     if (2 <= args.length) {
-
                         // TODO: The user may have entered the display name
                         // Need display name -> user_id resolution. Pb: how to manage user with same display names?
                         var user_id = args[1];
@@ -290,6 +297,15 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput'])
                         promise = matrixService.ban($scope.room_id, user_id, reason);
                     }
                     break;
+                    
+                case "/op":
+                    if (3 === args.length) {
+                        var user_id = args[1];
+                        var powerLevel = parseInt(args[2]);
+
+                        promise = matrixService.setUserPowerLevel($scope.room_id, user_id, powerLevel);
+                    }
+                    break;
             }
         }
         else {