aboutsummaryrefslogtreecommitdiffstats
path: root/shared
diff options
context:
space:
mode:
Diffstat (limited to 'shared')
-rw-r--r--shared/NotifyConfig.js10
-rw-r--r--shared/test_notify_config.js14
2 files changed, 23 insertions, 1 deletions
diff --git a/shared/NotifyConfig.js b/shared/NotifyConfig.js
index 143168f..6fc98e6 100644
--- a/shared/NotifyConfig.js
+++ b/shared/NotifyConfig.js
@@ -71,6 +71,16 @@ function withheld(cfg, n, dnd) {
return dnd && !(n.urgency === "critical" && cfg.dndPassCritical);
}
+// Whether a queued notification's balloon is on screen at `now`: the drawer
+// and snooze withhold everything, then mute and DND, then its own expiry.
+// The balloon shell and the desktop companion both ask this, so they cannot
+// disagree about what is showing.
+function shown(cfg, n, dnd, drawerOpen, snoozeUntil, now) {
+ if (drawerOpen || snoozeUntil > now) return false;
+ if (withheld(cfg, n, dnd)) return false;
+ return n.expires === 0 || now < n.expires;
+}
+
// The file a balloon plays, "" for none: the app's suppress-sound wins, then
// the app's own sound (notifyd resolved its hints), then the urgency's.
function soundFor(cfg, n) {
diff --git a/shared/test_notify_config.js b/shared/test_notify_config.js
index c7bc2cc..4e8db23 100644
--- a/shared/test_notify_config.js
+++ b/shared/test_notify_config.js
@@ -18,7 +18,7 @@ const assert = require("assert");
const src = fs.readFileSync(__dirname + "/NotifyConfig.js", "utf8")
.replace(/^\.pragma library$/m, "");
-const C = new Function(src + "\nreturn { defaults, resolve, withheld, soundFor };")();
+const C = new Function(src + "\nreturn { defaults, resolve, withheld, soundFor, shown };")();
// Nothing, or garbage, is the defaults.
assert.deepStrictEqual(C.resolve(undefined), C.defaults());
@@ -64,4 +64,16 @@ assert.strictEqual(C.soundFor(sc, sn("critical", "/app.oga", true)), "");
// An old daemon publishes neither field.
assert.strictEqual(C.soundFor(sc, { app: "x", urgency: "critical" }), "/c.oga");
+// On screen: the drawer, snooze, mute, DND and expiry, in one check that
+// the balloons and the desktop companion share.
+const live = { app: "ok", urgency: "normal", expires: 0 };
+assert.strictEqual(C.shown(cfg, live, false, false, 0, 5000), true);
+assert.strictEqual(C.shown(cfg, live, false, true, 0, 5000), false); // drawer open
+assert.strictEqual(C.shown(cfg, live, false, false, 6000, 5000), false); // snoozed
+assert.strictEqual(C.shown(cfg, { app: "spam", urgency: "normal", expires: 0 }, false, false, 0, 5000), false);
+assert.strictEqual(C.shown(cfg, live, true, false, 0, 5000), false); // DND
+const timed = { app: "ok", urgency: "normal", expires: 5000 };
+assert.strictEqual(C.shown(cfg, timed, false, false, 0, 4999), true);
+assert.strictEqual(C.shown(cfg, timed, false, false, 0, 5000), false); // expired
+
console.log("ok");