Skip to content

Commit

Permalink
implement experimental no_push push action
Browse files Browse the repository at this point in the history
  • Loading branch information
ara4n committed Sep 19, 2019
1 parent 020f15c commit efe2c6b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ const Notifier = {
_evaluateEvent: function(ev) {
const room = MatrixClientPeg.get().getRoom(ev.getRoomId());
const actions = MatrixClientPeg.get().getPushActionsForEvent(ev);
if (actions && actions.notify) {
if (actions && actions.notify && actions.push) {
if (this.isEnabled()) {
this._displayPopupNotification(ev, room);
}
Expand Down
11 changes: 10 additions & 1 deletion src/notifications/NotificationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.
module.exports = {
// Encodes a dictionary of {
// "notify": true/false,
// "push": true/false,
// "sound": string or undefined,
// "highlight: true/false,
// }
Expand All @@ -27,8 +28,12 @@ module.exports = {
const notify = action.notify;
const sound = action.sound;
const highlight = action.highlight;
const push = action.push;
if (notify) {
const actions = ["notify"];
if (push === false) {
actions.push("dont_push");
}
if (sound) {
actions.push({"set_tweak": "sound", "value": sound});
}
Expand All @@ -45,6 +50,7 @@ module.exports = {

// Decode a list of actions to a dictionary of {
// "notify": true/false,
// "push": true/false,
// "sound": string or undefined,
// "highlight: true/false,
// }
Expand All @@ -53,13 +59,16 @@ module.exports = {
let notify = false;
let sound = null;
let highlight = false;
let push = true;

for (let i = 0; i < actions.length; ++i) {
const action = actions[i];
if (action === "notify") {
notify = true;
} else if (action === "dont_notify") {
notify = false;
} else if (action === "dont_push") {
push = false;
} else if (typeof action === 'object') {
if (action.set_tweak === "sound") {
sound = action.value;
Expand All @@ -80,7 +89,7 @@ module.exports = {
highlight = true;
}

const result = {notify: notify, highlight: highlight};
const result = {notify: notify, highlight: highlight, push: push};
if (sound !== null) {
result.sound = sound;
}
Expand Down

0 comments on commit efe2c6b

Please sign in to comment.