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

Commit

Permalink
strict fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry Archibald committed Mar 6, 2023
1 parent 55bb323 commit 2443dd4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/components/views/settings/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,10 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
} else {
const definition: VectorPushRuleDefinition = VectorPushRulesDefinitions[rule.ruleId];
const actions = definition.vectorStateToActions[checkedState];
// we should not encounter this
if (!rule.rule) {
throw new Error("Unable to update rule without rule_id");
}
await updatePushRuleActions(cli, rule.rule.rule_id, rule.rule.kind, actions);
await updateExistingPushRulesWithActions(cli, definition.syncedRuleIds, actions);
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils/pushRules/monitorSyncedPushRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ const monitorSyncedRule = async (
if (!primaryRule) {
return;
}
const syncedRules: IAnnotatedPushRule[] = definition.syncedRuleIds
const syncedRules: IAnnotatedPushRule[] | undefined = definition.syncedRuleIds
?.map((ruleId) => pushRuleAndKindToAnnotated(pushProcessor.getPushRuleAndKindById(ruleId)))
.filter(Boolean);
.filter((n?: IAnnotatedPushRule): n is IAnnotatedPushRule => Boolean(n));

// no synced rules to manage
if (!syncedRules?.length) {
Expand All @@ -70,7 +70,7 @@ const monitorSyncedRule = async (
};

export const monitorSyncedPushRules = async (
accountDataEvent: MatrixEvent,
accountDataEvent: MatrixEvent | undefined,
matrixClient: MatrixClient,
): Promise<void> => {
if (accountDataEvent?.getType() !== EventType.PushRules) {
Expand Down
11 changes: 8 additions & 3 deletions src/utils/pushRules/updatePushRuleActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export const updatePushRuleActions = async (
}
};

interface PushRuleAndKind {
rule: IPushRule;
kind: PushRuleKind;
}

/**
* Update push rules with given actions
* Where they already exist for current user
Expand All @@ -50,14 +55,14 @@ export const updatePushRuleActions = async (
*/
export const updateExistingPushRulesWithActions = async (
matrixClient: MatrixClient,
ruleIds: IPushRule["rule_id"][],
ruleIds?: IPushRule["rule_id"][],
actions?: PushRuleAction[],
): Promise<void> => {
const pushProcessor = new PushProcessor(matrixClient);

const rules: ReturnType<PushProcessor["getPushRuleAndKindById"]>[] = ruleIds
const rules: PushRuleAndKind[] | undefined = ruleIds
?.map((ruleId) => pushProcessor.getPushRuleAndKindById(ruleId))
.filter(Boolean);
.filter((n: PushRuleAndKind | null): n is PushRuleAndKind => Boolean(n));

if (!rules?.length) {
return;
Expand Down
2 changes: 1 addition & 1 deletion test/components/structures/LoggedInView-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ describe("<LoggedInView />", () => {

mockClient.emit(ClientEvent.AccountData, pushRulesEvent);

// set to match primary rule
// not called
expect(mockClient.setPushRuleActions).not.toHaveBeenCalled();
});
});
Expand Down

0 comments on commit 2443dd4

Please sign in to comment.