Iterate type definitions (#7168) (#7178)

This commit is contained in:
David Baker 2021-11-22 14:22:41 +00:00 committed by GitHub
parent 74fd21c505
commit 855c69edf7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 11 deletions

View file

@ -18,7 +18,7 @@ limitations under the License.
import { MatrixClientPeg } from './MatrixClientPeg'; import { MatrixClientPeg } from './MatrixClientPeg';
import { PushProcessor } from 'matrix-js-sdk/src/pushprocessor'; import { PushProcessor } from 'matrix-js-sdk/src/pushprocessor';
import { NotificationCountType, Room } from "matrix-js-sdk/src/models/room"; import { NotificationCountType, Room } from "matrix-js-sdk/src/models/room";
import { IAnnotatedPushRule, PushRuleKind } from "matrix-js-sdk/src/@types/PushRules"; import { ConditionKind, IPushRule, PushRuleActionName, PushRuleKind } from "matrix-js-sdk/src/@types/PushRules";
export enum RoomNotifState { export enum RoomNotifState {
AllMessagesLoud = 'all_messages_loud', AllMessagesLoud = 'all_messages_loud',
@ -205,14 +205,12 @@ function setRoomNotifsStateUnmuted(roomId: string, newState: RoomNotifState): Pr
return Promise.all(promises); return Promise.all(promises);
} }
function findOverrideMuteRule(roomId: string): IAnnotatedPushRule { function findOverrideMuteRule(roomId: string): IPushRule {
const cli = MatrixClientPeg.get(); const cli = MatrixClientPeg.get();
if (!cli.pushRules || if (!cli?.pushRules?.global?.override) {
!cli.pushRules['global'] ||
!cli.pushRules['global'].override) {
return null; return null;
} }
for (const rule of cli.pushRules['global'].override) { for (const rule of cli.pushRules.global.override) {
if (isRuleForRoom(roomId, rule)) { if (isRuleForRoom(roomId, rule)) {
if (isMuteRule(rule) && rule.enabled) { if (isMuteRule(rule) && rule.enabled) {
return rule; return rule;
@ -222,14 +220,14 @@ function findOverrideMuteRule(roomId: string): IAnnotatedPushRule {
return null; return null;
} }
function isRuleForRoom(roomId: string, rule: IAnnotatedPushRule): boolean { function isRuleForRoom(roomId: string, rule: IPushRule): boolean {
if (rule.conditions.length !== 1) { if (rule.conditions.length !== 1) {
return false; return false;
} }
const cond = rule.conditions[0]; const cond = rule.conditions[0];
return (cond.kind === 'event_match' && cond.key === 'room_id' && cond.pattern === roomId); return (cond.kind === ConditionKind.EventMatch && cond.key === 'room_id' && cond.pattern === roomId);
} }
function isMuteRule(rule: IAnnotatedPushRule): boolean { function isMuteRule(rule: IPushRule): boolean {
return (rule.actions.length === 1 && rule.actions[0] === 'dont_notify'); return (rule.actions.length === 1 && rule.actions[0] === PushRuleActionName.DontNotify);
} }

View file

@ -39,7 +39,7 @@ const PHASE_VERIFIED = 3;
const PHASE_CANCELLED = 4; const PHASE_CANCELLED = 4;
interface IProps extends IDialogProps { interface IProps extends IDialogProps {
verifier: VerificationBase; // TODO types verifier: VerificationBase;
} }
interface IState { interface IState {