mirror of
https://github.com/element-hq/element-web
synced 2024-11-27 03:36:07 +03:00
Move the max candidates constant out of the function
This commit is contained in:
parent
c389540522
commit
d802ee0fa2
1 changed files with 5 additions and 2 deletions
|
@ -19,6 +19,10 @@ import MatrixClientPeg from "./MatrixClientPeg";
|
||||||
export const host = "matrix.to";
|
export const host = "matrix.to";
|
||||||
export const baseUrl = `https://${host}`;
|
export const baseUrl = `https://${host}`;
|
||||||
|
|
||||||
|
// The maximum number of servers to pick when working out which servers
|
||||||
|
// to add to permalinks. The servers are appended as ?via=example.org
|
||||||
|
const MAX_SERVER_CANDIDATES = 3;
|
||||||
|
|
||||||
export function makeEventPermalink(roomId, eventId) {
|
export function makeEventPermalink(roomId, eventId) {
|
||||||
const serverCandidates = pickServerCandidates(roomId);
|
const serverCandidates = pickServerCandidates(roomId);
|
||||||
return `${baseUrl}/#/${roomId}/${eventId}?${encodeServerCandidates(serverCandidates)}`;
|
return `${baseUrl}/#/${roomId}/${eventId}?${encodeServerCandidates(serverCandidates)}`;
|
||||||
|
@ -103,11 +107,10 @@ export function pickServerCandidates(roomId) {
|
||||||
if (highestPlUser.powerLevel >= 50) candidates.push(highestPlUser.serverName);
|
if (highestPlUser.powerLevel >= 50) candidates.push(highestPlUser.serverName);
|
||||||
|
|
||||||
const beforePopulation = candidates.length;
|
const beforePopulation = candidates.length;
|
||||||
const maxCandidates = 3;
|
|
||||||
const serversByPopulation = Object.keys(populationMap)
|
const serversByPopulation = Object.keys(populationMap)
|
||||||
.sort((a, b) => populationMap[b] - populationMap[a])
|
.sort((a, b) => populationMap[b] - populationMap[a])
|
||||||
.filter(a => !candidates.includes(a));
|
.filter(a => !candidates.includes(a));
|
||||||
for (let i = beforePopulation; i <= maxCandidates; i++) {
|
for (let i = beforePopulation; i <= MAX_SERVER_CANDIDATES; i++) {
|
||||||
const idx = i - beforePopulation;
|
const idx = i - beforePopulation;
|
||||||
if (idx >= serversByPopulation.length) break;
|
if (idx >= serversByPopulation.length) break;
|
||||||
candidates.push(serversByPopulation[idx]);
|
candidates.push(serversByPopulation[idx]);
|
||||||
|
|
Loading…
Reference in a new issue