From f60b4fc26866cca7bf14ee8595d1525b90d09e41 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Sat, 25 Feb 2017 09:52:31 +0000 Subject: [PATCH] `auto_away` shouldn't change the user's status if it's set to `dnd` Fixes #620 --- docs/CHANGES.md | 1 + spec/converse.js | 48 +++++++++++++++++++++++++++++++++++++------- src/converse-core.js | 5 +++-- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/docs/CHANGES.md b/docs/CHANGES.md index 0f9e94e5f..8f6b0e7ec 100755 --- a/docs/CHANGES.md +++ b/docs/CHANGES.md @@ -57,6 +57,7 @@ [muc_show_join_leave](https://conversejs.org/docs/html/configuration.html#muc-show-join-leave) - #366 Show the chat room occupant's JID in the tooltip (if you're allowed to see it). [jcbrand] - #610, #785 Add presence priority handling [w3host, jcbrand] +- #620 `auto_away` shouldn't change the user's status if it's set to `dnd`. [jcbrand] - #694 The `notification_option` wasn't being used consistently. [jcbrand] - #745 New config option [priority](https://conversejs.org/docs/html/configuration.html#priority) [jcbrand] - #770 Allow setting contact attrs on chats.open [Ape] diff --git a/spec/converse.js b/spec/converse.js index 8e91549e5..8bfa267f7 100644 --- a/spec/converse.js +++ b/spec/converse.js @@ -96,10 +96,8 @@ _converse.auto_xa = 6; expect(_converse.xmppstatus.getStatus()).toBe('online'); - while (i <= _converse.auto_away) { - _converse.onEverySecond(); - i++; + _converse.onEverySecond(); i++; } expect(_converse.auto_changed_status).toBe(true); @@ -115,10 +113,46 @@ expect(_converse.xmppstatus.getStatus()).toBe('online'); expect(_converse.auto_changed_status).toBe(false); - // Reset values - _converse.auto_away = 0; - _converse.auto_xa = 0; - _converse.auto_changed_status = false; + // Check that it also works for the chat feature + _converse.xmppstatus.setStatus('chat'); + i = 0; + while (i <= _converse.auto_away) { + _converse.onEverySecond(); + i++; + } + expect(_converse.auto_changed_status).toBe(true); + while (i <= _converse.auto_xa) { + expect(_converse.xmppstatus.getStatus()).toBe('away'); + _converse.onEverySecond(); + i++; + } + expect(_converse.xmppstatus.getStatus()).toBe('xa'); + expect(_converse.auto_changed_status).toBe(true); + + _converse.onUserActivity(); + expect(_converse.xmppstatus.getStatus()).toBe('online'); + expect(_converse.auto_changed_status).toBe(false); + + // Check that it doesn't work for 'dnd' + _converse.xmppstatus.setStatus('dnd'); + i = 0; + while (i <= _converse.auto_away) { + _converse.onEverySecond(); + i++; + } + expect(_converse.xmppstatus.getStatus()).toBe('dnd'); + expect(_converse.auto_changed_status).toBe(false); + while (i <= _converse.auto_xa) { + expect(_converse.xmppstatus.getStatus()).toBe('dnd'); + _converse.onEverySecond(); + i++; + } + expect(_converse.xmppstatus.getStatus()).toBe('dnd'); + expect(_converse.auto_changed_status).toBe(false); + + _converse.onUserActivity(); + expect(_converse.xmppstatus.getStatus()).toBe('dnd'); + expect(_converse.auto_changed_status).toBe(false); })); }); diff --git a/src/converse-core.js b/src/converse-core.js index d0ceca473..7c09b3e67 100755 --- a/src/converse-core.js +++ b/src/converse-core.js @@ -350,11 +350,12 @@ } if (_converse.auto_away > 0 && _converse.idle_seconds > _converse.auto_away && - stat !== 'away' && stat !== 'xa') { + stat !== 'away' && stat !== 'xa' && stat !== 'dnd') { _converse.auto_changed_status = true; _converse.xmppstatus.setStatus('away'); } else if (_converse.auto_xa > 0 && - _converse.idle_seconds > _converse.auto_xa && stat !== 'xa') { + _converse.idle_seconds > _converse.auto_xa && + stat !== 'xa' && stat !== 'dnd') { _converse.auto_changed_status = true; _converse.xmppstatus.setStatus('xa'); }