Skip to content

Commit 78e5d4e

Browse files
committed
Remove some redundant legacy code that turned sets to arrays.
I will consult a friend to verify that I am not missing something obvious. Apparently it was probably a result of microsoft/TypeScript#8856
1 parent 2b97f33 commit 78e5d4e

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

src/models/ServerAcl.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ limitations under the License.
2626
*/
2727

2828
import { MatrixGlob } from "matrix-bot-sdk";
29-
import { setToArray } from "../utils";
3029

3130
export interface ServerAclContent {
3231
allow: string[];
@@ -93,15 +92,15 @@ export class ServerAcl {
9392

9493
public literalAclContent(): ServerAclContent {
9594
return {
96-
allow: setToArray(this.allowedServers),
97-
deny: setToArray(this.deniedServers),
95+
allow: [...this.allowedServers],
96+
deny: [...this.deniedServers],
9897
allow_ip_literals: this.allowIps,
9998
};
10099
}
101100

102101
public safeAclContent(): ServerAclContent {
103-
const allowed = setToArray(this.allowedServers);
104-
if (!allowed || allowed.length === 0) {
102+
const allowed = [...this.allowedServers];
103+
if (allowed.length === 0) {
105104
allowed.push("*"); // allow everything
106105
}
107106
if (!allowed.some(server => new MatrixGlob(server).test(this.homeserver))) {
@@ -125,7 +124,7 @@ export class ServerAcl {
125124
let denyMatches = true; // until proven false
126125
let ipsMatch = ips === this.allowIps;
127126

128-
const currentAllowed = setToArray(this.allowedServers);
127+
const currentAllowed = [...this.allowedServers];
129128
if (allow.length === currentAllowed.length) {
130129
for (const s of allow) {
131130
if (!currentAllowed.includes(s)) {
@@ -135,7 +134,7 @@ export class ServerAcl {
135134
}
136135
} else allowMatches = false;
137136

138-
const currentDenied = setToArray(this.deniedServers);
137+
const currentDenied = [...this.deniedServers];
139138
if (deny.length === currentDenied.length) {
140139
for (const s of deny) {
141140
if (!currentDenied.includes(s)) {

src/utils.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,6 @@ export function htmlEscape(input: string): string {
6363
})[char.charCodeAt(0)]);
6464
}
6565

66-
export function setToArray<T>(set: Set<T>): T[] {
67-
const arr: T[] = [];
68-
for (const v of set) {
69-
arr.push(v);
70-
}
71-
return arr;
72-
}
73-
7466
/**
7567
* This increments a prometheus gauge. Used in the Appservice MjolnirManager.
7668
*

0 commit comments

Comments
 (0)