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

This commit is contained in:
JC Brand 2019-08-02 11:34:24 +02:00
parent 550d0ae31b
commit ec85490f1c
3 changed files with 41 additions and 2 deletions

View File

@ -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
------------------

View File

@ -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'], {},

View File

@ -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(),