mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-12-25 21:39:26 -05:00
Added /op $user_id $powerLevel
This commit is contained in:
parent
cd0afb85c4
commit
4b85c5f52c
@ -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,
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user