summary refs log tree commit diff
path: root/webclient/components
diff options
context:
space:
mode:
Diffstat (limited to 'webclient/components')
-rw-r--r--webclient/components/matrix/event-handler-service.js21
-rw-r--r--webclient/components/matrix/matrix-filter.js15
-rw-r--r--webclient/components/matrix/matrix-service.js55
-rw-r--r--webclient/components/matrix/model-service.js5
4 files changed, 47 insertions, 49 deletions
diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js
index c11391a6da..dc00d83f33 100644
--- a/webclient/components/matrix/event-handler-service.js
+++ b/webclient/components/matrix/event-handler-service.js
@@ -706,6 +706,27 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService
         },
         
         /**
+         * Return the power level of an user in a particular room
+         * @param {String} room_id the room id
+         * @param {String} user_id the user id
+         * @returns {Number} a value between 0 and 10
+         */
+        getUserPowerLevel: function(room_id, user_id) {
+            var powerLevel = 0;
+            var room = $rootScope.events.rooms[room_id];
+            if (room && room["m.room.power_levels"]) {
+                if (user_id in room["m.room.power_levels"].content) {
+                    powerLevel = room["m.room.power_levels"].content[user_id];
+                }
+                else {
+                    // Use the room default user power
+                    powerLevel = room["m.room.power_levels"].content["default"];
+                }
+            }
+            return powerLevel;
+        },
+        
+        /**
          * Return the display name of an user acccording to data already downloaded
          * @param {String} room_id the room id
          * @param {String} user_id the id of the user
diff --git a/webclient/components/matrix/matrix-filter.js b/webclient/components/matrix/matrix-filter.js
index 3d64a569a1..e4b42a2edb 100644
--- a/webclient/components/matrix/matrix-filter.js
+++ b/webclient/components/matrix/matrix-filter.js
@@ -19,23 +19,24 @@
 angular.module('matrixFilter', [])
 
 // Compute the room name according to information we have
-.filter('mRoomName', ['$rootScope', 'matrixService', 'eventHandlerService', function($rootScope, matrixService, eventHandlerService) {
+.filter('mRoomName', ['$rootScope', 'matrixService', 'eventHandlerService', 'modelService', 
+function($rootScope, matrixService, eventHandlerService, modelService) {
     return function(room_id) {
         var roomName;
 
         // If there is an alias, use it
         // TODO: only one alias is managed for now
         var alias = matrixService.getRoomIdToAliasMapping(room_id);
-
-        var room = $rootScope.events.rooms[room_id];
+        var room = modelService.getRoom(room_id).current_room_state;
+        
         if (room) {
             // Get name from room state date
-            var room_name_event = room["m.room.name"];
+            var room_name_event = room.state("m.room.name");
 
             // Determine if it is a public room
             var isPublicRoom = false;
-            if (room["m.room.join_rules"] && room["m.room.join_rules"].content) {
-                isPublicRoom = ("public" === room["m.room.join_rules"].content.join_rule);
+            if (room.state("m.room.join_rules") && room.state("m.room.join_rules").content) {
+                isPublicRoom = ("public" === room.state("m.room.join_rules").content.join_rule);
             }
 
             if (room_name_event) {
@@ -44,7 +45,7 @@ angular.module('matrixFilter', [])
             else if (alias) {
                 roomName = alias;
             }
-            else if (room.members && !isPublicRoom) {    // Do not rename public room
+            else if (room.members.length > 0 && !isPublicRoom) {    // Do not rename public room
             
                 var user_id = matrixService.config().user_id;
                 // Else, build the name from its users
diff --git a/webclient/components/matrix/matrix-service.js b/webclient/components/matrix/matrix-service.js
index 1840cf46c0..d089bf601c 100644
--- a/webclient/components/matrix/matrix-service.js
+++ b/webclient/components/matrix/matrix-service.js
@@ -724,57 +724,30 @@ angular.module('matrixService', [])
             //console.log("looking for roomId for " + alias + "; found: " + roomId);
             return roomId;
         },
-
-        /****** Power levels management ******/
-
-        /**
-         * Return the power level of an user in a particular room
-         * @param {String} room_id the room id
-         * @param {String} user_id the user id
-         * @returns {Number} a value between 0 and 10
-         */
-        getUserPowerLevel: function(room_id, user_id) {
-            var powerLevel = 0;
-            var room = $rootScope.events.rooms[room_id];
-            if (room && room["m.room.power_levels"]) {
-                if (user_id in room["m.room.power_levels"].content) {
-                    powerLevel = room["m.room.power_levels"].content[user_id];
-                }
-                else {
-                    // Use the room default user power
-                    powerLevel = room["m.room.power_levels"].content["default"];
-                }
-            }
-            return powerLevel;
-        },
             
         /**
          * 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
+         * @param {Number} powerLevel The desired power level.
          *    If undefined, the user power level will be reset, ie he will use the default room user power level
+         * @param event The existing m.room.power_levels event if one exists.
          * @returns {promise} an $http promise
          */
-        setUserPowerLevel: function(room_id, user_id, powerLevel) {
-            
-            // 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;
+        setUserPowerLevel: function(room_id, user_id, powerLevel, event) {
+            var content = {};
+            if (event) {
+                // if there is an existing event, copy the content as it contains
+                // the power level values for other members which we do not want
+                // to modify.
+                content = angular.copy(event.content);
+            }
+            content[user_id] = powerLevel;
                 
-                var path = "/rooms/$room_id/state/m.room.power_levels";
-                path = path.replace("$room_id", encodeURIComponent(room_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;
+            return doRequest("PUT", path, undefined, content);
         },
 
         getTurnServer: function() {
diff --git a/webclient/components/matrix/model-service.js b/webclient/components/matrix/model-service.js
index 6167a84c62..26349f1461 100644
--- a/webclient/components/matrix/model-service.js
+++ b/webclient/components/matrix/model-service.js
@@ -89,8 +89,11 @@ angular.module('modelService', [])
         // provided which can just be given the type and it will return the 
         // 0-len event by default.
         state: function state(type, state_key) {
+            if (!type) {
+                return undefined; // event type MUST be specified
+            }
             if (!state_key) {
-                return this.state_events[type];
+                return this.state_events[type]; // treat as 0-len state key
             }
             return this.state_events[type + state_key];
         },