diff --git a/webclient/components/matrix/matrix-service.js b/webclient/components/matrix/matrix-service.js index 18a484129..8a0223979 100644 --- a/webclient/components/matrix/matrix-service.js +++ b/webclient/components/matrix/matrix-service.js @@ -168,23 +168,20 @@ angular.module('matrixService', []) }, // Change the membership of an another user - setMembership: function(room_id, user_id, membershipValue) { - return this.setMembershipObject(room_id, user_id, { - membership : membershipValue - }); - }, - - // Change the membership of an another user - setMembershipObject: function(room_id, user_id, membershipObject) { + setMembership: function(room_id, user_id, membershipValue, reason) { + // The REST path spec var path = "/rooms/$room_id/state/m.room.member/$user_id"; path = path.replace("$room_id", encodeURIComponent(room_id)); path = path.replace("$user_id", user_id); - return doRequest("PUT", path, undefined, membershipObject); + return doRequest("PUT", path, undefined, { + membership : membershipValue, + reason: reason + }); }, - // Bans a user from from a room + // Bans a user from a room ban: function(room_id, user_id, reason) { var path = "/rooms/$room_id/ban"; path = path.replace("$room_id", encodeURIComponent(room_id)); @@ -194,7 +191,20 @@ angular.module('matrixService', []) reason: reason }); }, - + + // Unbans a user in a room + unban: function(room_id, user_id) { + // FIXME: To update when there will be homeserver API for unban + // For now, do an unban by resetting the user membership to "leave" + return this.setMembership(room_id, user_id, "leave"); + }, + + // Kicks a user from a room + kick: function(room_id, user_id, reason) { + // Set the user membership to "leave" to kick him + return this.setMembership(room_id, user_id, "leave", reason); + }, + // Retrieves the room ID corresponding to a room alias resolveRoomAlias:function(room_alias) { var path = "/_matrix/client/api/v1/directory/room/$room_alias"; diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js index 39f8635d7..905a0723d 100644 --- a/webclient/room/room-controller.js +++ b/webclient/room/room-controller.js @@ -325,15 +325,9 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput']) // Kick a user from the room with an optional reason if (args) { var matches = args.match(/^(\S+?)( +(.*))?$/); - if (matches.length === 2) { - promise = matrixService.setMembership($scope.room_id, matches[1], "leave"); + if (matches) { + promise = matrixService.kick($scope.room_id, matches[1], matches[3]); } - else if (matches.length === 4) { - promise = matrixService.setMembershipObject($scope.room_id, matches[1], { - membership: "leave", - reason: matches[3] // TODO: we need to specify resaon in the spec - }); - } } if (!promise) { @@ -357,14 +351,11 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput']) case "/unban": // Unban a user from the room - // FIXME: this feels horribly asymmetrical - why are we banning via RPC - // and unbanning by editing the membership list? - // Why can't we specify a reason? if (args) { var matches = args.match(/^(\S+)$/); if (matches) { // Reset the user membership to "leave" to unban him - promise = matrixService.setMembership($scope.room_id, matches[1], "leave"); + promise = matrixService.unban($scope.room_id, matches[1]); } }