Browse Source

Change `muc_show_disconnection_status` to `muc_show_join_leave_status`

JC Brand 6 years ago
parent
commit
7950f7c2ac
5 changed files with 64 additions and 23 deletions
  1. 1 1
      CHANGES.md
  2. 11 10
      docs/source/configuration.rst
  3. 2 0
      spec/messages.js
  4. 47 9
      spec/muc.js
  5. 3 3
      src/converse-muc-views.js

+ 1 - 1
CHANGES.md

@@ -12,7 +12,7 @@
 - Continuously retry (in 2s intervals) to fetch login credentials (via [credentials_url](https://conversejs.org/docs/html/configuration.html#credentials-url)) in case of failure
 - Continuously retry (in 2s intervals) to fetch login credentials (via [credentials_url](https://conversejs.org/docs/html/configuration.html#credentials-url)) in case of failure
 - Replace `moment` with [DayJS](https://github.com/iamkun/dayjs).
 - Replace `moment` with [DayJS](https://github.com/iamkun/dayjs).
 - New API method [\_converse.api.disco.features.get](https://conversejs.org/docs/html/api/-_converse.api.disco.features.html#.get)
 - New API method [\_converse.api.disco.features.get](https://conversejs.org/docs/html/api/-_converse.api.disco.features.html#.get)
-- New config setting [muc_show_disconnection_status](https://conversejs.org/docs/html/configuration.html#muc-show-disconnection-status)
+- New config setting [muc_show_join_leave_status](https://conversejs.org/docs/html/configuration.html#muc-show-join-leave-status)
 - New event: `chatBoxBlurred`.
 - New event: `chatBoxBlurred`.
 - #1296: `embedded` view mode shows `chatbox-navback` arrow in header
 - #1296: `embedded` view mode shows `chatbox-navback` arrow in header
 - #1465: When highlighting a roster contact, they're incorrectly shown as online
 - #1465: When highlighting a roster contact, they're incorrectly shown as online

+ 11 - 10
docs/source/configuration.rst

@@ -1026,16 +1026,6 @@ all MUCs with set autojoin flag in their respective bookmarks will be joined on
 startup of Converse. When set to ``false`` no MUCs are automatically joined based on
 startup of Converse. When set to ``false`` no MUCs are automatically joined based on
 their bookmarks.
 their bookmarks.
 
 
-muc_show_disconnection_status
------------------------------
-
-* Default; ``true``
-
-Determines whether Converse shows the optionally included status message when a
-user leaves the MUC.
-
-See https://xmpp.org/extensions/xep-0045.html#changepres
-
 muc_show_join_leave
 muc_show_join_leave
 -------------------
 -------------------
 
 
@@ -1044,6 +1034,17 @@ muc_show_join_leave
 Determines whether Converse will show info messages inside a chatroom
 Determines whether Converse will show info messages inside a chatroom
 whenever a user joins or leaves it.
 whenever a user joins or leaves it.
 
 
+muc_show_join_leave_status
+--------------------------
+
+* Default; ``true``
+
+Determines whether Converse shows the optionally included status message when a
+user joins or leaves the MUC. This setting only has an effect if
+``muc_show_join_leave`` is set to ``true``.
+
+See https://xmpp.org/extensions/xep-0045.html#changepres
+
 .. _`nickname`:
 .. _`nickname`:
 
 
 nickname
 nickname

+ 2 - 0
spec/messages.js

@@ -2656,6 +2656,8 @@
             });
             });
             await new Promise((resolve, reject) => view.once('messageInserted', resolve));
             await new Promise((resolve, reject) => view.once('messageInserted', resolve));
             expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
             expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
+            expect(view.el.querySelector('.chat-msg .chat-msg__body').textContent.trim())
+                .toBe("But soft, what light through yonder airlock breaks?");
 
 
             const msg_obj = view.model.messages.at(0);
             const msg_obj = view.model.messages.at(0);
             let stanza = u.toStanza(`
             let stanza = u.toStanza(`

+ 47 - 9
spec/muc.js

@@ -855,6 +855,7 @@
                 presence = u.toStanza(
                 presence = u.toStanza(
                     `<presence xmlns="jabber:client" to="dummy@localhost/resource" from="coven@chat.shakespeare.lit/fabio">
                     `<presence xmlns="jabber:client" to="dummy@localhost/resource" from="coven@chat.shakespeare.lit/fabio">
                         <c xmlns="http://jabber.org/protocol/caps" node="http://conversations.im" ver="INI3xjRUioclBTP/aACfWi5m9UY=" hash="sha-1"/>
                         <c xmlns="http://jabber.org/protocol/caps" node="http://conversations.im" ver="INI3xjRUioclBTP/aACfWi5m9UY=" hash="sha-1"/>
+                        <status>Ready for a new day</status>
                         <x xmlns="http://jabber.org/protocol/muc#user">
                         <x xmlns="http://jabber.org/protocol/muc#user">
                             <item affiliation="none" jid="fabio@montefuscolo.com.br/Conversations.ZvLu" role="participant"/>
                             <item affiliation="none" jid="fabio@montefuscolo.com.br/Conversations.ZvLu" role="participant"/>
                         </x>
                         </x>
@@ -862,7 +863,7 @@
                 _converse.connection._dataRecv(test_utils.createRequest(presence));
                 _converse.connection._dataRecv(test_utils.createRequest(presence));
                 expect(sizzle('div.chat-info', chat_content).length).toBe(5);
                 expect(sizzle('div.chat-info', chat_content).length).toBe(5);
                 expect(sizzle('div.chat-info:last', chat_content).pop().textContent).toBe(
                 expect(sizzle('div.chat-info:last', chat_content).pop().textContent).toBe(
-                    `fabio has entered the groupchat`);
+                    `fabio has entered the groupchat. "Ready for a new day"`);
 
 
                 // XXX: hack so that we can test leave/enter of occupants
                 // XXX: hack so that we can test leave/enter of occupants
                 // who were already in the room when we joined.
                 // who were already in the room when we joined.
@@ -905,14 +906,16 @@
                 done();
                 done();
             }));
             }));
 
 
-            it("doesn't show the disconnection status when muc_show_disconnection_status is false",
+            it("doesn't show the disconnection status when muc_show_join_leave_status is false",
                 mock.initConverse(
                 mock.initConverse(
-                    null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'muc_show_disconnection_status': false},
+                    null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'muc_show_join_leave_status': false},
                     async function (done, _converse) {
                     async function (done, _converse) {
 
 
-                await test_utils.openChatRoom(_converse, "coven", 'chat.shakespeare.lit', 'some1');
+                await test_utils.openAndEnterChatRoom(_converse, "coven", 'chat.shakespeare.lit', 'some1');
                 const view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
                 const view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
                 const chat_content = view.el.querySelector('.chat-content');
                 const chat_content = view.el.querySelector('.chat-content');
+                expect(sizzle('div.chat-info', chat_content).pop().textContent).toBe('some1 has entered the groupchat');
+
                 let presence = $pres({
                 let presence = $pres({
                         to: 'dummy@localhost/resource',
                         to: 'dummy@localhost/resource',
                         from: 'coven@chat.shakespeare.lit/newguy'
                         from: 'coven@chat.shakespeare.lit/newguy'
@@ -923,12 +926,13 @@
                         'role': 'participant'
                         'role': 'participant'
                     });
                     });
                 _converse.connection._dataRecv(test_utils.createRequest(presence));
                 _converse.connection._dataRecv(test_utils.createRequest(presence));
-                expect(chat_content.querySelectorAll('div.chat-info').length).toBe(0);
+                expect(chat_content.querySelectorAll('div.chat-info').length).toBe(2);
+                expect(sizzle('div.chat-info', chat_content).pop().textContent).toBe('newguy has entered the groupchat');
 
 
                 presence = $pres({
                 presence = $pres({
                     to: 'dummy@localhost/resource',
                     to: 'dummy@localhost/resource',
-                        type: 'unavailable',
-                        from: 'coven@chat.shakespeare.lit/newguy'
+                    type: 'unavailable',
+                    from: 'coven@chat.shakespeare.lit/newguy'
                     })
                     })
                     .c('status', 'Disconnected: Replaced by new connection').up()
                     .c('status', 'Disconnected: Replaced by new connection').up()
                     .c('x', {xmlns: Strophe.NS.MUC_USER})
                     .c('x', {xmlns: Strophe.NS.MUC_USER})
@@ -938,8 +942,42 @@
                             'role': 'none'
                             'role': 'none'
                         });
                         });
                 _converse.connection._dataRecv(test_utils.createRequest(presence));
                 _converse.connection._dataRecv(test_utils.createRequest(presence));
-                expect(chat_content.querySelectorAll('div.chat-info').length).toBe(1);
-                expect(sizzle('div.chat-info', chat_content).pop().textContent).toBe('newguy has left the groupchat');
+                expect(chat_content.querySelectorAll('div.chat-info').length).toBe(2);
+                expect(sizzle('div.chat-info', chat_content).pop().textContent).toBe('newguy has entered and left the groupchat');
+
+                presence = u.toStanza(
+                    `<presence xmlns="jabber:client" to="dummy@localhost/resource" from="coven@chat.shakespeare.lit/fabio">
+                        <c xmlns="http://jabber.org/protocol/caps" node="http://conversations.im" ver="INI3xjRUioclBTP/aACfWi5m9UY=" hash="sha-1"/>
+                        <status>Ready for a new day</status>
+                        <x xmlns="http://jabber.org/protocol/muc#user">
+                            <item affiliation="none" jid="fabio@montefuscolo.com.br/Conversations.ZvLu" role="participant"/>
+                        </x>
+                    </presence>`);
+                _converse.connection._dataRecv(test_utils.createRequest(presence));
+
+                expect(sizzle('div.chat-info:last', chat_content).pop().textContent).toBe(`fabio has entered the groupchat`);
+
+                presence = u.toStanza(
+                    `<presence xmlns="jabber:client" to="dummy@localhost/resource" from="coven@chat.shakespeare.lit/Dele Olajide">
+                        <x xmlns="http://jabber.org/protocol/muc#user">
+                            <item affiliation="none" jid="deleo@traderlynk.4ng.net/converse.js-39320524" role="participant"/>
+                        </x>
+                    </presence>`);
+                _converse.connection._dataRecv(test_utils.createRequest(presence));
+                expect(sizzle('div.chat-info', chat_content).length).toBe(4);
+                expect(sizzle('div.chat-info:last', chat_content).pop().textContent).toBe("Dele Olajide has entered the groupchat");
+                await test_utils.sendMessage(view, 'hello world');
+
+                presence = u.toStanza(
+                    `<presence xmlns="jabber:client" to="dummy@localhost/resource" type="unavailable" from="coven@chat.shakespeare.lit/Dele Olajide">
+                        <status>Gotta go!</status>
+                        <x xmlns="http://jabber.org/protocol/muc#user">
+                            <item affiliation="none" jid="deleo@traderlynk.4ng.net/converse.js-74567907" role="none"/>
+                        </x>
+                    </presence>`);
+                _converse.connection._dataRecv(test_utils.createRequest(presence));
+                expect(sizzle('div.chat-info', chat_content).length).toBe(5);
+                expect(sizzle('div.chat-info:last', chat_content).pop().textContent).toBe(`Dele Olajide has left the groupchat`);
                 done();
                 done();
             }));
             }));
 
 

