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

Commit 9edb34a

Browse files
authored
Send stable m.policy.rule.* events instead of mjolnir-prefixed unstable ones (#8300)
1 parent a4d3da7 commit 9edb34a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/mjolnir/BanList.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ export const ROOM_RULE_TYPES = [RULE_ROOM, "m.room.rule.room", "org.matrix.mjoln
2929
export const SERVER_RULE_TYPES = [RULE_SERVER, "m.room.rule.server", "org.matrix.mjolnir.rule.server"];
3030
export const ALL_RULE_TYPES = [...USER_RULE_TYPES, ...ROOM_RULE_TYPES, ...SERVER_RULE_TYPES];
3131

32-
export function ruleTypeToStable(rule: string, unstable = true): string {
32+
export function ruleTypeToStable(rule: string): string {
3333
if (USER_RULE_TYPES.includes(rule)) {
34-
return unstable ? USER_RULE_TYPES[USER_RULE_TYPES.length - 1] : RULE_USER;
34+
return RULE_USER;
3535
}
3636
if (ROOM_RULE_TYPES.includes(rule)) {
37-
return unstable ? ROOM_RULE_TYPES[ROOM_RULE_TYPES.length - 1] : RULE_ROOM;
37+
return RULE_ROOM;
3838
}
3939
if (SERVER_RULE_TYPES.includes(rule)) {
40-
return unstable ? SERVER_RULE_TYPES[SERVER_RULE_TYPES.length - 1] : RULE_SERVER;
40+
return RULE_SERVER;
4141
}
4242
return null;
4343
}
@@ -68,19 +68,19 @@ export class BanList {
6868
}
6969

7070
async banEntity(kind: string, entity: string, reason: string): Promise<any> {
71-
await MatrixClientPeg.get().sendStateEvent(this._roomId, ruleTypeToStable(kind, true), {
71+
await MatrixClientPeg.get().sendStateEvent(this._roomId, ruleTypeToStable(kind), {
7272
entity: entity,
7373
reason: reason,
7474
recommendation: recommendationToStable(RECOMMENDATION_BAN, true),
7575
}, "rule:" + entity);
76-
this._rules.push(new ListRule(entity, RECOMMENDATION_BAN, reason, ruleTypeToStable(kind, false)));
76+
this._rules.push(new ListRule(entity, RECOMMENDATION_BAN, reason, ruleTypeToStable(kind)));
7777
}
7878

7979
async unbanEntity(kind: string, entity: string): Promise<any> {
8080
// Empty state event is effectively deleting it.
81-
await MatrixClientPeg.get().sendStateEvent(this._roomId, ruleTypeToStable(kind, true), {}, "rule:" + entity);
81+
await MatrixClientPeg.get().sendStateEvent(this._roomId, ruleTypeToStable(kind), {}, "rule:" + entity);
8282
this._rules = this._rules.filter(r => {
83-
if (r.kind !== ruleTypeToStable(kind, false)) return true;
83+
if (r.kind !== ruleTypeToStable(kind)) return true;
8484
if (r.entity !== entity) return true;
8585
return false; // we just deleted this rule
8686
});
@@ -97,7 +97,7 @@ export class BanList {
9797
for (const ev of events) {
9898
if (!ev.getStateKey()) continue;
9999

100-
const kind = ruleTypeToStable(eventType, false);
100+
const kind = ruleTypeToStable(eventType);
101101

102102
const entity = ev.getContent()['entity'];
103103
const recommendation = ev.getContent()['recommendation'];

0 commit comments

Comments
 (0)