Browse Source

Allow configuration of which XEP-0095 CSN's may be sent out

JC Brand 6 years ago
parent
commit
ec85490f1c
3 changed files with 41 additions and 2 deletions
  1. 13 2
      docs/source/configuration.rst
  2. 24 0
      spec/chatbox.js
  3. 4 0
      src/headless/converse-chatboxes.js

+ 13 - 2
docs/source/configuration.rst

@@ -1403,8 +1403,19 @@ send_chat_state_notifications
 
 * Default: ``true``
 
-Determines whether chat state notifications (see `XEP-0085 <https://xmpp.org/extensions/xep-0085.html>`_)
-should be sent out or not.
+Determines whether chat state notifications (see `XEP-0085 <https://xmpp.org/extensions/xep-0085.html>`_) 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
 ------------------

+ 24 - 0
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'], {},

+ 4 - 0
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(),