Add a new config setting nickname

- for subscription requests
- when entering chat rooms
This commit is contained in:
JC Brand 2018-03-27 16:05:38 +02:00
parent 3354083934
commit b584f2efb3
5 changed files with 25 additions and 12 deletions

View File

@ -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. * 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 * The data returned from the `xhr_user_search_url` must now include the user's
`jid` instead of just an `id`. `jid` instead of just an `id`.
- New configuration setting [nickname](https://conversejs.org/docs/html/configurations.html#nickname)
### Bugfixes ### Bugfixes

View File

@ -992,6 +992,15 @@ muc_show_join_leave
Determines whether Converse.js will show info messages inside a chatroom Determines whether Converse.js will show info messages inside a chatroom
whenever a user joins or leaves it. 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 notify_all_room_messages
------------------------ ------------------------

View File

@ -318,6 +318,7 @@
], ],
message_carbons: true, message_carbons: true,
message_storage: 'session', message_storage: 'session',
nickname: undefined,
password: undefined, password: undefined,
prebind_url: null, prebind_url: null,
priority: 0, priority: 0,
@ -903,8 +904,8 @@
if (message && message !== "") { if (message && message !== "") {
pres.c("status").t(message).up(); pres.c("status").t(message).up();
} }
const nick = _converse.xmppstatus.get('fullname'); const nick = _converse.xmppstatus.get('nickname') || _converse.xmppstatus.get('fullname');
if (nick && nick !== "") { if (nick) {
pres.c('nick', {'xmlns': Strophe.NS.NICK}).t(nick).up(); pres.c('nick', {'xmlns': Strophe.NS.NICK}).t(nick).up();
} }
_converse.connection.send(pres); _converse.connection.send(pres);
@ -1131,8 +1132,7 @@
if (item.getAttribute('action') === 'add') { if (item.getAttribute('action') === 'add') {
_converse.roster.addAndSubscribe( _converse.roster.addAndSubscribe(
item.getAttribute('jid'), item.getAttribute('jid'),
null, _converse.xmppstatus.get('nickname') || _converse.xmppstatus.get('fullname')
_converse.xmppstatus.get('fullname')
); );
} }
}); });
@ -1159,7 +1159,7 @@
contact.subscribe(message); 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) { sendContactAddIQ (jid, name, groups, callback, errback) {
@ -1180,7 +1180,7 @@
_converse.connection.sendIQ(iq, callback, errback); _converse.connection.sendIQ(iq, callback, errback);
}, },
addContact (jid, name, groups, attributes) { addContactToRoster (jid, name, groups, attributes) {
/* Adds a RosterContact instance to _converse.roster and /* Adds a RosterContact instance to _converse.roster and
* registers the contact on the XMPP server. * registers the contact on the XMPP server.
* Returns a promise which is resolved once the XMPP server has * 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); const contact = this.get(bare_jid);
if (contact instanceof _converse.RosterContact) { if (contact instanceof _converse.RosterContact) {
contact.authorize().subscribe(); contact.authorize().subscribe();
@ -1227,7 +1227,8 @@
contact.authorize().subscribe(); 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 * Note: this method gets completely overridden by converse-vcard.js
*/ */
const bare_jid = Strophe.getBareJidFromJid(presence.getAttribute('from')), 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 = { const user_data = {
'jid': bare_jid, 'jid': bare_jid,
'subscription': 'none', 'subscription': 'none',
'ask': null, 'ask': null,
'requesting': true, 'requesting': true,
'fullname': nick_el && nick_el.textContent || bare_jid, 'fullname': nickname
}; };
this.create(user_data); this.create(user_data);
_converse.emit('contactRequest', user_data); _converse.emit('contactRequest', user_data);
@ -1365,7 +1366,7 @@
} }
if (_converse.auto_subscribe) { if (_converse.auto_subscribe) {
if ((!contact) || (contact.get('subscription') !== 'to')) { if ((!contact) || (contact.get('subscription') !== 'to')) {
this.subscribeBack(bare_jid); this.subscribeBack(bare_jid, presence);
} else { } else {
contact.authorize(); contact.authorize();
} }
@ -1485,6 +1486,7 @@
return { return {
"status": _converse.default_state, "status": _converse.default_state,
"jid": _converse.bare_jid, "jid": _converse.bare_jid,
"nickname": _converse.nickname,
"vcard_updated": null "vcard_updated": null
} }
}, },

View File

@ -114,7 +114,7 @@
if (!this.roomspanel.model.get('nick')) { if (!this.roomspanel.model.get('nick')) {
this.roomspanel.model.save({ this.roomspanel.model.save({
nick: Strophe.getNodeFromJid(_converse.bare_jid) nick: _converse.xmppstatus.get('nickname') || Strophe.getNodeFromJid(_converse.bare_jid)
}); });
} }
_converse.emit('roomsPanelRendered'); _converse.emit('roomsPanelRendered');

View File

@ -264,6 +264,7 @@
'affiliation': null, 'affiliation': null,
'connection_status': converse.ROOMSTATUS.DISCONNECTED, 'connection_status': converse.ROOMSTATUS.DISCONNECTED,
'name': '', 'name': '',
'nick': _converse.xmppstatus.get('nickname'),
'description': '', 'description': '',
'features_fetched': false, 'features_fetched': false,
'roomconfig': {}, 'roomconfig': {},