Convert CommonJS exports to ES6-compatible exports
We use `export default` begrudgingly here. Ideally we'd use just `export`, though this entire SDK expects things to be exported as a default. Instead of breaking everything, we'll sacrifice our export pattern for a smaller diff - a later commit can always do the default export -> regular export conversion.
This commit is contained in:
parent
0b0fe92b17
commit
344dac4fb9
147 changed files with 649 additions and 620 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright 2016 OpenMarket Ltd
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -16,9 +17,9 @@ limitations under the License.
|
|||
|
||||
'use strict';
|
||||
|
||||
const PushRuleVectorState = require('./PushRuleVectorState');
|
||||
import {PushRuleVectorState} from "./PushRuleVectorState";
|
||||
|
||||
module.exports = {
|
||||
export class ContentRules {
|
||||
/**
|
||||
* Extract the keyword rules from a list of rules, and parse them
|
||||
* into a form which is useful for Vector's UI.
|
||||
|
@ -30,7 +31,7 @@ module.exports = {
|
|||
* externalRules: a list of other keyword rules, with states other than
|
||||
* vectorState
|
||||
*/
|
||||
parseContentRules: function(rulesets) {
|
||||
static parseContentRules(rulesets) {
|
||||
// first categorise the keyword rules in terms of their actions
|
||||
const contentRules = this._categoriseContentRules(rulesets);
|
||||
|
||||
|
@ -79,9 +80,9 @@ module.exports = {
|
|||
externalRules: contentRules.other,
|
||||
};
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_categoriseContentRules: function(rulesets) {
|
||||
static _categoriseContentRules(rulesets) {
|
||||
const contentRules = {on: [], on_but_disabled: [], loud: [], loud_but_disabled: [], other: []};
|
||||
for (const kind in rulesets.global) {
|
||||
for (let i = 0; i < Object.keys(rulesets.global[kind]).length; ++i) {
|
||||
|
@ -116,5 +117,5 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
return contentRules;
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright 2016 OpenMarket Ltd
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -16,14 +17,14 @@ limitations under the License.
|
|||
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
export class NotificationUtils {
|
||||
// Encodes a dictionary of {
|
||||
// "notify": true/false,
|
||||
// "sound": string or undefined,
|
||||
// "highlight: true/false,
|
||||
// }
|
||||
// to a list of push actions.
|
||||
encodeActions: function(action) {
|
||||
static encodeActions(action) {
|
||||
const notify = action.notify;
|
||||
const sound = action.sound;
|
||||
const highlight = action.highlight;
|
||||
|
@ -41,7 +42,7 @@ module.exports = {
|
|||
} else {
|
||||
return ["dont_notify"];
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
// Decode a list of actions to a dictionary of {
|
||||
// "notify": true/false,
|
||||
|
@ -49,7 +50,7 @@ module.exports = {
|
|||
// "highlight: true/false,
|
||||
// }
|
||||
// If the actions couldn't be decoded then returns null.
|
||||
decodeActions: function(actions) {
|
||||
static decodeActions(actions) {
|
||||
let notify = false;
|
||||
let sound = null;
|
||||
let highlight = false;
|
||||
|
@ -85,5 +86,5 @@ module.exports = {
|
|||
result.sound = sound;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright 2016 OpenMarket Ltd
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -16,42 +17,44 @@ limitations under the License.
|
|||
|
||||
'use strict';
|
||||
|
||||
const StandardActions = require('./StandardActions');
|
||||
const NotificationUtils = require('./NotificationUtils');
|
||||
import {StandardActions} from "./StandardActions";
|
||||
import {NotificationUtils} from "./NotificationUtils";
|
||||
|
||||
const states = {
|
||||
/** The push rule is disabled */
|
||||
OFF: "off",
|
||||
export class PushRuleVectorState {
|
||||
// Backwards compatibility (things should probably be using .states instead)
|
||||
static OFF = "off";
|
||||
static ON = "on";
|
||||
static LOUD = "loud";
|
||||
|
||||
/** The user will receive push notification for this rule */
|
||||
ON: "on",
|
||||
|
||||
/** The user will receive push notification for this rule with sound and
|
||||
highlight if this is legitimate */
|
||||
LOUD: "loud",
|
||||
};
|
||||
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Enum for state of a push rule as defined by the Vector UI.
|
||||
* @readonly
|
||||
* @enum {string}
|
||||
*/
|
||||
states: states,
|
||||
static states = {
|
||||
/** The push rule is disabled */
|
||||
OFF: PushRuleVectorState.OFF,
|
||||
|
||||
/** The user will receive push notification for this rule */
|
||||
ON: PushRuleVectorState.ON,
|
||||
|
||||
/** The user will receive push notification for this rule with sound and
|
||||
highlight if this is legitimate */
|
||||
LOUD: PushRuleVectorState.LOUD,
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a PushRuleVectorState to a list of actions
|
||||
*
|
||||
* @return [object] list of push-rule actions
|
||||
*/
|
||||
actionsFor: function(pushRuleVectorState) {
|
||||
if (pushRuleVectorState === this.ON) {
|
||||
static actionsFor(pushRuleVectorState) {
|
||||
if (pushRuleVectorState === PushRuleVectorState.ON) {
|
||||
return StandardActions.ACTION_NOTIFY;
|
||||
} else if (pushRuleVectorState === this.LOUD) {
|
||||
} else if (pushRuleVectorState === PushRuleVectorState.LOUD) {
|
||||
return StandardActions.ACTION_HIGHLIGHT_DEFAULT_SOUND;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a pushrule's actions to a PushRuleVectorState.
|
||||
|
@ -60,7 +63,7 @@ module.exports = {
|
|||
* category or in PushRuleVectorState.LOUD, regardless of its enabled
|
||||
* state. Returns null if it does not match these categories.
|
||||
*/
|
||||
contentRuleVectorStateKind: function(rule) {
|
||||
static contentRuleVectorStateKind(rule) {
|
||||
const decoded = NotificationUtils.decodeActions(rule.actions);
|
||||
|
||||
if (!decoded) {
|
||||
|
@ -78,16 +81,12 @@ module.exports = {
|
|||
let stateKind = null;
|
||||
switch (tweaks) {
|
||||
case 0:
|
||||
stateKind = this.ON;
|
||||
stateKind = PushRuleVectorState.ON;
|
||||
break;
|
||||
case 2:
|
||||
stateKind = this.LOUD;
|
||||
stateKind = PushRuleVectorState.LOUD;
|
||||
break;
|
||||
}
|
||||
return stateKind;
|
||||
},
|
||||
};
|
||||
|
||||
for (const k in states) {
|
||||
module.exports[k] = states[k];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright 2016 OpenMarket Ltd
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -16,16 +17,16 @@ limitations under the License.
|
|||
|
||||
'use strict';
|
||||
|
||||
const NotificationUtils = require('./NotificationUtils');
|
||||
import {NotificationUtils} from "./NotificationUtils";
|
||||
|
||||
const encodeActions = NotificationUtils.encodeActions;
|
||||
|
||||
module.exports = {
|
||||
ACTION_NOTIFY: encodeActions({notify: true}),
|
||||
ACTION_NOTIFY_DEFAULT_SOUND: encodeActions({notify: true, sound: "default"}),
|
||||
ACTION_NOTIFY_RING_SOUND: encodeActions({notify: true, sound: "ring"}),
|
||||
ACTION_HIGHLIGHT: encodeActions({notify: true, highlight: true}),
|
||||
ACTION_HIGHLIGHT_DEFAULT_SOUND: encodeActions({notify: true, sound: "default", highlight: true}),
|
||||
ACTION_DONT_NOTIFY: encodeActions({notify: false}),
|
||||
ACTION_DISABLED: null,
|
||||
};
|
||||
export class StandardActions {
|
||||
static ACTION_NOTIFY = encodeActions({notify: true});
|
||||
static ACTION_NOTIFY_DEFAULT_SOUND = encodeActions({notify: true, sound: "default"});
|
||||
static ACTION_NOTIFY_RING_SOUND = encodeActions({notify: true, sound: "ring"});
|
||||
static ACTION_HIGHLIGHT = encodeActions({notify: true, highlight: true});
|
||||
static ACTION_HIGHLIGHT_DEFAULT_SOUND = encodeActions({notify: true, sound: "default", highlight: true});
|
||||
static ACTION_DONT_NOTIFY = encodeActions({notify: false});
|
||||
static ACTION_DISABLED = null;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright 2016 OpenMarket Ltd
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -17,10 +18,9 @@ limitations under the License.
|
|||
'use strict';
|
||||
|
||||
import { _td } from '../languageHandler';
|
||||
|
||||
const StandardActions = require('./StandardActions');
|
||||
const PushRuleVectorState = require('./PushRuleVectorState');
|
||||
const { decodeActions } = require('./NotificationUtils');
|
||||
import {StandardActions} from "./StandardActions";
|
||||
import {PushRuleVectorState} from "./PushRuleVectorState";
|
||||
import {NotificationUtils} from "./NotificationUtils";
|
||||
|
||||
class VectorPushRuleDefinition {
|
||||
constructor(opts) {
|
||||
|
@ -51,8 +51,8 @@ class VectorPushRuleDefinition {
|
|||
// value: true vs. unspecified for highlight (which defaults to
|
||||
// true, making them equivalent).
|
||||
if (enabled &&
|
||||
JSON.stringify(decodeActions(rule.actions)) ===
|
||||
JSON.stringify(decodeActions(vectorStateToActions))) {
|
||||
JSON.stringify(NotificationUtils.decodeActions(rule.actions)) ===
|
||||
JSON.stringify(NotificationUtils.decodeActions(vectorStateToActions))) {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ class VectorPushRuleDefinition {
|
|||
/**
|
||||
* The descriptions of rules managed by the Vector UI.
|
||||
*/
|
||||
module.exports = {
|
||||
export const VectorPushRulesDefinitions = {
|
||||
// Messages containing user's display name
|
||||
".m.rule.contains_display_name": new VectorPushRuleDefinition({
|
||||
kind: "override",
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright 2016 OpenMarket Ltd
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -16,9 +17,7 @@ limitations under the License.
|
|||
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
NotificationUtils: require('./NotificationUtils'),
|
||||
PushRuleVectorState: require('./PushRuleVectorState'),
|
||||
VectorPushRulesDefinitions: require('./VectorPushRulesDefinitions'),
|
||||
ContentRules: require('./ContentRules'),
|
||||
};
|
||||
export * from "./NotificationUtils";
|
||||
export * from "./PushRuleVectorState";
|
||||
export * from "./VectorPushRulesDefinitions";
|
||||
export * from "./ContentRules";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue