no-op a setBotPower request from the integration manager when the PL is equal to or greater to the requested PL
When configuredpull/21833/head
parent
a51847e50a
commit
3f6f2bcbb3
|
@ -452,7 +452,7 @@ function setBotOptions(event: MessageEvent<any>, roomId: string, userId: string)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setBotPower(event: MessageEvent<any>, roomId: string, userId: string, level: number): void {
|
function setBotPower(event: MessageEvent<any>, roomId: string, userId: string, level: number, ignoreIfGreater?: boolean): void {
|
||||||
if (!(Number.isInteger(level) && level >= 0)) {
|
if (!(Number.isInteger(level) && level >= 0)) {
|
||||||
sendError(event, _t('Power level must be positive integer.'));
|
sendError(event, _t('Power level must be positive integer.'));
|
||||||
return;
|
return;
|
||||||
|
@ -473,6 +473,18 @@ function setBotPower(event: MessageEvent<any>, roomId: string, userId: string, l
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// If the PL is equal to or greater than the requested PL, ignore.
|
||||||
|
if (ignoreIfGreater) {
|
||||||
|
// As per https://matrix.org/docs/spec/client_server/r0.6.0#m-room-power-levels
|
||||||
|
const currentPl = (powerLevels.content.users && powerLevels.content.users[userId]) || powerLevels.content.users_default || 0;
|
||||||
|
|
||||||
|
if (currentPl >= level) {
|
||||||
|
sendResponse(event, {
|
||||||
|
success: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
client.setPowerLevel(roomId, userId, level, powerEvent).then(() => {
|
client.setPowerLevel(roomId, userId, level, powerEvent).then(() => {
|
||||||
sendResponse(event, {
|
sendResponse(event, {
|
||||||
success: true,
|
success: true,
|
||||||
|
@ -678,7 +690,7 @@ const onMessage = function(event: MessageEvent<any>): void {
|
||||||
setBotOptions(event, roomId, userId);
|
setBotOptions(event, roomId, userId);
|
||||||
break;
|
break;
|
||||||
case Action.SetBotPower:
|
case Action.SetBotPower:
|
||||||
setBotPower(event, roomId, userId, event.data.level);
|
setBotPower(event, roomId, userId, event.data.level, event.data.ignoreIfGreater);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.warn("Unhandled postMessage event with action '" + event.data.action +"'");
|
console.warn("Unhandled postMessage event with action '" + event.data.action +"'");
|
||||||
|
|
Loading…
Reference in New Issue