Commit bad815b4 authored by JC Brand's avatar JC Brand

Bugfix. Don't create multiple RosterContactView objects

parent 77f38bb4
...@@ -212,6 +212,7 @@ describe("Message Archive Management", function () { ...@@ -212,6 +212,7 @@ describe("Message Archive Management", function () {
await mock.waitForRoster(_converse, 'current', 1); await mock.waitForRoster(_converse, 'current', 1);
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit'; const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
await mock.openChatBoxFor(_converse, contact_jid); await mock.openChatBoxFor(_converse, contact_jid);
const view = _converse.chatboxviews.get(contact_jid);
await mock.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, null, [Strophe.NS.MAM]); await mock.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, null, [Strophe.NS.MAM]);
const sent_IQs = _converse.connection.IQ_stanzas; const sent_IQs = _converse.connection.IQ_stanzas;
const stanza = await u.waitUntil(() => sent_IQs.filter(iq => iq.querySelector(`iq[type="set"] query[xmlns="${Strophe.NS.MAM}"]`)).pop()); const stanza = await u.waitUntil(() => sent_IQs.filter(iq => iq.querySelector(`iq[type="set"] query[xmlns="${Strophe.NS.MAM}"]`)).pop());
...@@ -252,7 +253,6 @@ describe("Message Archive Management", function () { ...@@ -252,7 +253,6 @@ describe("Message Archive Management", function () {
.c('count').t('16'); .c('count').t('16');
_converse.connection._dataRecv(mock.createRequest(iq_result)); _converse.connection._dataRecv(mock.createRequest(iq_result));
const view = _converse.chatboxviews.get(contact_jid);
await new Promise(resolve => view.once('messageInserted', resolve)); await new Promise(resolve => view.once('messageInserted', resolve));
expect(view.model.messages.length).toBe(1); expect(view.model.messages.length).toBe(1);
expect(view.model.messages.at(0).get('message')).toBe("Thrice the brinded cat hath mew'd."); expect(view.model.messages.at(0).get('message')).toBe("Thrice the brinded cat hath mew'd.");
......
...@@ -300,7 +300,6 @@ converse.plugins.add('converse-rosterview', { ...@@ -300,7 +300,6 @@ converse.plugins.add('converse-rosterview', {
this.listenTo(this.model, "change", this.debouncedRender); this.listenTo(this.model, "change", this.debouncedRender);
this.listenTo(this.model, "destroy", this.remove); this.listenTo(this.model, "destroy", this.remove);
this.listenTo(this.model, "highlight", this.highlight); this.listenTo(this.model, "highlight", this.highlight);
this.listenTo(this.model, "open", this.openChat);
this.listenTo(this.model, "remove", this.remove); this.listenTo(this.model, "remove", this.remove);
this.listenTo(this.model, 'vcard:change', this.debouncedRender); this.listenTo(this.model, 'vcard:change', this.debouncedRender);
this.listenTo(this.model.presence, "change:show", this.debouncedRender); this.listenTo(this.model.presence, "change:show", this.debouncedRender);
...@@ -453,8 +452,7 @@ converse.plugins.add('converse-rosterview', { ...@@ -453,8 +452,7 @@ converse.plugins.add('converse-rosterview', {
openChat (ev) { openChat (ev) {
if (ev && ev.preventDefault) { ev.preventDefault(); } if (ev && ev.preventDefault) { ev.preventDefault(); }
const attrs = this.model.attributes; this.model.openChat();
api.chats.open(attrs.jid, attrs, true);
}, },
async removeContact (ev) { async removeContact (ev) {
......
...@@ -248,6 +248,11 @@ converse.plugins.add('converse-roster', { ...@@ -248,6 +248,11 @@ converse.plugins.add('converse-roster', {
this.presence = _converse.presences.findWhere({'jid': jid}) || _converse.presences.create({'jid': jid}); this.presence = _converse.presences.findWhere({'jid': jid}) || _converse.presences.create({'jid': jid});
}, },
openChat () {
const attrs = this.attributes;
api.chats.open(attrs.jid, attrs, true);
},
getDisplayName () { getDisplayName () {
// Gets overridden in converse-vcard where the fullname is may be returned // Gets overridden in converse-vcard where the fullname is may be returned
if (this.get('nickname')) { if (this.get('nickname')) {
......
...@@ -132,17 +132,15 @@ window.addEventListener('converse-loaded', () => { ...@@ -132,17 +132,15 @@ window.addEventListener('converse-loaded', () => {
}; };
mock.openChatBoxes = function (converse, amount) { mock.openChatBoxes = function (converse, amount) {
const views = [];
for (let i=0; i<amount; i++) { for (let i=0; i<amount; i++) {
const jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@montague.lit'; const jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@montague.lit';
views.push(converse.roster.get(jid).trigger("open")); converse.roster.get(jid).openChat();
} }
return views;
}; };
mock.openChatBoxFor = async function (_converse, jid) { mock.openChatBoxFor = async function (_converse, jid) {
await _converse.api.waitUntil('rosterContactsFetched'); await _converse.api.waitUntil('rosterContactsFetched');
_converse.roster.get(jid).trigger("open"); _converse.roster.get(jid).openChat();
return u.waitUntil(() => _converse.chatboxviews.get(jid), 1000); return u.waitUntil(() => _converse.chatboxviews.get(jid), 1000);
}; };
......
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