From 5dd1a738f8dcd18176e606249fc461d4197d0d71 Mon Sep 17 00:00:00 2001 From: Emmanuel ROHEE Date: Wed, 3 Sep 2014 18:33:36 +0200 Subject: [PATCH] Use /rooms/$room_id/state/m.room.member/$user_id to change the membership of another user --- webclient/components/matrix/matrix-service.js | 14 +++++++++++++- webclient/room/room-controller.js | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/webclient/components/matrix/matrix-service.js b/webclient/components/matrix/matrix-service.js index a0674d06c..165930fbc 100644 --- a/webclient/components/matrix/matrix-service.js +++ b/webclient/components/matrix/matrix-service.js @@ -165,13 +165,25 @@ angular.module('matrixService', []) // TODO: Use PUT with transaction IDs return doRequest("POST", path, undefined, data); }, + + // Change the membership of an another user + setMembership: function(room_id, user_id, membershipValue) { + // 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, { + membership: membershipValue + }); + }, // Bans a user from from a room ban: function(room_id, user_id, reason) { var path = "/rooms/$room_id/ban/"; path = path.replace("$room_id", encodeURIComponent(room_id)); - return doRequest("PUT", path, undefined, { + return doRequest("POST", path, undefined, { user_id: user_id, reason: reason }); diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js index a26d1c72d..0ffbe8761 100644 --- a/webclient/room/room-controller.js +++ b/webclient/room/room-controller.js @@ -289,7 +289,7 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput']) var user_id = args[1]; // Set his state in the room as leave - promise = matrixService.membershipChange($scope.room_id, user_id, "leave"); + promise = matrixService.setMembership($scope.room_id, user_id, "leave"); } break; @@ -314,7 +314,7 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput']) var user_id = args[1]; // Reset the user membership to leave to unban him - promise = matrixService.membershipChange($scope.room_id, user_id, "leave"); + promise = matrixService.setMembership($scope.room_id, user_id, "leave"); } break;