summary refs log tree commit diff
path: root/webclient/components
diff options
context:
space:
mode:
authorEmmanuel ROHEE <erohee@amdocs.com>2014-09-02 11:54:11 +0200
committerEmmanuel ROHEE <erohee@amdocs.com>2014-09-02 11:54:35 +0200
commit828101dd5145d462add4900340874ea2147da994 (patch)
tree30c74fce2f819c899afe995674b287bb02ec4db7 /webclient/components
parentEnsure that event source unit tests could cope with get_new_events_for_user()... (diff)
downloadsynapse-828101dd5145d462add4900340874ea2147da994.tar.xz
Represent user power level in a room by a red bar at the bottom of his avatar image. The width of this bar depends on the power level.
Diffstat (limited to 'webclient/components')
-rw-r--r--webclient/components/matrix/event-handler-service.js18
-rw-r--r--webclient/components/matrix/matrix-service.js24
2 files changed, 42 insertions, 0 deletions
diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js
index b6e5c2eaac..f248116914 100644
--- a/webclient/components/matrix/event-handler-service.js
+++ b/webclient/components/matrix/event-handler-service.js
@@ -95,6 +95,15 @@ angular.module('eventHandlerService', [])
         $rootScope.presence[event.content.user_id] = event;
         $rootScope.$broadcast(PRESENCE_EVENT, event, isLiveEvent);
     };
+    
+    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);
+    };
 
     var handleCallEvent = function(event, isLiveEvent) {
         $rootScope.$broadcast(CALL_EVENT, event, isLiveEvent);
@@ -118,8 +127,17 @@ angular.module('eventHandlerService', [])
                 case "m.presence":
                     handlePresence(event, isLiveEvent);
                     break;
+                case 'm.room.ops_levels':
+                case 'm.room.send_event_level':
+                case 'm.room.add_state_level':
+                case 'm.room.join_rules':
+                case 'm.room.power_levels':
+                    handlePowerLevels(event, isLiveEvent);
+                    break;
+
                 default:
                     console.log("Unable to handle event type " + event.type);
+                    console.log(JSON.stringify(event, undefined, 4));
                     break;
             }
             if (event.type.indexOf('m.call.') == 0) {
diff --git a/webclient/components/matrix/matrix-service.js b/webclient/components/matrix/matrix-service.js
index d509c20b0f..2ae55bea9f 100644
--- a/webclient/components/matrix/matrix-service.js
+++ b/webclient/components/matrix/matrix-service.js
@@ -484,6 +484,30 @@ angular.module('matrixService', [])
         
         getRoomIdToAliasMapping: function(roomId) {
             return localStorage.getItem(MAPPING_PREFIX+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;
         }
 
     };