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

Commit

Permalink
Send stable m.policy.rule.* events instead of mjolnir-prefixed unstab…
Browse files Browse the repository at this point in the history
…le ones (#8300)
  • Loading branch information
t3chguy authored Apr 13, 2022
1 parent a4d3da7 commit 9edb34a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/mjolnir/BanList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ export const ROOM_RULE_TYPES = [RULE_ROOM, "m.room.rule.room", "org.matrix.mjoln
export const SERVER_RULE_TYPES = [RULE_SERVER, "m.room.rule.server", "org.matrix.mjolnir.rule.server"];
export const ALL_RULE_TYPES = [...USER_RULE_TYPES, ...ROOM_RULE_TYPES, ...SERVER_RULE_TYPES];

export function ruleTypeToStable(rule: string, unstable = true): string {
export function ruleTypeToStable(rule: string): string {
if (USER_RULE_TYPES.includes(rule)) {
return unstable ? USER_RULE_TYPES[USER_RULE_TYPES.length - 1] : RULE_USER;
return RULE_USER;
}
if (ROOM_RULE_TYPES.includes(rule)) {
return unstable ? ROOM_RULE_TYPES[ROOM_RULE_TYPES.length - 1] : RULE_ROOM;
return RULE_ROOM;
}
if (SERVER_RULE_TYPES.includes(rule)) {
return unstable ? SERVER_RULE_TYPES[SERVER_RULE_TYPES.length - 1] : RULE_SERVER;
return RULE_SERVER;
}
return null;
}
Expand Down Expand Up @@ -68,19 +68,19 @@ export class BanList {
}

async banEntity(kind: string, entity: string, reason: string): Promise<any> {
await MatrixClientPeg.get().sendStateEvent(this._roomId, ruleTypeToStable(kind, true), {
await MatrixClientPeg.get().sendStateEvent(this._roomId, ruleTypeToStable(kind), {
entity: entity,
reason: reason,
recommendation: recommendationToStable(RECOMMENDATION_BAN, true),
}, "rule:" + entity);
this._rules.push(new ListRule(entity, RECOMMENDATION_BAN, reason, ruleTypeToStable(kind, false)));
this._rules.push(new ListRule(entity, RECOMMENDATION_BAN, reason, ruleTypeToStable(kind)));
}

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

const kind = ruleTypeToStable(eventType, false);
const kind = ruleTypeToStable(eventType);

const entity = ev.getContent()['entity'];
const recommendation = ev.getContent()['recommendation'];
Expand Down

0 comments on commit 9edb34a

Please sign in to comment.