Clarify that vectorState is a VectorState

This commit is contained in:
Travis Ralston 2021-07-11 20:53:12 -06:00
parent 5b9fca3b91
commit 0e749e32ac
2 changed files with 20 additions and 20 deletions

View file

@ -14,11 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License. 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"; import { IAnnotatedPushRule, IPushRules, PushRuleKind } from "matrix-js-sdk/src/@types/PushRules";
export interface IContentRules { export interface IContentRules {
vectorState: State; vectorState: VectorState;
rules: IAnnotatedPushRule[]; rules: IAnnotatedPushRule[];
externalRules: IAnnotatedPushRule[]; externalRules: IAnnotatedPushRule[];
} }
@ -58,7 +58,7 @@ export class ContentRules {
if (contentRules.loud.length) { if (contentRules.loud.length) {
return { return {
vectorState: State.Loud, vectorState: VectorState.Loud,
rules: contentRules.loud, rules: contentRules.loud,
externalRules: [ externalRules: [
...contentRules.loud_but_disabled, ...contentRules.loud_but_disabled,
@ -69,25 +69,25 @@ export class ContentRules {
}; };
} else if (contentRules.loud_but_disabled.length) { } else if (contentRules.loud_but_disabled.length) {
return { return {
vectorState: State.Off, vectorState: VectorState.Off,
rules: contentRules.loud_but_disabled, rules: contentRules.loud_but_disabled,
externalRules: [...contentRules.on, ...contentRules.on_but_disabled, ...contentRules.other], externalRules: [...contentRules.on, ...contentRules.on_but_disabled, ...contentRules.other],
}; };
} else if (contentRules.on.length) { } else if (contentRules.on.length) {
return { return {
vectorState: State.On, vectorState: VectorState.On,
rules: contentRules.on, rules: contentRules.on,
externalRules: [...contentRules.on_but_disabled, ...contentRules.other], externalRules: [...contentRules.on_but_disabled, ...contentRules.other],
}; };
} else if (contentRules.on_but_disabled.length) { } else if (contentRules.on_but_disabled.length) {
return { return {
vectorState: State.Off, vectorState: VectorState.Off,
rules: contentRules.on_but_disabled, rules: contentRules.on_but_disabled,
externalRules: contentRules.other, externalRules: contentRules.other,
}; };
} else { } else {
return { return {
vectorState: State.On, vectorState: VectorState.On,
rules: [], rules: [],
externalRules: contentRules.other, externalRules: contentRules.other,
}; };
@ -116,14 +116,14 @@ export class ContentRules {
r.kind = kind; r.kind = kind;
switch (PushRuleVectorState.contentRuleVectorStateKind(r)) { switch (PushRuleVectorState.contentRuleVectorStateKind(r)) {
case State.On: case VectorState.On:
if (r.enabled) { if (r.enabled) {
contentRules.on.push(r); contentRules.on.push(r);
} else { } else {
contentRules.on_but_disabled.push(r); contentRules.on_but_disabled.push(r);
} }
break; break;
case State.Loud: case VectorState.Loud:
if (r.enabled) { if (r.enabled) {
contentRules.loud.push(r); contentRules.loud.push(r);
} else { } else {

View file

@ -18,7 +18,7 @@ import { StandardActions } from "./StandardActions";
import { NotificationUtils } from "./NotificationUtils"; import { NotificationUtils } from "./NotificationUtils";
import { IPushRule } from "matrix-js-sdk/src/@types/PushRules"; import { IPushRule } from "matrix-js-sdk/src/@types/PushRules";
export enum State { export enum VectorState {
/** The push rule is disabled */ /** The push rule is disabled */
Off = "off", Off = "off",
/** The user will receive push notification for this rule */ /** The user will receive push notification for this rule */
@ -30,26 +30,26 @@ export enum State {
export class PushRuleVectorState { export class PushRuleVectorState {
// Backwards compatibility (things should probably be using the enum above instead) // Backwards compatibility (things should probably be using the enum above instead)
static OFF = State.Off; static OFF = VectorState.Off;
static ON = State.On; static ON = VectorState.On;
static LOUD = State.Loud; static LOUD = VectorState.Loud;
/** /**
* Enum for state of a push rule as defined by the Vector UI. * Enum for state of a push rule as defined by the Vector UI.
* @readonly * @readonly
* @enum {string} * @enum {string}
*/ */
static states = State; static states = VectorState;
/** /**
* Convert a PushRuleVectorState to a list of actions * Convert a PushRuleVectorState to a list of actions
* *
* @return [object] list of push-rule actions * @return [object] list of push-rule actions
*/ */
static actionsFor(pushRuleVectorState: State) { static actionsFor(pushRuleVectorState: VectorState) {
if (pushRuleVectorState === State.On) { if (pushRuleVectorState === VectorState.On) {
return StandardActions.ACTION_NOTIFY; return StandardActions.ACTION_NOTIFY;
} else if (pushRuleVectorState === State.Loud) { } else if (pushRuleVectorState === VectorState.Loud) {
return StandardActions.ACTION_HIGHLIGHT_DEFAULT_SOUND; return StandardActions.ACTION_HIGHLIGHT_DEFAULT_SOUND;
} }
} }
@ -61,7 +61,7 @@ export class PushRuleVectorState {
* category or in PushRuleVectorState.LOUD, regardless of its enabled * category or in PushRuleVectorState.LOUD, regardless of its enabled
* state. Returns null if it does not match these categories. * 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); const decoded = NotificationUtils.decodeActions(rule.actions);
if (!decoded) { if (!decoded) {
@ -79,10 +79,10 @@ export class PushRuleVectorState {
let stateKind = null; let stateKind = null;
switch (tweaks) { switch (tweaks) {
case 0: case 0:
stateKind = State.On; stateKind = VectorState.On;
break; break;
case 2: case 2:
stateKind = State.Loud; stateKind = VectorState.Loud;
break; break;
} }
return stateKind; return stateKind;