From 00771d88c32b819450c4fbe144aa960d0d7aa58b Mon Sep 17 00:00:00 2001 From: Christian Paul Date: Thu, 18 May 2023 21:18:15 +0200 Subject: [PATCH] Fix #598; setup issues when the bot has PL 0 and room default isn't 0 (#755) * Fix #598 If the bot has PL 0, the bot incorrectly used the default power level. * Create 755.bugfix --- changelog.d/755.bugfix | 1 + src/Bridge.ts | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 changelog.d/755.bugfix diff --git a/changelog.d/755.bugfix b/changelog.d/755.bugfix new file mode 100644 index 00000000..ef783528 --- /dev/null +++ b/changelog.d/755.bugfix @@ -0,0 +1 @@ +Fix setup issues when the bot has PL 0 and room default isn't 0. diff --git a/src/Bridge.ts b/src/Bridge.ts index 1cfd82ee..39a02669 100644 --- a/src/Bridge.ts +++ b/src/Bridge.ts @@ -1143,9 +1143,9 @@ export class Bridge { if (this.config.widgets?.roomSetupWidget?.addOnInvite && event.type === "m.room.power_levels" && event.state_key === "" && !this.connectionManager.isRoomConnected(roomId)) { log.debug(`${roomId} got a new powerlevel change and isn't connected to any connections, testing to see if we should create a setup widget`) const plEvent = new PowerLevelsEvent(event); - const currentPl = plEvent.content.users?.[botUser.userId] || plEvent.defaultUserLevel; - const previousPl = plEvent.previousContent?.users?.[botUser.userId] || plEvent.previousContent?.users_default; - const requiredPl = plEvent.content.events?.["im.vector.modular.widgets"] || plEvent.defaultStateEventLevel; + const currentPl = plEvent.content.users?.[botUser.userId] ?? plEvent.defaultUserLevel; + const previousPl = plEvent.previousContent?.users?.[botUser.userId] ?? plEvent.previousContent?.users_default; + const requiredPl = plEvent.content.events?.["im.vector.modular.widgets"] ?? plEvent.defaultStateEventLevel; if (currentPl !== previousPl && currentPl >= requiredPl) { // PL changed for bot user, check to see if the widget can be created. try {