浏览代码

Wait for emojis to be initialized before sending a message

JC Brand 2 年之前
父节点
当前提交
3d19def3e7

+ 1 - 0
src/headless/plugins/chat/model.js

@@ -845,6 +845,7 @@ const ChatBox = ModelWithContact.extend({
     },
 
     async getOutgoingMessageAttributes (attrs) {
+        await api.emojis.initialize();
         const is_spoiler = !!this.get('composing_spoiler');
         const origin_id = u.getUniqueId();
         const text = attrs?.body;

+ 1 - 2
src/headless/plugins/emoji/utils.js

@@ -94,7 +94,7 @@ export function getShortnameReferences (text) {
     if (!converse.emojis.initialized) {
         throw new Error(
             'getShortnameReferences called before emojis are initialized. '+
-            'To avoid this problem, first await the converse.emojis.initilaized_promise.'
+            'To avoid this problem, first await the converse.emojis.initialized_promise'
         );
     }
     const references = [...text.matchAll(converse.emojis.shortnames_regex)].filter(ref => ref[0].length > 0);
@@ -207,4 +207,3 @@ Object.assign(u, {
     isOnlyEmojis,
     shortnamesToUnicode,
 });
-

+ 1 - 0
src/headless/plugins/muc/muc.js

@@ -981,6 +981,7 @@ const ChatRoomMixin = {
     },
 
     async getOutgoingMessageAttributes (attrs) {
+        await api.emojis.initialize();
         const is_spoiler = this.get('composing_spoiler');
         let text = '', references;
         if (attrs?.body) {

+ 6 - 2
src/plugins/muc-views/tests/component.js

@@ -42,7 +42,8 @@ describe("The <converse-muc> component", function () {
         const muc_jid = 'lounge@montague.lit';
         const nick = 'romeo';
 
-        const muc_creation_promise = await api.rooms.open(muc_jid, {nick, 'hidden': true}, false);
+
+        const muc_creation_promise = api.rooms.open(muc_jid, {nick, 'hidden': true}, false);
         await mock.getRoomFeatures(_converse, muc_jid, []);
         await mock.receiveOwnMUCPresence(_converse, muc_jid, nick);
         await muc_creation_promise;
@@ -59,6 +60,7 @@ describe("The <converse-muc> component", function () {
         span_el.classList.add('conversejs');
         span_el.classList.add('converse-embedded');
 
+
         const muc_el = document.createElement('converse-muc');
         muc_el.classList.add('chatbox');
         muc_el.classList.add('chatroom');
@@ -73,8 +75,10 @@ describe("The <converse-muc> component", function () {
         const message = await u.waitUntil(() => muc_el.querySelector('converse-chat-message'));
         expect(message.model.get('body')).toBe('hello from the lounge!');
 
+        _converse.connection.sent_stanzas = [];
+
         const muc2_jid = 'bar@montague.lit';
-        const muc2_creation_promise = await api.rooms.open(muc2_jid, {nick, 'hidden': true}, false);
+        const muc2_creation_promise = api.rooms.open(muc2_jid, {nick, 'hidden': true}, false);
         await mock.getRoomFeatures(_converse, muc2_jid, []);
         await mock.receiveOwnMUCPresence(_converse, muc2_jid, nick);
         await muc2_creation_promise;