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

Commit

Permalink
Ensure that permalink server candidates can't be duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
robintown committed Apr 17, 2022
1 parent f0e7b64 commit bd8ff17
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/utils/permalinks/Permalinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,27 +238,27 @@ export class RoomPermalinkCreator {
}

private updateServerCandidates = () => {
const candidates = [];
const candidates = new Set<string>();
if (this.highestPlUserId) {
candidates.push(getServerName(this.highestPlUserId));
candidates.add(getServerName(this.highestPlUserId));
}

const serversByPopulation = Object.keys(this.populationMap)
.sort((a, b) => this.populationMap[b] - this.populationMap[a]);

for (let i = 0; i < serversByPopulation.length && candidates.length < MAX_SERVER_CANDIDATES; i++) {
for (let i = 0; i < serversByPopulation.length && candidates.size < MAX_SERVER_CANDIDATES; i++) {
const server = serversByPopulation[i];
if (
!candidates.includes(server) &&
!candidates.has(server) &&
!isHostnameIpAddress(server) &&
!isHostInRegex(server, this.bannedHostsRegexps) &&
isHostInRegex(server, this.allowedHostsRegexps)
) {
candidates.push(server);
candidates.add(server);
}
}

this._serverCandidates = candidates;
this._serverCandidates = [...candidates];
};
}

Expand Down

0 comments on commit bd8ff17

Please sign in to comment.