summary refs log tree commit diff
path: root/webclient/components
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 /webclient/components
parentUpdated feedback api docs and fixed feedback content template bug (diff)
downloadsynapse-4b85c5f52ca5a87fa998d70db81d9f158aa90ada.tar.xz
Added /op $user_id $powerLevel
Diffstat (limited to 'webclient/components')
-rw-r--r--webclient/components/matrix/event-handler-service.js8
-rw-r--r--webclient/components/matrix/matrix-service.js40
2 files changed, 42 insertions, 6 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;
         }
 
     };