+ 3 - 3
src/converse-muc-views.js

@@ -117,8 +117,8 @@ converse.plugins.add('converse-muc-views', {
             'locked_muc_nickname': false,
             'locked_muc_nickname': false,
             'muc_disable_slash_commands': false,
             'muc_disable_slash_commands': false,
             'muc_domain': undefined,
             'muc_domain': undefined,
-            'muc_show_disconnection_status': true,
             'muc_show_join_leave': true,
             'muc_show_join_leave': true,
+            'muc_show_join_leave_status': true,
             'roomconfig_whitelist': [],
             'roomconfig_whitelist': [],
             'visible_toolbar_buttons': {
             'visible_toolbar_buttons': {
                 'toggle_occupants': true
                 'toggle_occupants': true
@@ -1597,7 +1597,7 @@ converse.plugins.add('converse-muc-views', {
                     return;
                     return;
                 }
                 }
                 const nick = occupant.get('nick'),
                 const nick = occupant.get('nick'),
-                      stat = occupant.get('status'),
+                      stat = _converse.muc_show_join_leave_status ? occupant.get('status') : null,
                       prev_info_el = this.getPreviousJoinOrLeaveNotification(this.content.lastElementChild, nick),
                       prev_info_el = this.getPreviousJoinOrLeaveNotification(this.content.lastElementChild, nick),
                       data = _.get(prev_info_el, 'dataset', {});
                       data = _.get(prev_info_el, 'dataset', {});
 
 
@@ -1652,7 +1652,7 @@ converse.plugins.add('converse-muc-views', {
                     return;
                     return;
                 }
                 }
                 const nick = occupant.get('nick'),
                 const nick = occupant.get('nick'),
-                      stat = _converse.muc_show_disconnection_status ? occupant.get('status') : null,
+                      stat = _converse.muc_show_join_leave_status ? occupant.get('status') : null,
                       prev_info_el = this.getPreviousJoinOrLeaveNotification(this.content.lastElementChild, nick),
                       prev_info_el = this.getPreviousJoinOrLeaveNotification(this.content.lastElementChild, nick),
                       dataset = _.get(prev_info_el, 'dataset', {});
                       dataset = _.get(prev_info_el, 'dataset', {});