Commit b5c56c83 authored by JC Brand's avatar JC Brand

Add `getFullname` to XMPPStatus model and use that

instead of returning the fullname as fallback in `getNickname`
parent 5f5de90f
...@@ -280,22 +280,10 @@ ...@@ -280,22 +280,10 @@
} }
}); });
await test_utils.openChatRoom(_converse, 'lounge', 'montague.lit', 'romeo'); await test_utils.openChatRoom(_converse, 'lounge', 'montague.lit', 'romeo');
let stanza = await u.waitUntil(() => _.filter(
IQ_stanzas,
iq => iq.querySelector(
`iq[to="${muc_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
)).pop());
// We pretend this is a new room, so no disco info is returned.
/* <iq from="jordie.langen@chat.example.org/converse.js-11659299" to="myroom@conference.chat.example.org" type="get"> const disco_selector = `iq[to="${muc_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`;
* <query xmlns="http://jabber.org/protocol/disco#info"/> const stanza = await u.waitUntil(() => IQ_stanzas.filter(iq => iq.querySelector(disco_selector)).pop());
* </iq> // We pretend this is a new room, so no disco info is returned.
* <iq xmlns="jabber:client" type="error" to="jordie.langen@chat.example.org/converse.js-11659299" from="myroom@conference.chat.example.org">
* <error type="cancel">
* <item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
* </error>
* </iq>
*/
const features_stanza = $iq({ const features_stanza = $iq({
'from': 'lounge@montague.lit', 'from': 'lounge@montague.lit',
'id': stanza.getAttribute('id'), 'id': stanza.getAttribute('id'),
...@@ -307,40 +295,8 @@ ...@@ -307,40 +295,8 @@
const view = _converse.chatboxviews.get('lounge@montague.lit'); const view = _converse.chatboxviews.get('lounge@montague.lit');
spyOn(view.model, 'join').and.callThrough(); spyOn(view.model, 'join').and.callThrough();
await test_utils.waitForReservedNick(_converse, muc_jid, '');
/* <iq to="myroom@conference.chat.example.org" const input = await u.waitUntil(() => view.el.querySelector('input[name="nick"]'), 1000);
* from="jordie.langen@chat.example.org/converse.js-11659299"
* type="get">
* <query xmlns="http://jabber.org/protocol/disco#info"
* node="x-roomuser-item"/>
* </iq>
*/
stanza = await u.waitUntil(() => _.filter(
IQ_stanzas,
s => sizzle(`iq[to="${muc_jid}"] query[node="x-roomuser-item"]`, s).length
).pop()
);
expect(Strophe.serialize(stanza)).toBe(
`<iq from="romeo@montague.lit/orchard" id="${stanza.getAttribute("id")}" to="lounge@montague.lit" `+
`type="get" xmlns="jabber:client">`+
`<query node="x-roomuser-item" xmlns="http://jabber.org/protocol/disco#info"/></iq>`);
/* <iq xmlns="jabber:client" type="error" to="jordie.langen@chat.example.org/converse.js-11659299" from="myroom@conference.chat.example.org">
* <error type="cancel">
* <item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
* </error>
* </iq>
*/
const result_stanza = $iq({
'type': 'error',
'id': stanza.getAttribute('id'),
'from': view.model.get('jid'),
'to': _converse.connection.jid
}).c('error', {'type': 'cancel'})
.c('item-not-found', {'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas"});
_converse.connection._dataRecv(test_utils.createRequest(result_stanza));
const input = await u.waitUntil(() => view.el.querySelector('input[name="nick"]'));
expect(view.model.get('connection_status')).toBe(converse.ROOMSTATUS.NICKNAME_REQUIRED); expect(view.model.get('connection_status')).toBe(converse.ROOMSTATUS.NICKNAME_REQUIRED);
input.value = 'nicky'; input.value = 'nicky';
view.el.querySelector('input[type=submit]').click(); view.el.querySelector('input[type=submit]').click();
......
...@@ -1292,6 +1292,11 @@ _converse.initialize = async function (settings, callback) { ...@@ -1292,6 +1292,11 @@ _converse.initialize = async function (settings, callback) {
return _converse.nickname; return _converse.nickname;
}, },
getFullname () {
// Gets overridden in converse-vcard
return '';
},
constructPresence (type, status_message) { constructPresence (type, status_message) {
let presence; let presence;
type = _.isString(type) ? type : (this.get('status') || _converse.default_state); type = _.isString(type) ? type : (this.get('status') || _converse.default_state);
......
...@@ -1201,7 +1201,7 @@ converse.plugins.add('converse-muc', { ...@@ -1201,7 +1201,7 @@ converse.plugins.add('converse-muc', {
'xmlns': Strophe.NS.DISCO_INFO, 'xmlns': Strophe.NS.DISCO_INFO,
'node': 'x-roomuser-item' 'node': 'x-roomuser-item'
}) })
const result = await _converse.api.sendIQ(stanza, null, true); const result = await _converse.api.sendIQ(stanza, null, false);
if (u.isErrorObject(result)) { if (u.isErrorObject(result)) {
throw result; throw result;
} }
......
...@@ -294,7 +294,7 @@ converse.plugins.add('converse-roster', { ...@@ -294,7 +294,7 @@ converse.plugins.add('converse-roster', {
if (message && message !== "") { if (message && message !== "") {
pres.c("status").t(message).up(); pres.c("status").t(message).up();
} }
const nick = _converse.xmppstatus.getNickname(); const nick = _converse.xmppstatus.getNickname() || _converse.xmppstatus.getFullname();
if (nick) { if (nick) {
pres.c('nick', {'xmlns': Strophe.NS.NICK}).t(nick).up(); pres.c('nick', {'xmlns': Strophe.NS.NICK}).t(nick).up();
} }
...@@ -473,7 +473,7 @@ converse.plugins.add('converse-roster', { ...@@ -473,7 +473,7 @@ converse.plugins.add('converse-roster', {
if (item.getAttribute('action') === 'add') { if (item.getAttribute('action') === 'add') {
_converse.roster.addAndSubscribe( _converse.roster.addAndSubscribe(
item.getAttribute('jid'), item.getAttribute('jid'),
_converse.xmppstatus.getNickname() _converse.xmppstatus.getNickname() || _converse.xmppstatus.getFullname()
); );
} }
}); });
......
...@@ -24,10 +24,20 @@ converse.plugins.add('converse-vcard', { ...@@ -24,10 +24,20 @@ converse.plugins.add('converse-vcard', {
const { _converse } = this.__super__; const { _converse } = this.__super__;
const nick = this.__super__.getNickname.apply(this); const nick = this.__super__.getNickname.apply(this);
if (!nick && _converse.xmppstatus.vcard) { if (!nick && _converse.xmppstatus.vcard) {
return _converse.xmppstatus.vcard.get('nickname') || _converse.xmppstatus.vcard.get('fullname'); return _converse.xmppstatus.vcard.get('nickname');
} else { } else {
return nick; return nick;
} }
},
getFullname (){
const { _converse } = this.__super__;
const fullname = this.__super__.getFullname.apply(this);
if (!fullname && _converse.xmppstatus.vcard) {
return _converse.xmppstatus.vcard.get('fullname');
} else {
return fullname;
}
} }
}, },
......
...@@ -205,10 +205,14 @@ ...@@ -205,10 +205,14 @@
'id': IQ_id, 'id': IQ_id,
'from': view.model.get('jid'), 'from': view.model.get('jid'),
'to': _converse.connection.jid 'to': _converse.connection.jid
}).c('query', {'xmlns': 'http://jabber.org/protocol/disco#info', 'node': 'x-roomuser-item'}) }).c('query', {'xmlns': 'http://jabber.org/protocol/disco#info', 'node': 'x-roomuser-item'});
.c('identity', {'category': 'conference', 'name': nick, 'type': 'text'}); if (nick) {
stanza.c('identity', {'category': 'conference', 'name': nick, 'type': 'text'});
}
_converse.connection._dataRecv(utils.createRequest(stanza)); _converse.connection._dataRecv(utils.createRequest(stanza));
if (nick) {
return u.waitUntil(() => view.model.get('nick')); return u.waitUntil(() => view.model.get('nick'));
}
}; };
......
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