diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index 526e1091f..b6a0d0fb3 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -1403,8 +1403,19 @@ send_chat_state_notifications * Default: ``true`` -Determines whether chat state notifications (see `XEP-0085 `_) -should be sent out or not. +Determines whether chat state notifications (see `XEP-0085 `_) should be sent out or not. + +Can also be set to an Array in order to allow only certain types of chat state notifications. + +For example: + +.. code-block:: javascript + + converse.initialize({ + 'send_chat_state_notifications': ['composing'] + }); + +Valid values are ``'active', 'composing', 'gone' 'inactive', 'paused'`` show_images_inline ------------------ diff --git a/spec/chatbox.js b/spec/chatbox.js index b83411d49..bb3f042a8 100644 --- a/spec/chatbox.js +++ b/spec/chatbox.js @@ -715,6 +715,30 @@ done(); })); + it("is NOT sent out if send_chat_state_notifications doesn't allow it", + mock.initConverse( + null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'send_chat_state_notifications': []}, + async function (done, _converse) { + + await test_utils.waitForRoster(_converse, 'current'); + test_utils.openControlBox(); + const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit'; + + await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length); + await test_utils.openChatBoxFor(_converse, contact_jid); + var view = _converse.chatboxviews.get(contact_jid); + expect(view.model.get('chat_state')).toBe('active'); + spyOn(_converse.connection, 'send'); + spyOn(_converse.api, "trigger").and.callThrough(); + view.onKeyDown({ + target: view.el.querySelector('textarea.chat-textarea'), + keyCode: 1 + }); + expect(view.model.get('chat_state')).toBe('composing'); + expect(_converse.connection.send).not.toHaveBeenCalled(); + done(); + })); + it("will be shown if received", mock.initConverse( null, ['rosterGroupsFetched'], {}, diff --git a/src/headless/converse-chatboxes.js b/src/headless/converse-chatboxes.js index 4f4f6e0b7..e5844c3ac 100644 --- a/src/headless/converse-chatboxes.js +++ b/src/headless/converse-chatboxes.js @@ -748,6 +748,10 @@ converse.plugins.add('converse-chatboxes', { */ sendChatState () { if (_converse.send_chat_state_notifications && this.get('chat_state')) { + const allowed = _converse.send_chat_state_notifications; + if (Array.isArray(allowed) && !allowed.includes(this.get('chat_state'))) { + return; + } _converse.api.send( $msg({ 'id': _converse.connection.getUniqueId(),