Commit 9f290dab authored by JC Brand's avatar JC Brand

New config setting `locked_muc_nickname`

When set, the "Nickname" field won't be shown in the "Add groupchat"
modal and instead the nickname will be automatically set (based on other
config settings).
parent 32f0eb54
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
- Don't send out receipts or markers for MAM messages - Don't send out receipts or markers for MAM messages
- Allow setting of debug mode via URL with `/#converse?debug=true` - Allow setting of debug mode via URL with `/#converse?debug=true`
- New config setting [locked_muc_domain](https://conversejs.org/docs/html/configuration.html#locked-muc-domain) - New config setting [locked_muc_domain](https://conversejs.org/docs/html/configuration.html#locked-muc-domain)
- New config setting [locked_muc_nickname](https://conversejs.org/docs/html/configuration.html#locked-muc-nickname)
- New config setting [show_client_info](https://conversejs.org/docs/html/configuration.html#show-client-info) - New config setting [show_client_info](https://conversejs.org/docs/html/configuration.html#show-client-info)
- Render inline images served over HTTP if Converse itself was loaded on an unsecured (HTTP) page. - Render inline images served over HTTP if Converse itself was loaded on an unsecured (HTTP) page.
- Document new API method [sendMessage](https://conversejs.org/docs/html/api/-_converse.ChatBox.html#sendMessage) - Document new API method [sendMessage](https://conversejs.org/docs/html/api/-_converse.ChatBox.html#sendMessage)
......
...@@ -53797,7 +53797,8 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins ...@@ -53797,7 +53797,8 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins
'auto_list_rooms': false, 'auto_list_rooms': false,
'muc_disable_moderator_commands': false, 'muc_disable_moderator_commands': false,
'muc_domain': undefined, 'muc_domain': undefined,
'locked_muc_domain': undefined, 'locked_muc_nickname': false,
'locked_muc_domain': false,
'muc_show_join_leave': true, 'muc_show_join_leave': true,
'roomconfig_whitelist': [], 'roomconfig_whitelist': [],
'visible_toolbar_buttons': { 'visible_toolbar_buttons': {
...@@ -54129,9 +54130,21 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins ...@@ -54129,9 +54130,21 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins
const data = new FormData(form); const data = new FormData(form);
const jid = data.get('chatroom'); const jid = data.get('chatroom');
this.model.save('muc_domain', Strophe.getDomainFromJid(jid)); this.model.save('muc_domain', Strophe.getDomainFromJid(jid));
let nick;
if (_converse.locked_muc_nickname) {
nick = _converse.getDefaultMUCNickname();
if (!nick) {
throw new Error("Using locked_muc_nickname but no nickname found!");
}
} else {
nick = data.get('nickname').trim();
}
return { return {
'jid': jid, 'jid': jid,
'nick': data.get('nickname').trim() 'nick': nick
}; };
}, },
...@@ -66641,8 +66654,10 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc ...@@ -66641,8 +66654,10 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
_converse.router.route('converse/room?jid=:jid', openRoom); _converse.router.route('converse/room?jid=:jid', openRoom);
_converse.getDefaultMUCNickname = function () { _converse.getDefaultMUCNickname = function () {
// XXX: if anything changes here, update the docs for the
// locked_muc_nickname setting.
if (!_converse.xmppstatus) { if (!_converse.xmppstatus) {
throw new Error("Can't call _converse.getNickname before the statusInitialized has been fired."); throw new Error("Can't call _converse.getDefaultMUCNickname before the statusInitialized has been fired.");
} }
const nick = _converse.nickname || _converse.xmppstatus.vcard.get('nickname'); const nick = _converse.nickname || _converse.xmppstatus.vcard.get('nickname');
...@@ -92534,20 +92549,25 @@ var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*global define ...@@ -92534,20 +92549,25 @@ var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*global define
var _ = {escape:__webpack_require__(/*! ./node_modules/lodash/escape.js */ "./node_modules/lodash/escape.js")}; var _ = {escape:__webpack_require__(/*! ./node_modules/lodash/escape.js */ "./node_modules/lodash/escape.js")};
module.exports = function(o) { module.exports = function(o) {
var __t, __p = '', __e = _.escape; var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
function print() { __p += __j.call(arguments, '') }
__p += '<!-- src/templates/add_chatroom_modal.html -->\n<div class="modal fade" id="add-chatroom-modal" tabindex="-1" role="dialog" aria-labelledby="add-chatroom-modal-label" aria-hidden="true">\n <div class="modal-dialog" role="document">\n <div class="modal-content">\n <div class="modal-header">\n <h5 class="modal-title"\n id="add-chatroom-modal-label">' + __p += '<!-- src/templates/add_chatroom_modal.html -->\n<div class="modal fade" id="add-chatroom-modal" tabindex="-1" role="dialog" aria-labelledby="add-chatroom-modal-label" aria-hidden="true">\n <div class="modal-dialog" role="document">\n <div class="modal-content">\n <div class="modal-header">\n <h5 class="modal-title"\n id="add-chatroom-modal-label">' +
__e(o.__('Enter a new Groupchat')) + __e(o.__('Enter a new Groupchat')) +
'</h5>\n <button type="button" class="close" data-dismiss="modal" aria-label="Close">\n <span aria-hidden="true">×</span>\n </button>\n </div>\n <div class="modal-body">\n <form class="converse-form add-chatroom">\n <div class="form-group">\n <label for="chatroom">' + '</h5>\n <button type="button" class="close" data-dismiss="modal" aria-label="Close">\n <span aria-hidden="true">×</span>\n </button>\n </div>\n <div class="modal-body">\n <form class="converse-form add-chatroom">\n <div class="form-group">\n <label for="chatroom">' +
__e(o.label_room_address) + __e(o.label_room_address) +
':</label>\n <input type="text" required="required" name="chatroom" class="form-control" placeholder="' + ':</label>\n <input type="text" required="required" name="chatroom" class="form-control" placeholder="' +
__e(o.chatroom_placeholder) + __e(o.chatroom_placeholder) +
'"/>\n </div>\n <div class="form-group" >\n <label for="nickname">' + '"/>\n </div>\n ';
if (!o._converse.locked_muc_nickname) { ;
__p += '\n <div class="form-group" >\n <label for="nickname">' +
__e(o.__('Nickname')) + __e(o.__('Nickname')) +
':</label>\n <input type="text" pattern=".*\\S+.*" title="' + ':</label>\n <input type="text" pattern=".*\\S+.*" title="' +
__e(o.__('This field is required')) + __e(o.__('This field is required')) +
'" required="required" name="nickname" value="' + '" required="required" name="nickname" value="' +
__e(o.nick) + __e(o.nick) +
'" class="form-control"/>\n </div>\n <input type="submit" class="btn btn-primary" name="join" value="' + '" class="form-control"/>\n </div>\n ';
} ;
__p += '\n <input type="submit" class="btn btn-primary" name="join" value="' +
__e(o.__('Join')) + __e(o.__('Join')) +
'"/>\n </form>\n </div>\n </div>\n </div>\n</div>\n'; '"/>\n </form>\n </div>\n </div>\n </div>\n</div>\n';
return __p return __p
...@@ -886,6 +886,22 @@ locked_muc_domain ...@@ -886,6 +886,22 @@ locked_muc_domain
This setting allows you to restrict the multi-user chat (MUC) domain to only the value This setting allows you to restrict the multi-user chat (MUC) domain to only the value
specified in `muc_domain`_. specified in `muc_domain`_.
locked_muc_nickname
-------------------
* Default: ``false``
This setting allows you to restrict the multi-user chat (MUC) nickname that a
user uses to a particular value.
Where the nickname value comes from depends on other settings.
The `nickname`_ configuration setting takes precedence ahead of any other
nickname value. If that's not set, then the "nickname" value from the user's
VCard is taken, and if that is not set but `muc_nickname_from_jid`_ is set to
``true``, then the node of the user's JID (the part before the ``@``) is used.
If no nickame value is found, then an error will be raised.
message_archiving message_archiving
----------------- -----------------
...@@ -1042,8 +1058,8 @@ This setting allows you to specify the nickname for the current user. ...@@ -1042,8 +1058,8 @@ This setting allows you to specify the nickname for the current user.
The nickname will be included in presence requests to other users and will also The nickname will be included in presence requests to other users and will also
be used as the default nickname when entering MUC chatrooms. be used as the default nickname when entering MUC chatrooms.
This value will have first preference (i.e. used instead of any other nickname source, This value will have first preference ahead of other nickname sources, such as
such as the VCard `nickname` value). the VCard `nickname` value.
notify_all_room_messages notify_all_room_messages
......
...@@ -28,11 +28,6 @@ ...@@ -28,11 +28,6 @@
expect(u.isVisible(_converse.chatboxviews.get('leisure@localhost').el)).toBeTruthy(); expect(u.isVisible(_converse.chatboxviews.get('leisure@localhost').el)).toBeTruthy();
expect(u.isVisible(_converse.chatboxviews.get('news@localhost').el)).toBeTruthy(); expect(u.isVisible(_converse.chatboxviews.get('news@localhost').el)).toBeTruthy();
// XXX: bit of a cheat here. We want `cleanup()` to be
// called on the room. Either it's this or faking
// `sendPresence`.
_converse.connection.connected = false;
_converse.api.roomviews.close('lounge@localhost'); _converse.api.roomviews.close('lounge@localhost');
expect(_converse.chatboxviews.get('lounge@localhost')).toBeUndefined(); expect(_converse.chatboxviews.get('lounge@localhost')).toBeUndefined();
expect(u.isVisible(_converse.chatboxviews.get('leisure@localhost').el)).toBeTruthy(); expect(u.isVisible(_converse.chatboxviews.get('leisure@localhost').el)).toBeTruthy();
...@@ -3994,6 +3989,29 @@ ...@@ -3994,6 +3989,29 @@
done(); done();
})); }));
it("doesn't show the nickname field if locked_muc_nickname is true",
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'locked_muc_nickname': true, 'muc_nickname_from_jid': true},
async function (done, _converse) {
test_utils.openControlBox();
await test_utils.waitForRoster(_converse, 'current', 0);
const roomspanel = _converse.chatboxviews.get('controlbox').roomspanel;
roomspanel.el.querySelector('.show-add-muc-modal').click();
test_utils.closeControlBox(_converse);
const modal = roomspanel.add_room_modal;
await test_utils.waitUntil(() => u.isVisible(modal.el), 1000)
const name_input = modal.el.querySelector('input[name="chatroom"]');
name_input.value = 'lounge@localhost';
expect(modal.el.querySelector('label[for="nickname"]')).toBe(null);
expect(modal.el.querySelector('input[name="nickname"]')).toBe(null);
modal.el.querySelector('form input[type="submit"]').click();
await test_utils.waitUntil(() => _converse.chatboxes.length > 1);
const chatroom = _converse.chatboxes.get('lounge@localhost');
expect(chatroom.get('nick')).toBe('dummy');
done();
}));
it("uses the JID node if muc_nickname_from_jid is set to true", it("uses the JID node if muc_nickname_from_jid is set to true",
mock.initConverse( mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'muc_nickname_from_jid': true}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'muc_nickname_from_jid': true},
...@@ -4013,7 +4031,6 @@ ...@@ -4013,7 +4031,6 @@
done(); done();
})); }));
it("uses the nickname passed in to converse.initialize", it("uses the nickname passed in to converse.initialize",
mock.initConverse( mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'nickname': 'st.nick'}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'nickname': 'st.nick'},
......
...@@ -104,7 +104,8 @@ converse.plugins.add('converse-muc-views', { ...@@ -104,7 +104,8 @@ converse.plugins.add('converse-muc-views', {
'auto_list_rooms': false, 'auto_list_rooms': false,
'muc_disable_moderator_commands': false, 'muc_disable_moderator_commands': false,
'muc_domain': undefined, 'muc_domain': undefined,
'locked_muc_domain': undefined, 'locked_muc_nickname': false,
'locked_muc_domain': false,
'muc_show_join_leave': true, 'muc_show_join_leave': true,
'roomconfig_whitelist': [], 'roomconfig_whitelist': [],
'visible_toolbar_buttons': { 'visible_toolbar_buttons': {
...@@ -429,9 +430,18 @@ converse.plugins.add('converse-muc-views', { ...@@ -429,9 +430,18 @@ converse.plugins.add('converse-muc-views', {
const data = new FormData(form); const data = new FormData(form);
const jid = data.get('chatroom'); const jid = data.get('chatroom');
this.model.save('muc_domain', Strophe.getDomainFromJid(jid)); this.model.save('muc_domain', Strophe.getDomainFromJid(jid));
let nick;
if (_converse.locked_muc_nickname) {
nick = _converse.getDefaultMUCNickname();
if (!nick) {
throw new Error("Using locked_muc_nickname but no nickname found!");
}
} else {
nick = data.get('nickname').trim();
}
return { return {
'jid': jid, 'jid': jid,
'nick': data.get('nickname').trim() 'nick': nick
} }
}, },
......
...@@ -141,8 +141,11 @@ converse.plugins.add('converse-muc', { ...@@ -141,8 +141,11 @@ converse.plugins.add('converse-muc', {
_converse.getDefaultMUCNickname = function () { _converse.getDefaultMUCNickname = function () {
// XXX: if anything changes here, update the docs for the
// locked_muc_nickname setting.
if (!_converse.xmppstatus) { if (!_converse.xmppstatus) {
throw new Error("Can't call _converse.getNickname before the statusInitialized has been fired."); throw new Error(
"Can't call _converse.getDefaultMUCNickname before the statusInitialized has been fired.");
} }
const nick = _converse.nickname || _converse.xmppstatus.vcard.get('nickname'); const nick = _converse.nickname || _converse.xmppstatus.vcard.get('nickname');
if (nick) { if (nick) {
......
...@@ -14,10 +14,12 @@ ...@@ -14,10 +14,12 @@
<label for="chatroom">{{{o.label_room_address}}}:</label> <label for="chatroom">{{{o.label_room_address}}}:</label>
<input type="text" required="required" name="chatroom" class="form-control" placeholder="{{{o.chatroom_placeholder}}}"/> <input type="text" required="required" name="chatroom" class="form-control" placeholder="{{{o.chatroom_placeholder}}}"/>
</div> </div>
{[ if (!o._converse.locked_muc_nickname) { ]}
<div class="form-group" > <div class="form-group" >
<label for="nickname">{{{o.__('Nickname')}}}:</label> <label for="nickname">{{{o.__('Nickname')}}}:</label>
<input type="text" pattern=".*\S+.*" title="{{{o.__('This field is required')}}}" required="required" name="nickname" value="{{{o.nick}}}" class="form-control"/> <input type="text" pattern=".*\S+.*" title="{{{o.__('This field is required')}}}" required="required" name="nickname" value="{{{o.nick}}}" class="form-control"/>
</div> </div>
{[ } ]}
<input type="submit" class="btn btn-primary" name="join" value="{{{o.__('Join')}}}"/> <input type="submit" class="btn btn-primary" name="join" value="{{{o.__('Join')}}}"/>
</form> </form>
</div> </div>
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
<link rel="shortcut icon" type="image/png" href="../node_modules/jasmine-core/images/jasmine_favicon.png"> <link rel="shortcut icon" type="image/png" href="../node_modules/jasmine-core/images/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" media="screen" href="../node_modules/jasmine-core/lib/jasmine-core/jasmine.css"> <link rel="stylesheet" type="text/css" media="screen" href="../node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
<link type="text/css" rel="stylesheet" media="screen" href="../node_modules/font-awesome/css/font-awesome.min.css" />
<link rel="stylesheet" type="text/css" media="screen" href="../css/jasmine.css"> <link rel="stylesheet" type="text/css" media="screen" href="../css/jasmine.css">
<link type="text/css" rel="stylesheet" media="screen" href="../css/website.css" /> <link type="text/css" rel="stylesheet" media="screen" href="../css/website.css" />
<link type="text/css" rel="stylesheet" media="screen" href="../css/converse.css" /> <link type="text/css" rel="stylesheet" media="screen" href="../css/converse.css" />
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment