Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
use nesting instead of short-circuited && operator
Browse files Browse the repository at this point in the history
  • Loading branch information
bwindels committed Feb 25, 2019
1 parent b8c6bed commit a7db42c
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/matrix-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down

0 comments on commit a7db42c

Please sign in to comment.