Get power levels before setting them

This commit is contained in:
Luke Barnard 2016-09-07 17:06:57 +01:00
parent 4bfa57b34e
commit 31d2a819f0

View file

@ -123,7 +123,8 @@ Example:
const SdkConfig = require('./SdkConfig'); const SdkConfig = require('./SdkConfig');
const MatrixClientPeg = require("./MatrixClientPeg"); const MatrixClientPeg = require("./MatrixClientPeg");
var dis = require("./dispatcher"); const MatrixEvent = require("matrix-js-sdk").MatrixEvent;
const dis = require("./dispatcher");
function sendResponse(event, res) { function sendResponse(event, res) {
const data = JSON.parse(JSON.stringify(event.data)); const data = JSON.parse(JSON.stringify(event.data));
@ -201,13 +202,25 @@ function setBotPower(event, roomId, userId, level) {
sendError(event, "You need to be logged in."); sendError(event, "You need to be logged in.");
return; return;
} }
client.setPowerLevel(roomId, userId, level).done(() => {
client.getStateEvent(roomId, "m.room.power_levels", "").then((rawPowerState) => {
console.log(rawPowerState);
let powerEvent = new MatrixEvent(
{
type: "m.room.power_levels",
content: rawPowerState,
}
);
client.setPowerLevel(roomId, userId, level, powerEvent).done(() => {
console.log('Power level has been set');
sendResponse(event, { sendResponse(event, {
success: true, success: true,
}); });
}, (err) => { }, (err) => {
sendError(event, err.message ? err.message : "Failed to send request.", err); sendError(event, err.message ? err.message : "Failed to send request.", err);
}); });
});
} }
function getMembershipState(event, roomId, userId) { function getMembershipState(event, roomId, userId) {