diff --git a/spec/chatbox.js b/spec/chatbox.js index 1e388fabe..36aa66cf4 100644 --- a/spec/chatbox.js +++ b/spec/chatbox.js @@ -1,4 +1,4 @@ -/*global mock */ +/*global mock, converse */ const _ = converse.env._; const $msg = converse.env.$msg; diff --git a/spec/controlbox.js b/spec/controlbox.js index 77c25c7aa..784e9e8db 100644 --- a/spec/controlbox.js +++ b/spec/controlbox.js @@ -1,10 +1,10 @@ -/*global mock */ +/*global mock, converse */ -const _ = converse.env._, - $msg = converse.env.$msg, - u = converse.env.utils, - Strophe = converse.env.Strophe, - sizzle = converse.env.sizzle; +const _ = converse.env._; +const $msg = converse.env.$msg; +const u = converse.env.utils; +const Strophe = converse.env.Strophe; +const sizzle = converse.env.sizzle; describe("The Controlbox", function () { @@ -90,7 +90,7 @@ describe("The Controlbox", function () { _converse.handleMessageStanza(msg); await u.waitUntil(() => _converse.rosterview.el.querySelectorAll(".msgs-indicator").length); spyOn(chatview.model, 'incrementUnreadMsgCounter').and.callThrough(); - expect(_converse.chatboxviews.el.querySelector('.restore-chat .message-count').textContent).toBe('1'); + await u.waitUntil(() => _converse.chatboxviews.el.querySelector('.restore-chat .message-count')?.textContent === '1'); expect(_converse.rosterview.el.querySelector('.msgs-indicator').textContent).toBe('1'); msg = $msg({ @@ -102,7 +102,7 @@ describe("The Controlbox", function () { .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree(); _converse.handleMessageStanza(msg); await u.waitUntil(() => chatview.model.incrementUnreadMsgCounter.calls.count()); - expect(_converse.chatboxviews.el.querySelector('.restore-chat .message-count').textContent).toBe('2'); + await u.waitUntil(() => _converse.chatboxviews.el.querySelector('.restore-chat .message-count')?.textContent === '2'); expect(_converse.rosterview.el.querySelector('.msgs-indicator').textContent).toBe('2'); chatview.model.set({'minimized': false}); expect(_converse.chatboxviews.el.querySelector('.restore-chat .message-count')).toBe(null); diff --git a/spec/mam.js b/spec/mam.js index 597f6f7e9..779300bc4 100644 --- a/spec/mam.js +++ b/spec/mam.js @@ -1,4 +1,4 @@ -/*global mock */ +/*global mock, converse */ const Model = converse.env.Model; const Strophe = converse.env.Strophe; diff --git a/spec/muc_messages.js b/spec/muc_messages.js index bfc2e4071..b3f3c2924 100644 --- a/spec/muc_messages.js +++ b/spec/muc_messages.js @@ -1,4 +1,4 @@ -/*global mock */ +/*global mock, converse */ const { Promise, Strophe, $msg, $pres, sizzle, stanza_utils } = converse.env; const u = converse.env.utils; @@ -334,7 +334,7 @@ describe("A Groupchat Message", function () { }) .c('x', {xmlns: Strophe.NS.MUC_USER}) .c('item', { - 'affiliation': 'none', + 'affiliation': 'owner', 'jid': 'newguy@montague.lit/_converse.js-290929789', 'role': 'participant' }).tree(); @@ -367,6 +367,7 @@ describe("A Groupchat Message", function () { const view = _converse.api.chatviews.get(muc_jid); spyOn(converse.env.log, 'error'); await view.model.handleMAMResult({ 'messages': [msg] }); + await u.waitUntil(() => converse.env.log.error.calls.count()); expect(converse.env.log.error).toHaveBeenCalledWith( 'Invalid Stanza: MUC messages SHOULD NOT be XEP-0280 carbon copied' ); diff --git a/spec/omemo.js b/spec/omemo.js index d357c8776..c75c41bed 100644 --- a/spec/omemo.js +++ b/spec/omemo.js @@ -1,4 +1,4 @@ -/*global mock */ +/*global mock, converse */ const { $iq, $pres, $msg, _, Strophe } = converse.env; const u = converse.env.utils; diff --git a/src/headless/converse-chat.js b/src/headless/converse-chat.js index 7a2413e15..a4b73d2f4 100644 --- a/src/headless/converse-chat.js +++ b/src/headless/converse-chat.js @@ -437,7 +437,7 @@ converse.plugins.add('converse-chat', { * @async * @private * @method _converse.ChatRoom#queueMessage - * @param { XMLElement } stanza - The message stanza. + * @param { Promise } attrs - A promise which resolves to the message attributes */ queueMessage (attrs) { this.msg_chain = (this.msg_chain || this.messages.fetched); @@ -445,6 +445,12 @@ converse.plugins.add('converse-chat', { return this.msg_chain; }, + /** + * @async + * @private + * @method _converse.ChatRoom#onMessage + * @param { MessageAttributes } attrs_promse - A promise which resolves to the message attributes. + */ async onMessage (attrs) { attrs = await attrs; if (u.isErrorObject(attrs)) { diff --git a/src/headless/converse-muc.js b/src/headless/converse-muc.js index 9d6271acc..0fe7814f4 100644 --- a/src/headless/converse-muc.js +++ b/src/headless/converse-muc.js @@ -1911,15 +1911,15 @@ converse.plugins.add('converse-muc', { * @async * @private * @method _converse.ChatRoom#queueMessage - * @param { XMLElement } stanza - The message stanza. + * @param { Promise } attrs - A promise which resolves to the message attributes */ - queueMessage (stanza) { + queueMessage (attrs) { if (this.messages?.fetched) { this.msg_chain = (this.msg_chain || this.messages.fetched); - this.msg_chain = this.msg_chain.then(() => this.onMessage(stanza)); + this.msg_chain = this.msg_chain.then(() => this.onMessage(attrs)); return this.msg_chain; } else { - this.message_queue.push(stanza); + this.message_queue.push(attrs); return Promise.resolve(); } }, @@ -1983,9 +1983,10 @@ converse.plugins.add('converse-muc', { * should be called. * @private * @method _converse.ChatRoom#onMessage - * @param { MessageAttributes } attrs - The message attributes + * @param { MessageAttributes } attrs - A promise which resolves to the message attributes. */ async onMessage (attrs) { + attrs = await attrs; if (u.isErrorObject(attrs)) { attrs.stanza && log.error(attrs.stanza); return log.error(attrs.message); diff --git a/src/headless/utils/stanza.js b/src/headless/utils/stanza.js index 3f1eebbc1..79f48467b 100644 --- a/src/headless/utils/stanza.js +++ b/src/headless/utils/stanza.js @@ -523,6 +523,7 @@ const st = { return new StanzaParseError(`Invalid Stanza: Forged MAM message from ${from}`, stanza); } } + await api.emojis.initialize(); attrs = Object.assign({ 'message': attrs.body || attrs.error, // TODO: Remove and use body and error attributes instead 'is_only_emojis': attrs.body ? u.isOnlyEmojis(attrs.body) : false, @@ -543,9 +544,9 @@ const st = { * message stanza, if it was contained, otherwise it's the message stanza itself. * @param { _converse.ChatRoom } chatbox * @param { _converse } _converse - * @returns { (MUCMessageAttributes|Error) } + * @returns { Promise } */ - parseMUCMessage (stanza, chatbox, _converse) { + async parseMUCMessage (stanza, chatbox, _converse) { const err = rejectUnencapsulatedForward(stanza); if (err) { return err; @@ -650,6 +651,7 @@ const st = { getEncryptionAttributes(stanza, _converse) ); + await api.emojis.initialize(); attrs = Object.assign({ 'is_only_emojis': attrs.body ? u.isOnlyEmojis(attrs.body) : false, 'is_receipt_request': isReceiptRequest(stanza, attrs),