Commit 4de9816f authored by JC Brand's avatar JC Brand

Make sure emojis are initialized before parsing a message

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