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:
Michael Telatynski 2023-02-24 15:28:40 +00:00 committed by GitHub
parent 4c79ecf141
commit 76b82b4b2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
130 changed files with 603 additions and 603 deletions

View file

@ -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"];