Commit 59c43a23 authored by JC Brand's avatar JC Brand

Two changes, see below

* Add new test helper to create contacts via IQ exchange
* Use roster nickname to set message fullname
parent 0ee08ee6
......@@ -61589,11 +61589,12 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
return {
'bookmarked': false,
'chat_state': undefined,
'hidden': _.includes(['mobile', 'fullscreen'], _converse.view_mode),
'message_type': 'chat',
'nickname': undefined,
'num_unread': 0,
'type': _converse.PRIVATE_CHAT_TYPE,
'message_type': 'chat',
'url': '',
'hidden': _.includes(['mobile', 'fullscreen'], _converse.view_mode)
'url': ''
};
},
......@@ -61643,7 +61644,8 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
// and we listen for change:chat_state, so shouldn't set it to ACTIVE here.
'box_id': b64_sha1(this.get('jid')),
'time_opened': this.get('time_opened') || moment().valueOf(),
'user_id': Strophe.getNodeFromJid(this.get('jid'))
'user_id': Strophe.getNodeFromJid(this.get('jid')),
'nickname': _.get(_converse.api.contacts.get(this.get('jid')), 'attributes.nickname')
});
},
......@@ -62126,7 +62128,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
attrs.fullname = _converse.xmppstatus.get('fullname');
} else {
attrs.sender = 'them';
attrs.fullname = this.get('fullname');
attrs.fullname = this.get('fullname') || this.get('fullname');
}
}
......@@ -62362,10 +62364,10 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
const has_body = sizzle(`body, encrypted[xmlns="${Strophe.NS.OMEMO}"]`, stanza).length > 0,
chatbox_attrs = {
'fullname': _.get(_converse.api.contacts.get(contact_jid), 'attributes.fullname')
},
chatbox = this.getChatBox(contact_jid, chatbox_attrs, has_body);
roster_nick = _.get(_converse.api.contacts.get(contact_jid), 'attributes.nickname'),
chatbox = this.getChatBox(contact_jid, {
'nickname': roster_nick
}, has_body);
if (chatbox && !chatbox.findDuplicateFromOriginID(stanza) && !(await chatbox.hasDuplicateArchiveID(original_stanza)) && !(await chatbox.hasDuplicateStanzaID(stanza)) && !chatbox.handleMessageCorrection(stanza) && !chatbox.handleReceipt(stanza, from_jid, is_carbon, is_me) && !chatbox.handleChatMarker(stanza, from_jid, is_carbon, is_roster_contact)) {
const attrs = await chatbox.getMessageAttributesFromStanza(stanza, original_stanza);
This diff is collapsed.
This diff is collapsed.
......@@ -14,8 +14,7 @@
null, ['rosterGroupsFetched'], {},
async (done, _converse) => {
test_utils.createContacts(_converse, 'current');
_converse.emit('rosterContactsFetched');
await test_utils.waitForRoster(_converse, 'current');
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
/* <message to='romeo@montague.net/orchard' from='juliet@capulet.net/balcony' id='spoiler2'>
......@@ -35,7 +34,7 @@
'xmlns': 'urn:xmpp:spoiler:0',
}).t(spoiler_hint)
.tree();
_converse.chatboxes.onMessage(msg);
await _converse.chatboxes.onMessage(msg);
await test_utils.waitUntil(() => _converse.api.chats.get().length === 2);
const view = _converse.chatboxviews.get(sender_jid);
......@@ -53,8 +52,7 @@
null, ['rosterGroupsFetched'], {},
async (done, _converse) => {
test_utils.createContacts(_converse, 'current');
_converse.emit('rosterContactsFetched');
await test_utils.waitForRoster(_converse, 'current');
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
/* <message to='romeo@montague.net/orchard' from='juliet@capulet.net/balcony' id='spoiler2'>
* <body>And at the end of the story, both of them die! It is so tragic!</body>
......@@ -71,7 +69,7 @@
.c('spoiler', {
'xmlns': 'urn:xmpp:spoiler:0',
}).tree();
_converse.chatboxes.onMessage(msg);
await _converse.chatboxes.onMessage(msg);
await test_utils.waitUntil(() => _converse.api.chats.get().length === 2);
const view = _converse.chatboxviews.get(sender_jid);
await test_utils.waitUntil(() => view.model.vcard.get('fullname') === 'Max Frankfurter')
......@@ -88,9 +86,7 @@
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async (done, _converse) => {
test_utils.createContacts(_converse, 'current', 1);
_converse.emit('rosterContactsFetched');
await test_utils.waitForRoster(_converse, 'current', 1);
test_utils.openControlBox();
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
......@@ -105,7 +101,7 @@
_converse.connection._dataRecv(test_utils.createRequest(presence));
await test_utils.openChatBoxFor(_converse, contact_jid);
await test_utils.waitUntilDiscoConfirmed(_converse, contact_jid+'/phone', [], [Strophe.NS.SPOILER]);
const view = _converse.chatboxviews.get(contact_jid);
const view = _converse.api.chatviews.get(contact_jid);
spyOn(_converse.connection, 'send');
await test_utils.waitUntil(() => view.el.querySelector('.toggle-compose-spoiler'));
......@@ -163,9 +159,7 @@
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async (done, _converse) => {
test_utils.createContacts(_converse, 'current', 1);
_converse.emit('rosterContactsFetched');
await test_utils.waitForRoster(_converse, 'current', 1);
test_utils.openControlBox();
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
......
......@@ -225,11 +225,12 @@ converse.plugins.add('converse-chatboxes', {
return {
'bookmarked': false,
'chat_state': undefined,
'hidden': _.includes(['mobile', 'fullscreen'], _converse.view_mode),
'message_type': 'chat',
'nickname': undefined,
'num_unread': 0,
'type': _converse.PRIVATE_CHAT_TYPE,
'message_type': 'chat',
'url': '',
'hidden': _.includes(['mobile', 'fullscreen'], _converse.view_mode)
'url': ''
}
},
......@@ -273,7 +274,8 @@ converse.plugins.add('converse-chatboxes', {
// and we listen for change:chat_state, so shouldn't set it to ACTIVE here.
'box_id' : b64_sha1(this.get('jid')),
'time_opened': this.get('time_opened') || moment().valueOf(),
'user_id' : Strophe.getNodeFromJid(this.get('jid'))
'user_id' : Strophe.getNodeFromJid(this.get('jid')),
'nickname':_.get(_converse.api.contacts.get(this.get('jid')), 'attributes.nickname')
});
},
......@@ -685,7 +687,7 @@ converse.plugins.add('converse-chatboxes', {
attrs.fullname = _converse.xmppstatus.get('fullname');
} else {
attrs.sender = 'them';
attrs.fullname = this.get('fullname');
attrs.fullname = this.get('fullname') || this.get('fullname')
}
}
_.each(sizzle(`x[xmlns="${Strophe.NS.OUTOFBAND}"]`, stanza), (xform) => {
......@@ -903,8 +905,8 @@ converse.plugins.add('converse-chatboxes', {
}
// Get chat box, but only create when the message has something to show to the user
const has_body = sizzle(`body, encrypted[xmlns="${Strophe.NS.OMEMO}"]`, stanza).length > 0,
chatbox_attrs = {'fullname': _.get(_converse.api.contacts.get(contact_jid), 'attributes.fullname')},
chatbox = this.getChatBox(contact_jid, chatbox_attrs, has_body);
roster_nick = _.get(_converse.api.contacts.get(contact_jid), 'attributes.nickname'),
chatbox = this.getChatBox(contact_jid, {'nickname': roster_nick}, has_body);
if (chatbox &&
!chatbox.findDuplicateFromOriginID(stanza) &&
......
......@@ -62,7 +62,7 @@
};
utils.openControlBox = function () {
var toggle = document.querySelector(".toggle-controlbox");
const toggle = document.querySelector(".toggle-controlbox");
if (!u.isVisible(document.querySelector("#controlbox"))) {
if (!u.isVisible(toggle)) {
u.removeClass('hidden', toggle);
......@@ -260,10 +260,45 @@
return this;
};
utils.waitForRoster = async function (_converse, type='current', length, include_nick=true) {
const iq = await utils.waitUntil(() =>
_.filter(
_converse.connection.IQ_stanzas,
iq => sizzle(`iq[type="get"] query[xmlns="${Strophe.NS.ROSTER}"]`, iq.nodeTree).length
).pop());
const result = $iq({
'to': _converse.connection.jid,
'type': 'result',
'id': iq.nodeTree.getAttribute('id')
}).c('query', {
'xmlns': 'jabber:iq:roster'
});
if (type === 'pending' || type === 'all') {
mock.pend_names.slice(0, length).map(name =>
result.c('item', {
jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
name: include_nick ? name : undefined,
subscription: 'to'
}).up()
);
} else if (type === 'current' || type === 'all') {
mock.cur_names.slice(0, length).map(name =>
result.c('item', {
jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
name: include_nick ? name : undefined,
subscription: 'both'
}).up()
);
}
_converse.connection._dataRecv(utils.createRequest(result));
await _converse.api.waitUntil('rosterContactsFetched');
};
utils.createGroupedContacts = function (converse) {
/* Create grouped contacts
*/
var i=0, j=0;
let i=0, j=0;
_.each(_.keys(mock.groups), function (name) {
j = i;
for (i=j; i<j+mock.groups[name]; i++) {
......
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