Commit a9ce9acf authored by JC Brand's avatar JC Brand

Make sure `nickname` config option takes precedence

above other nickname sources.
parent d7db4df4
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
- 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)
- Make sure `nickname` passed in via `_converse.initialize` has first preference as MUC nickname
- #1149: With `xhr_user_search_url`, contact requests are not being sent out - #1149: With `xhr_user_search_url`, contact requests are not being sent out
- #1213: Switch roster filter input and icons - #1213: Switch roster filter input and icons
- #1327: fix False mentions positives in URLs and Email addresses - #1327: fix False mentions positives in URLs and Email addresses
......
...@@ -53767,12 +53767,6 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins ...@@ -53767,12 +53767,6 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins
this.roomspanel.model.fetch(); this.roomspanel.model.fetch();
this.el.querySelector('.controlbox-pane').insertAdjacentElement('beforeEnd', this.roomspanel.render().el); this.el.querySelector('.controlbox-pane').insertAdjacentElement('beforeEnd', this.roomspanel.render().el);
if (!this.roomspanel.model.get('nick')) {
this.roomspanel.model.save({
nick: _converse.xmppstatus.vcard.get('nickname') || Strophe.getNodeFromJid(_converse.bare_jid)
});
}
_converse.emit('roomsPanelRendered'); _converse.emit('roomsPanelRendered');
}, },
...@@ -55017,7 +55011,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins ...@@ -55017,7 +55011,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins
}, },
onReservedNickNotFound(message) { onReservedNickNotFound(message) {
const nick = this.model.getDefaultNick(); const nick = _converse.getDefaultMUCNickname();
if (nick) { if (nick) {
this.join(nick); this.join(nick);
...@@ -55038,7 +55032,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins ...@@ -55038,7 +55032,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins
if (_converse.muc_nickname_from_jid) { if (_converse.muc_nickname_from_jid) {
const nick = presence.getAttribute('from').split('/')[1]; const nick = presence.getAttribute('from').split('/')[1];
if (nick === this.model.getDefaultNick()) { if (nick === _converse.getDefaultMUCNickname()) {
this.join(nick + '-2'); this.join(nick + '-2');
} else { } else {
const del = nick.lastIndexOf("-"); const del = nick.lastIndexOf("-");
...@@ -64109,11 +64103,12 @@ _converse.initialize = async function (settings, callback) { ...@@ -64109,11 +64103,12 @@ _converse.initialize = async function (settings, callback) {
_converse.onStatusInitialized(reconnecting); _converse.onStatusInitialized(reconnecting);
} else { } else {
const id = `converse.xmppstatus-${_converse.bare_jid}`; const id = `converse.xmppstatus-${_converse.bare_jid}`;
this.xmppstatus = new this.XMPPStatus({ _converse.xmppstatus = new this.XMPPStatus({
'id': id 'id': id
}); });
this.xmppstatus.browserStorage = new Backbone.BrowserStorage.session(id); _converse.xmppstatus.browserStorage = new Backbone.BrowserStorage.session(id);
this.xmppstatus.fetch({
_converse.xmppstatus.fetch({
'success': _lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.partial(_converse.onStatusInitialized, reconnecting), 'success': _lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.partial(_converse.onStatusInitialized, reconnecting),
'error': _lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.partial(_converse.onStatusInitialized, reconnecting) 'error': _lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.partial(_converse.onStatusInitialized, reconnecting)
}); });
...@@ -66646,6 +66641,20 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc ...@@ -66646,6 +66641,20 @@ _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 () {
if (!_converse.xmppstatus) {
throw new Error("Can't call _converse.getNickname before the statusInitialized has been fired.");
}
const nick = _converse.nickname || _converse.xmppstatus.vcard.get('nickname');
if (nick) {
return nick;
} else if (_converse.muc_nickname_from_jid) {
return Strophe.unescapeNode(Strophe.getNodeFromJid(_converse.bare_jid));
}
};
_converse.openChatRoom = function (jid, settings, bring_to_foreground) { _converse.openChatRoom = function (jid, settings, bring_to_foreground) {
/* Opens a groupchat, making sure that certain attributes /* Opens a groupchat, making sure that certain attributes
* are correct, for example that the "type" is set to * are correct, for example that the "type" is set to
...@@ -67382,21 +67391,6 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc ...@@ -67382,21 +67391,6 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
this.getJidsWithAffiliations(affiliations).then(old_members => this.setAffiliations(deltaFunc(members, old_members))).then(() => this.occupants.fetchMembers()).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR)); this.getJidsWithAffiliations(affiliations).then(old_members => this.setAffiliations(deltaFunc(members, old_members))).then(() => this.occupants.fetchMembers()).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
}, },
getDefaultNick() {
/* The default nickname (used when muc_nickname_from_jid is true)
* is the node part of the user's JID.
* We put this in a separate method so that it can be
* overridden by plugins.
*/
const nick = _converse.xmppstatus.vcard.get('nickname');
if (nick) {
return nick;
} else if (_converse.muc_nickname_from_jid) {
return Strophe.unescapeNode(Strophe.getNodeFromJid(_converse.bare_jid));
}
},
async checkForReservedNick() { async checkForReservedNick() {
/* Use service-discovery to ask the XMPP server whether /* Use service-discovery to ask the XMPP server whether
* this user has a reserved nickname for this groupchat. * this user has a reserved nickname for this groupchat.
...@@ -67956,8 +67950,11 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc ...@@ -67956,8 +67950,11 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
}); });
_converse.RoomsPanelModel = Backbone.Model.extend({ _converse.RoomsPanelModel = Backbone.Model.extend({
defaults: { defaults: function defaults() {
'muc_domain': '' return {
'muc_domain': '',
'nick': _converse.getDefaultMUCNickname()
};
} }
}); });
...@@ -68831,11 +68828,11 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins ...@@ -68831,11 +68828,11 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
subscribe(message) { subscribe(message) {
/* Send a presence subscription request to this roster contact /* Send a presence subscription request to this roster contact
* *
* Parameters: * Parameters:
* (String) message - An optional message to explain the * (String) message - An optional message to explain the
* reason for the subscription request. * reason for the subscription request.
*/ */
const pres = $pres({ const pres = $pres({
to: this.get('jid'), to: this.get('jid'),
type: "subscribe" type: "subscribe"
...@@ -68845,7 +68842,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins ...@@ -68845,7 +68842,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
pres.c("status").t(message).up(); pres.c("status").t(message).up();
} }
const nick = _converse.xmppstatus.vcard.get('nickname') || _converse.xmppstatus.vcard.get('fullname'); const nick = _converse.nickname || _converse.xmppstatus.vcard.get('nickname') || _converse.xmppstatus.vcard.get('fullname');
if (nick) { if (nick) {
pres.c('nick', { pres.c('nick', {
...@@ -68862,10 +68859,10 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins ...@@ -68862,10 +68859,10 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
ackSubscribe() { ackSubscribe() {
/* Upon receiving the presence stanza of type "subscribed", /* Upon receiving the presence stanza of type "subscribed",
* the user SHOULD acknowledge receipt of that subscription * the user SHOULD acknowledge receipt of that subscription
* state notification by sending a presence stanza of type * state notification by sending a presence stanza of type
* "subscribe" to the contact * "subscribe" to the contact
*/ */
_converse.api.send($pres({ _converse.api.send($pres({
'type': 'subscribe', 'type': 'subscribe',
'to': this.get('jid') 'to': this.get('jid')
...@@ -68892,9 +68889,9 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins ...@@ -68892,9 +68889,9 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
unauthorize(message) { unauthorize(message) {
/* Unauthorize this contact's presence subscription /* Unauthorize this contact's presence subscription
* Parameters: * Parameters:
* (String) message - Optional message to send to the person being unauthorized * (String) message - Optional message to send to the person being unauthorized
*/ */
_converse.rejectPresenceSubscription(this.get('jid'), message); _converse.rejectPresenceSubscription(this.get('jid'), message);
return this; return this;
...@@ -1042,6 +1042,10 @@ This setting allows you to specify the nickname for the current user. ...@@ -1042,6 +1042,10 @@ 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,
such as the VCard `nickname` value).
notify_all_room_messages notify_all_room_messages
------------------------ ------------------------
......
...@@ -3971,6 +3971,11 @@ ...@@ -3971,6 +3971,11 @@
let name_input = modal.el.querySelector('input[name="chatroom"]'); let name_input = modal.el.querySelector('input[name="chatroom"]');
expect(name_input.placeholder).toBe('name@conference.example.org'); expect(name_input.placeholder).toBe('name@conference.example.org');
const label_nick = modal.el.querySelector('label[for="nickname"]');
expect(label_nick.textContent).toBe('Optional nickname:');
const nick_input = modal.el.querySelector('input[name="nickname"]');
expect(nick_input.value).toBe('');
expect(modal.el.querySelector('.modal-title').textContent).toBe('Enter a new Groupchat'); expect(modal.el.querySelector('.modal-title').textContent).toBe('Enter a new Groupchat');
spyOn(_converse.ChatRoom.prototype, 'getRoomFeatures').and.callFake(() => Promise.resolve()); spyOn(_converse.ChatRoom.prototype, 'getRoomFeatures').and.callFake(() => Promise.resolve());
roomspanel.delegateEvents(); // We need to rebind all events otherwise our spy won't be called roomspanel.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
...@@ -3988,6 +3993,45 @@ ...@@ -3988,6 +3993,45 @@
done(); done();
})); }));
it("uses the JID node if muc_nickname_from_jid is set to true",
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'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 label_nick = modal.el.querySelector('label[for="nickname"]');
expect(label_nick.textContent).toBe('Optional nickname:');
const nick_input = modal.el.querySelector('input[name="nickname"]');
expect(nick_input.value).toBe('dummy');
done();
}));
it("uses the nickname passed in to converse.initialize",
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'nickname': 'st.nick'},
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 label_nick = modal.el.querySelector('label[for="nickname"]');
expect(label_nick.textContent).toBe('Optional nickname:');
const nick_input = modal.el.querySelector('input[name="nickname"]');
expect(nick_input.value).toBe('st.nick');
done();
}));
it("doesn't require the domain when muc_domain is set", it("doesn't require the domain when muc_domain is set",
mock.initConverse( mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'muc_domain': 'muc.example.org'}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'muc_domain': 'muc.example.org'},
......
...@@ -1262,7 +1262,7 @@ ...@@ -1262,7 +1262,7 @@
*/ */
expect(_converse.roster.pluck('jid').length).toBe(0); expect(_converse.roster.pluck('jid').length).toBe(0);
var stanza = $pres({from: 'data@enterprise/resource', type: 'subscribe'}); let stanza = $pres({from: 'data@enterprise/resource', type: 'subscribe'});
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
test_utils.waitUntil(function () { test_utils.waitUntil(function () {
return $('a:contains("Contact requests")').length; return $('a:contains("Contact requests")').length;
......
...@@ -77,11 +77,6 @@ converse.plugins.add('converse-muc-views', { ...@@ -77,11 +77,6 @@ converse.plugins.add('converse-muc-views', {
this.el.querySelector('.controlbox-pane').insertAdjacentElement( this.el.querySelector('.controlbox-pane').insertAdjacentElement(
'beforeEnd', this.roomspanel.render().el); 'beforeEnd', this.roomspanel.render().el);
if (!this.roomspanel.model.get('nick')) {
this.roomspanel.model.save({
nick: _converse.xmppstatus.vcard.get('nickname') || Strophe.getNodeFromJid(_converse.bare_jid)
});
}
_converse.emit('roomsPanelRendered'); _converse.emit('roomsPanelRendered');
}, },
...@@ -1259,7 +1254,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -1259,7 +1254,7 @@ converse.plugins.add('converse-muc-views', {
}, },
onReservedNickNotFound (message) { onReservedNickNotFound (message) {
const nick = this.model.getDefaultNick(); const nick = _converse.getDefaultMUCNickname();
if (nick) { if (nick) {
this.join(nick); this.join(nick);
} else { } else {
...@@ -1278,7 +1273,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -1278,7 +1273,7 @@ converse.plugins.add('converse-muc-views', {
*/ */
if (_converse.muc_nickname_from_jid) { if (_converse.muc_nickname_from_jid) {
const nick = presence.getAttribute('from').split('/')[1]; const nick = presence.getAttribute('from').split('/')[1];
if (nick === this.model.getDefaultNick()) { if (nick === _converse.getDefaultMUCNickname()) {
this.join(nick + '-2'); this.join(nick + '-2');
} else { } else {
const del= nick.lastIndexOf("-"); const del= nick.lastIndexOf("-");
......
...@@ -108,7 +108,6 @@ _converse.keycodes = { ...@@ -108,7 +108,6 @@ _converse.keycodes = {
META_RIGHT: 93 META_RIGHT: 93
}; };
// Module-level constants // Module-level constants
_converse.STATUS_WEIGHTS = { _converse.STATUS_WEIGHTS = {
'offline': 6, 'offline': 6,
...@@ -847,9 +846,9 @@ _converse.initialize = async function (settings, callback) { ...@@ -847,9 +846,9 @@ _converse.initialize = async function (settings, callback) {
_converse.onStatusInitialized(reconnecting); _converse.onStatusInitialized(reconnecting);
} else { } else {
const id = `converse.xmppstatus-${_converse.bare_jid}`; const id = `converse.xmppstatus-${_converse.bare_jid}`;
this.xmppstatus = new this.XMPPStatus({'id': id}); _converse.xmppstatus = new this.XMPPStatus({'id': id});
this.xmppstatus.browserStorage = new Backbone.BrowserStorage.session(id); _converse.xmppstatus.browserStorage = new Backbone.BrowserStorage.session(id);
this.xmppstatus.fetch({ _converse.xmppstatus.fetch({
'success': _.partial(_converse.onStatusInitialized, reconnecting), 'success': _.partial(_converse.onStatusInitialized, reconnecting),
'error': _.partial(_converse.onStatusInitialized, reconnecting) 'error': _.partial(_converse.onStatusInitialized, reconnecting)
}); });
......
...@@ -140,6 +140,18 @@ converse.plugins.add('converse-muc', { ...@@ -140,6 +140,18 @@ converse.plugins.add('converse-muc', {
_converse.router.route('converse/room?jid=:jid', openRoom); _converse.router.route('converse/room?jid=:jid', openRoom);
_converse.getDefaultMUCNickname = function () {
if (!_converse.xmppstatus) {
throw new Error("Can't call _converse.getNickname before the statusInitialized has been fired.");
}
const nick = _converse.nickname || _converse.xmppstatus.vcard.get('nickname');
if (nick) {
return nick;
} else if (_converse.muc_nickname_from_jid) {
return Strophe.unescapeNode(Strophe.getNodeFromJid(_converse.bare_jid));
}
}
_converse.openChatRoom = function (jid, settings, bring_to_foreground) { _converse.openChatRoom = function (jid, settings, bring_to_foreground) {
/* Opens a groupchat, making sure that certain attributes /* Opens a groupchat, making sure that certain attributes
* are correct, for example that the "type" is set to * are correct, for example that the "type" is set to
...@@ -777,20 +789,6 @@ converse.plugins.add('converse-muc', { ...@@ -777,20 +789,6 @@ converse.plugins.add('converse-muc', {
.catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR)); .catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
}, },
getDefaultNick () {
/* The default nickname (used when muc_nickname_from_jid is true)
* is the node part of the user's JID.
* We put this in a separate method so that it can be
* overridden by plugins.
*/
const nick = _converse.xmppstatus.vcard.get('nickname');
if (nick) {
return nick;
} else if (_converse.muc_nickname_from_jid) {
return Strophe.unescapeNode(Strophe.getNodeFromJid(_converse.bare_jid));
}
},
async checkForReservedNick () { async checkForReservedNick () {
/* Use service-discovery to ask the XMPP server whether /* Use service-discovery to ask the XMPP server whether
* this user has a reserved nickname for this groupchat. * this user has a reserved nickname for this groupchat.
...@@ -1274,9 +1272,12 @@ converse.plugins.add('converse-muc', { ...@@ -1274,9 +1272,12 @@ converse.plugins.add('converse-muc', {
_converse.RoomsPanelModel = Backbone.Model.extend({ _converse.RoomsPanelModel = Backbone.Model.extend({
defaults: { defaults: function () {
'muc_domain': '', return {
}, 'muc_domain': '',
'nick': _converse.getDefaultMUCNickname()
}
}
}); });
......
...@@ -245,16 +245,16 @@ converse.plugins.add('converse-roster', { ...@@ -245,16 +245,16 @@ converse.plugins.add('converse-roster', {
subscribe (message) { subscribe (message) {
/* Send a presence subscription request to this roster contact /* Send a presence subscription request to this roster contact
* *
* Parameters: * Parameters:
* (String) message - An optional message to explain the * (String) message - An optional message to explain the
* reason for the subscription request. * reason for the subscription request.
*/ */
const pres = $pres({to: this.get('jid'), type: "subscribe"}); const pres = $pres({to: this.get('jid'), type: "subscribe"});
if (message && message !== "") { if (message && message !== "") {
pres.c("status").t(message).up(); pres.c("status").t(message).up();
} }
const nick = _converse.xmppstatus.vcard.get('nickname') || _converse.xmppstatus.vcard.get('fullname'); const nick = _converse.nickname || _converse.xmppstatus.vcard.get('nickname') || _converse.xmppstatus.vcard.get('fullname');
if (nick) { if (nick) {
pres.c('nick', {'xmlns': Strophe.NS.NICK}).t(nick).up(); pres.c('nick', {'xmlns': Strophe.NS.NICK}).t(nick).up();
} }
...@@ -265,10 +265,10 @@ converse.plugins.add('converse-roster', { ...@@ -265,10 +265,10 @@ converse.plugins.add('converse-roster', {
ackSubscribe () { ackSubscribe () {
/* Upon receiving the presence stanza of type "subscribed", /* Upon receiving the presence stanza of type "subscribed",
* the user SHOULD acknowledge receipt of that subscription * the user SHOULD acknowledge receipt of that subscription
* state notification by sending a presence stanza of type * state notification by sending a presence stanza of type
* "subscribe" to the contact * "subscribe" to the contact
*/ */
_converse.api.send($pres({ _converse.api.send($pres({
'type': 'subscribe', 'type': 'subscribe',
'to': this.get('jid') 'to': this.get('jid')
...@@ -291,9 +291,9 @@ converse.plugins.add('converse-roster', { ...@@ -291,9 +291,9 @@ converse.plugins.add('converse-roster', {
unauthorize (message) { unauthorize (message) {
/* Unauthorize this contact's presence subscription /* Unauthorize this contact's presence subscription
* Parameters: * Parameters:
* (String) message - Optional message to send to the person being unauthorized * (String) message - Optional message to send to the person being unauthorized
*/ */
_converse.rejectPresenceSubscription(this.get('jid'), message); _converse.rejectPresenceSubscription(this.get('jid'), message);
return this; return this;
}, },
......
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