Make sure nickname
config option takes precedence
above other nickname sources.
This commit is contained in:
parent
d7db4df468
commit
a9ce9acff2
@ -12,6 +12,7 @@
|
||||
- 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.
|
||||
- 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
|
||||
- #1213: Switch roster filter input and icons
|
||||
- #1327: fix False mentions positives in URLs and Email addresses
|
||||
|
55
dist/converse.js
vendored
55
dist/converse.js
vendored
@ -53767,12 +53767,6 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins
|
||||
this.roomspanel.model.fetch();
|
||||
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');
|
||||
},
|
||||
|
||||
@ -55017,7 +55011,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins
|
||||
},
|
||||
|
||||
onReservedNickNotFound(message) {
|
||||
const nick = this.model.getDefaultNick();
|
||||
const nick = _converse.getDefaultMUCNickname();
|
||||
|
||||
if (nick) {
|
||||
this.join(nick);
|
||||
@ -55038,7 +55032,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins
|
||||
if (_converse.muc_nickname_from_jid) {
|
||||
const nick = presence.getAttribute('from').split('/')[1];
|
||||
|
||||
if (nick === this.model.getDefaultNick()) {
|
||||
if (nick === _converse.getDefaultMUCNickname()) {
|
||||
this.join(nick + '-2');
|
||||
} else {
|
||||
const del = nick.lastIndexOf("-");
|
||||
@ -64109,11 +64103,12 @@ _converse.initialize = async function (settings, callback) {
|
||||
_converse.onStatusInitialized(reconnecting);
|
||||
} else {
|
||||
const id = `converse.xmppstatus-${_converse.bare_jid}`;
|
||||
this.xmppstatus = new this.XMPPStatus({
|
||||
_converse.xmppstatus = new this.XMPPStatus({
|
||||
'id': id
|
||||
});
|
||||
this.xmppstatus.browserStorage = new Backbone.BrowserStorage.session(id);
|
||||
this.xmppstatus.fetch({
|
||||
_converse.xmppstatus.browserStorage = new Backbone.BrowserStorage.session(id);
|
||||
|
||||
_converse.xmppstatus.fetch({
|
||||
'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)
|
||||
});
|
||||
@ -66646,6 +66641,20 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
|
||||
|
||||
_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) {
|
||||
/* Opens a groupchat, making sure that certain attributes
|
||||
* 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
|
||||
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() {
|
||||
/* Use service-discovery to ask the XMPP server whether
|
||||
* this user has a reserved nickname for this groupchat.
|
||||
@ -67956,8 +67950,11 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
|
||||
|
||||
});
|
||||
_converse.RoomsPanelModel = Backbone.Model.extend({
|
||||
defaults: {
|
||||
'muc_domain': ''
|
||||
defaults: function defaults() {
|
||||
return {
|
||||
'muc_domain': '',
|
||||
'nick': _converse.getDefaultMUCNickname()
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
@ -68845,7 +68842,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
|
||||
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) {
|
||||
pres.c('nick', {
|
||||
|
@ -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
|
||||
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
|
||||
------------------------
|
||||
|
||||
|
44
spec/muc.js
44
spec/muc.js
@ -3971,6 +3971,11 @@
|
||||
let name_input = modal.el.querySelector('input[name="chatroom"]');
|
||||
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');
|
||||
spyOn(_converse.ChatRoom.prototype, 'getRoomFeatures').and.callFake(() => Promise.resolve());
|
||||
roomspanel.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
||||
@ -3988,6 +3993,45 @@
|
||||
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",
|
||||
mock.initConverse(
|
||||
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'muc_domain': 'muc.example.org'},
|
||||
|
@ -1262,7 +1262,7 @@
|
||||
*/
|
||||
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));
|
||||
test_utils.waitUntil(function () {
|
||||
return $('a:contains("Contact requests")').length;
|
||||
|
@ -77,11 +77,6 @@ converse.plugins.add('converse-muc-views', {
|
||||
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');
|
||||
},
|
||||
|
||||
@ -1259,7 +1254,7 @@ converse.plugins.add('converse-muc-views', {
|
||||
},
|
||||
|
||||
onReservedNickNotFound (message) {
|
||||
const nick = this.model.getDefaultNick();
|
||||
const nick = _converse.getDefaultMUCNickname();
|
||||
if (nick) {
|
||||
this.join(nick);
|
||||
} else {
|
||||
@ -1278,7 +1273,7 @@ converse.plugins.add('converse-muc-views', {
|
||||
*/
|
||||
if (_converse.muc_nickname_from_jid) {
|
||||
const nick = presence.getAttribute('from').split('/')[1];
|
||||
if (nick === this.model.getDefaultNick()) {
|
||||
if (nick === _converse.getDefaultMUCNickname()) {
|
||||
this.join(nick + '-2');
|
||||
} else {
|
||||
const del= nick.lastIndexOf("-");
|
||||
|
@ -108,7 +108,6 @@ _converse.keycodes = {
|
||||
META_RIGHT: 93
|
||||
};
|
||||
|
||||
|
||||
// Module-level constants
|
||||
_converse.STATUS_WEIGHTS = {
|
||||
'offline': 6,
|
||||
@ -847,9 +846,9 @@ _converse.initialize = async function (settings, callback) {
|
||||
_converse.onStatusInitialized(reconnecting);
|
||||
} else {
|
||||
const id = `converse.xmppstatus-${_converse.bare_jid}`;
|
||||
this.xmppstatus = new this.XMPPStatus({'id': id});
|
||||
this.xmppstatus.browserStorage = new Backbone.BrowserStorage.session(id);
|
||||
this.xmppstatus.fetch({
|
||||
_converse.xmppstatus = new this.XMPPStatus({'id': id});
|
||||
_converse.xmppstatus.browserStorage = new Backbone.BrowserStorage.session(id);
|
||||
_converse.xmppstatus.fetch({
|
||||
'success': _.partial(_converse.onStatusInitialized, reconnecting),
|
||||
'error': _.partial(_converse.onStatusInitialized, reconnecting)
|
||||
});
|
||||
|
@ -140,6 +140,18 @@ converse.plugins.add('converse-muc', {
|
||||
_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) {
|
||||
/* Opens a groupchat, making sure that certain attributes
|
||||
* are correct, for example that the "type" is set to
|
||||
@ -777,20 +789,6 @@ converse.plugins.add('converse-muc', {
|
||||
.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 () {
|
||||
/* Use service-discovery to ask the XMPP server whether
|
||||
* this user has a reserved nickname for this groupchat.
|
||||
@ -1274,9 +1272,12 @@ converse.plugins.add('converse-muc', {
|
||||
|
||||
|
||||
_converse.RoomsPanelModel = Backbone.Model.extend({
|
||||
defaults: {
|
||||
defaults: function () {
|
||||
return {
|
||||
'muc_domain': '',
|
||||
},
|
||||
'nick': _converse.getDefaultMUCNickname()
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
@ -254,7 +254,7 @@ converse.plugins.add('converse-roster', {
|
||||
if (message && message !== "") {
|
||||
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) {
|
||||
pres.c('nick', {'xmlns': Strophe.NS.NICK}).t(nick).up();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user