diff options
author | Emmanuel ROHEE <erohee@amdocs.com> | 2014-09-05 17:30:50 +0200 |
---|---|---|
committer | Emmanuel ROHEE <erohee@amdocs.com> | 2014-09-05 17:30:50 +0200 |
commit | 3be615677407a4224202a3ae107762b1f3bc97ac (patch) | |
tree | 8f175e43edbee68065535b44862f3eb6b5abb05e /webclient | |
parent | Added sanity checks in commands (diff) | |
download | synapse-3be615677407a4224202a3ae107762b1f3bc97ac.tar.xz |
Created kick & unban methods in matrixService. Made some factorisation.
Diffstat (limited to 'webclient')
-rw-r--r-- | webclient/components/matrix/matrix-service.js | 32 | ||||
-rw-r--r-- | webclient/room/room-controller.js | 15 |
2 files changed, 24 insertions, 23 deletions
diff --git a/webclient/components/matrix/matrix-service.js b/webclient/components/matrix/matrix-service.js index 18a4841298..8a0223979c 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 39f8635d76..905a0723d8 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]); } } |