diff --git a/CHANGES.md b/CHANGES.md index eeee15632..16257a39e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ The UI is now based on Bootstrap4 and Flexbox is used extensively. * Removed `xhr_user_search` in favor of only accepting `xhr_user_search_url` as configuration option. * The data returned from the `xhr_user_search_url` must now include the user's `jid` instead of just an `id`. +- New configuration setting [nickname](https://conversejs.org/docs/html/configurations.html#nickname) ### Bugfixes diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index 3bafb6b5f..5c9c9db47 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -992,6 +992,15 @@ muc_show_join_leave Determines whether Converse.js will show info messages inside a chatroom whenever a user joins or leaves it. +nickname +-------- + +* Default: ``undefined`` + +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. + notify_all_room_messages ------------------------ diff --git a/src/converse-core.js b/src/converse-core.js index 8e7af3809..43fff40e9 100644 --- a/src/converse-core.js +++ b/src/converse-core.js @@ -318,6 +318,7 @@ ], message_carbons: true, message_storage: 'session', + nickname: undefined, password: undefined, prebind_url: null, priority: 0, @@ -903,8 +904,8 @@ if (message && message !== "") { pres.c("status").t(message).up(); } - const nick = _converse.xmppstatus.get('fullname'); - if (nick && nick !== "") { + const nick = _converse.xmppstatus.get('nickname') || _converse.xmppstatus.get('fullname'); + if (nick) { pres.c('nick', {'xmlns': Strophe.NS.NICK}).t(nick).up(); } _converse.connection.send(pres); @@ -1131,8 +1132,7 @@ if (item.getAttribute('action') === 'add') { _converse.roster.addAndSubscribe( item.getAttribute('jid'), - null, - _converse.xmppstatus.get('fullname') + _converse.xmppstatus.get('nickname') || _converse.xmppstatus.get('fullname') ); } }); @@ -1159,7 +1159,7 @@ contact.subscribe(message); } } - this.addContact(jid, name, groups, attributes).then(handler, handler); + this.addContactToRoster(jid, name, groups, attributes).then(handler, handler); }, sendContactAddIQ (jid, name, groups, callback, errback) { @@ -1180,7 +1180,7 @@ _converse.connection.sendIQ(iq, callback, errback); }, - addContact (jid, name, groups, attributes) { + addContactToRoster (jid, name, groups, attributes) { /* Adds a RosterContact instance to _converse.roster and * registers the contact on the XMPP server. * Returns a promise which is resolved once the XMPP server has @@ -1216,7 +1216,7 @@ }); }, - subscribeBack (bare_jid) { + subscribeBack (bare_jid, presence) { const contact = this.get(bare_jid); if (contact instanceof _converse.RosterContact) { contact.authorize().subscribe(); @@ -1227,7 +1227,8 @@ contact.authorize().subscribe(); } } - this.addContact(bare_jid, '', [], {'subscription': 'from'}).then(handler, handler); + const nickname = _.get(sizzle(`nick[xmlns="${Strophe.NS.NICK}"]`, presence).pop(), 'textContent', null); + this.addContactToRoster(bare_jid, nickname, [], {'subscription': 'from'}).then(handler, handler); } }, @@ -1340,13 +1341,13 @@ * Note: this method gets completely overridden by converse-vcard.js */ const bare_jid = Strophe.getBareJidFromJid(presence.getAttribute('from')), - nick_el = presence.querySelector(`nick[xmlns="${Strophe.NS.NICK}"]`); + nickname = _.get(sizzle(`nick[xmlns="${Strophe.NS.NICK}"]`, presence).pop(), 'textContent', null); const user_data = { 'jid': bare_jid, 'subscription': 'none', 'ask': null, 'requesting': true, - 'fullname': nick_el && nick_el.textContent || bare_jid, + 'fullname': nickname }; this.create(user_data); _converse.emit('contactRequest', user_data); @@ -1365,7 +1366,7 @@ } if (_converse.auto_subscribe) { if ((!contact) || (contact.get('subscription') !== 'to')) { - this.subscribeBack(bare_jid); + this.subscribeBack(bare_jid, presence); } else { contact.authorize(); } @@ -1485,6 +1486,7 @@ return { "status": _converse.default_state, "jid": _converse.bare_jid, + "nickname": _converse.nickname, "vcard_updated": null } }, diff --git a/src/converse-muc-views.js b/src/converse-muc-views.js index 8eeb62135..750b9e42b 100644 --- a/src/converse-muc-views.js +++ b/src/converse-muc-views.js @@ -114,7 +114,7 @@ if (!this.roomspanel.model.get('nick')) { this.roomspanel.model.save({ - nick: Strophe.getNodeFromJid(_converse.bare_jid) + nick: _converse.xmppstatus.get('nickname') || Strophe.getNodeFromJid(_converse.bare_jid) }); } _converse.emit('roomsPanelRendered'); diff --git a/src/converse-muc.js b/src/converse-muc.js index 651cd3314..dd0db0c7c 100644 --- a/src/converse-muc.js +++ b/src/converse-muc.js @@ -264,6 +264,7 @@ 'affiliation': null, 'connection_status': converse.ROOMSTATUS.DISCONNECTED, 'name': '', + 'nick': _converse.xmppstatus.get('nickname'), 'description': '', 'features_fetched': false, 'roomconfig': {},