Make sure emojis are initialized before parsing a message

for emoji related data
This commit is contained in:
JC Brand 2020-07-13 15:45:37 +02:00
parent 3519bfe7c6
commit 4de9816f24
8 changed files with 31 additions and 21 deletions

View File

@ -1,4 +1,4 @@
/*global mock */
/*global mock, converse */
const _ = converse.env._;
const $msg = converse.env.$msg;

View File

@ -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);

View File

@ -1,4 +1,4 @@
/*global mock */
/*global mock, converse */
const Model = converse.env.Model;
const Strophe = converse.env.Strophe;

View File

@ -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'
);

View File

@ -1,4 +1,4 @@
/*global mock */
/*global mock, converse */
const { $iq, $pres, $msg, _, Strophe } = converse.env;
const u = converse.env.utils;

View File

@ -437,7 +437,7 @@ converse.plugins.add('converse-chat', {
* @async
* @private
* @method _converse.ChatRoom#queueMessage
* @param { XMLElement } stanza - The message stanza.
* @param { Promise<MessageAttributes> } 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)) {

View File

@ -1911,15 +1911,15 @@ converse.plugins.add('converse-muc', {
* @async
* @private
* @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) {
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);

View File

@ -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<MUCMessageAttributes|Error> }
*/
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),