From a7db42c6cfd43f9ef536274739506858942cf1af Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 25 Feb 2019 16:21:23 +0100 Subject: [PATCH] use nesting instead of short-circuited && operator --- src/matrix-to.js | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/matrix-to.js b/src/matrix-to.js index c814501996..15979000c4 100644 --- a/src/matrix-to.js +++ b/src/matrix-to.js @@ -146,29 +146,31 @@ export class RoomPermalinkCreator { _updateHighestPlUser() { const plEvent = this._room.currentState.getStateEvents("m.room.power_levels", ""); - const content = plEvent && plEvent.getContent(); - if (content) { - const users = content.users; - if (users) { - const entries = Object.entries(users); - const allowedEntries = entries.filter(([userId]) => { - const member = this._room.getMember(userId); - if (!member || member.membership !== "join") { - return false; + if (plEvent) { + const content = plEvent.getContent(); + if (content) { + const users = content.users; + if (users) { + const entries = Object.entries(users); + const allowedEntries = entries.filter(([userId]) => { + const member = this._room.getMember(userId); + if (!member || member.membership !== "join") { + return false; + } + const serverName = getServerName(userId); + return !isHostnameIpAddress(serverName) && + !isHostInRegex(serverName, this._bannedHostsRegexps) && + isHostInRegex(serverName, this._allowedHostsRegexps); + }); + const maxEntry = allowedEntries.reduce((max, entry) => { + return (entry[1] > max[1]) ? entry : max; + }, [null, 0]); + const [userId, powerLevel] = maxEntry; + // object wasn't empty, and max entry wasn't a demotion from the default + if (userId !== null && powerLevel >= 50) { + this._highestPlUserId = userId; + return; } - const serverName = getServerName(userId); - return !isHostnameIpAddress(serverName) && - !isHostInRegex(serverName, this._bannedHostsRegexps) && - isHostInRegex(serverName, this._allowedHostsRegexps); - }); - const maxEntry = allowedEntries.reduce((max, entry) => { - return (entry[1] > max[1]) ? entry : max; - }, [null, 0]); - const [userId, powerLevel] = maxEntry; - // object wasn't empty, and max entry wasn't a demotion from the default - if (userId !== null && powerLevel >= 50) { - this._highestPlUserId = userId; - return; } } }