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

Commit

Permalink
Clarify that vectorState is a VectorState
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Jul 13, 2021
1 parent 5b9fca3 commit 0e749e3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
18 changes: 9 additions & 9 deletions src/notifications/ContentRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { PushRuleVectorState, State } from "./PushRuleVectorState";
import { PushRuleVectorState, VectorState } from "./PushRuleVectorState";
import { IAnnotatedPushRule, IPushRules, PushRuleKind } from "matrix-js-sdk/src/@types/PushRules";

export interface IContentRules {
vectorState: State;
vectorState: VectorState;
rules: IAnnotatedPushRule[];
externalRules: IAnnotatedPushRule[];
}
Expand Down Expand Up @@ -58,7 +58,7 @@ export class ContentRules {

if (contentRules.loud.length) {
return {
vectorState: State.Loud,
vectorState: VectorState.Loud,
rules: contentRules.loud,
externalRules: [
...contentRules.loud_but_disabled,
Expand All @@ -69,25 +69,25 @@ export class ContentRules {
};
} else if (contentRules.loud_but_disabled.length) {
return {
vectorState: State.Off,
vectorState: VectorState.Off,
rules: contentRules.loud_but_disabled,
externalRules: [...contentRules.on, ...contentRules.on_but_disabled, ...contentRules.other],
};
} else if (contentRules.on.length) {
return {
vectorState: State.On,
vectorState: VectorState.On,
rules: contentRules.on,
externalRules: [...contentRules.on_but_disabled, ...contentRules.other],
};
} else if (contentRules.on_but_disabled.length) {
return {
vectorState: State.Off,
vectorState: VectorState.Off,
rules: contentRules.on_but_disabled,
externalRules: contentRules.other,
};
} else {
return {
vectorState: State.On,
vectorState: VectorState.On,
rules: [],
externalRules: contentRules.other,
};
Expand Down Expand Up @@ -116,14 +116,14 @@ export class ContentRules {
r.kind = kind;

switch (PushRuleVectorState.contentRuleVectorStateKind(r)) {
case State.On:
case VectorState.On:
if (r.enabled) {
contentRules.on.push(r);
} else {
contentRules.on_but_disabled.push(r);
}
break;
case State.Loud:
case VectorState.Loud:
if (r.enabled) {
contentRules.loud.push(r);
} else {
Expand Down
22 changes: 11 additions & 11 deletions src/notifications/PushRuleVectorState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { StandardActions } from "./StandardActions";
import { NotificationUtils } from "./NotificationUtils";
import { IPushRule } from "matrix-js-sdk/src/@types/PushRules";

export enum State {
export enum VectorState {
/** The push rule is disabled */
Off = "off",
/** The user will receive push notification for this rule */
Expand All @@ -30,26 +30,26 @@ export enum State {

export class PushRuleVectorState {
// Backwards compatibility (things should probably be using the enum above instead)
static OFF = State.Off;
static ON = State.On;
static LOUD = State.Loud;
static OFF = VectorState.Off;
static ON = VectorState.On;
static LOUD = VectorState.Loud;

/**
* Enum for state of a push rule as defined by the Vector UI.
* @readonly
* @enum {string}
*/
static states = State;
static states = VectorState;

/**
* Convert a PushRuleVectorState to a list of actions
*
* @return [object] list of push-rule actions
*/
static actionsFor(pushRuleVectorState: State) {
if (pushRuleVectorState === State.On) {
static actionsFor(pushRuleVectorState: VectorState) {
if (pushRuleVectorState === VectorState.On) {
return StandardActions.ACTION_NOTIFY;
} else if (pushRuleVectorState === State.Loud) {
} else if (pushRuleVectorState === VectorState.Loud) {
return StandardActions.ACTION_HIGHLIGHT_DEFAULT_SOUND;
}
}
Expand All @@ -61,7 +61,7 @@ export class PushRuleVectorState {
* category or in PushRuleVectorState.LOUD, regardless of its enabled
* state. Returns null if it does not match these categories.
*/
static contentRuleVectorStateKind(rule: IPushRule): State {
static contentRuleVectorStateKind(rule: IPushRule): VectorState {
const decoded = NotificationUtils.decodeActions(rule.actions);

if (!decoded) {
Expand All @@ -79,10 +79,10 @@ export class PushRuleVectorState {
let stateKind = null;
switch (tweaks) {
case 0:
stateKind = State.On;
stateKind = VectorState.On;
break;
case 2:
stateKind = State.Loud;
stateKind = VectorState.Loud;
break;
}
return stateKind;
Expand Down

0 comments on commit 0e749e3

Please sign in to comment.