conversejs / converse.js

Web-based XMPP/Jabber chat client written in JavaScript
http://conversejs.org
Mozilla Public License 2.0
3.07k stars 768 forks source link

beforeMessageBodyTransformed plugin hooks (and others) are not respecting async/await #3342

Open OCDolan opened 7 months ago

OCDolan commented 7 months ago

Describe the bug beforeMessageBodyTransformed plugin hooks (and others) are not respecting async/await

To Reproduce Steps to reproduce the behavior: _converse.api.listen.on('beforeMessageBodyTransformed', async (text, view) => { console.log("beforeMessageBodyTransformed"); await something(text); // This await doesn't work, because beforeMessageBodyTransformed returns immedietly! });

Expected behavior beforeMessageBodyTransformed should wait untill await something(text) finishes before starting afterMessageBodyTransformed

Screenshots None

Environment (please complete the following information):

Additional context None

!!! CAUSE + HOW TO FIX !!! The cause of the bug is a capitalization error in rich-text.js. await api.trigger('beforeMessageBodyTransformed', this, { 'Synchronous': true }); should be await api.trigger('beforeMessageBodyTransformed', this, { 'synchronous': true }); synchronous not Synchronous!

I think this affects several plugin hooks, not just this one i've found, it might be worth doing a regex to find all instances of this bug.

Thanks!

OCDolan commented 7 months ago

FYI i've found it in 5 places - chatBoxInitialized, messageInitialized, chatRoomInitialized, rosterContactInitialized, afterMessageBodyTransformed