Make more code conform to strict null checks (#10219
* Make more code conform to strict null checks * Fix types * Fix tests * Fix remaining test assertions * Iterate PR
This commit is contained in:
parent
4c79ecf141
commit
76b82b4b2b
130 changed files with 603 additions and 603 deletions
|
@ -29,7 +29,7 @@ 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): string {
|
||||
export function ruleTypeToStable(rule: string): string | null {
|
||||
if (USER_RULE_TYPES.includes(rule)) {
|
||||
return RULE_USER;
|
||||
}
|
||||
|
@ -68,9 +68,11 @@ export class BanList {
|
|||
}
|
||||
|
||||
public async banEntity(kind: string, entity: string, reason: string): Promise<any> {
|
||||
const type = ruleTypeToStable(kind);
|
||||
if (!type) return; // unknown rule type
|
||||
await MatrixClientPeg.get().sendStateEvent(
|
||||
this._roomId,
|
||||
ruleTypeToStable(kind),
|
||||
type,
|
||||
{
|
||||
entity: entity,
|
||||
reason: reason,
|
||||
|
@ -78,12 +80,14 @@ export class BanList {
|
|||
},
|
||||
"rule:" + entity,
|
||||
);
|
||||
this._rules.push(new ListRule(entity, RECOMMENDATION_BAN, reason, ruleTypeToStable(kind)));
|
||||
this._rules.push(new ListRule(entity, RECOMMENDATION_BAN, reason, type));
|
||||
}
|
||||
|
||||
public async unbanEntity(kind: string, entity: string): Promise<any> {
|
||||
const type = ruleTypeToStable(kind);
|
||||
if (!type) return; // unknown rule type
|
||||
// Empty state event is effectively deleting it.
|
||||
await MatrixClientPeg.get().sendStateEvent(this._roomId, ruleTypeToStable(kind), {}, "rule:" + entity);
|
||||
await MatrixClientPeg.get().sendStateEvent(this._roomId, type, {}, "rule:" + entity);
|
||||
this._rules = this._rules.filter((r) => {
|
||||
if (r.kind !== ruleTypeToStable(kind)) return true;
|
||||
if (r.entity !== entity) return true;
|
||||
|
@ -103,6 +107,7 @@ export class BanList {
|
|||
if (!ev.getStateKey()) continue;
|
||||
|
||||
const kind = ruleTypeToStable(eventType);
|
||||
if (!kind) continue; // unknown type
|
||||
|
||||
const entity = ev.getContent()["entity"];
|
||||
const recommendation = ev.getContent()["recommendation"];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue