diff --git a/src/headless/plugins/muc/muc.js b/src/headless/plugins/muc/muc.js index 06ab58983..8d478cb2c 100644 --- a/src/headless/plugins/muc/muc.js +++ b/src/headless/plugins/muc/muc.js @@ -1908,10 +1908,20 @@ const ChatRoomMixin = { return true; }, + /** + * When sending a status update presence (i.e. based on the `` + * element), we need to first make sure that the MUC is connected, + * otherwise we will get an error from the MUC service. + * @method _converse.ChatRoom#sendStatusPresence + */ + async sendStatusPresence (presence) { + await this.rejoinIfNecessary(); + api.send(presence); + }, + /** * Check whether we're still joined and re-join if not * @async - * @private * @method _converse.ChatRoom#rejoinIfNecessary */ async rejoinIfNecessary () { diff --git a/src/headless/plugins/status/api.js b/src/headless/plugins/status/api.js index eab36280d..bfda8caad 100644 --- a/src/headless/plugins/status/api.js +++ b/src/headless/plugins/status/api.js @@ -18,28 +18,20 @@ export default { */ async send (type, to, status, child_nodes) { await api.waitUntil('statusInitialized'); - + if (child_nodes && !Array.isArray(child_nodes)) { + child_nodes = [child_nodes]; + } const model= _converse.xmppstatus const presence = await model.constructPresence(type, to, status); - if (child_nodes) { - if (!Array.isArray(child_nodes)) { - child_nodes = [child_nodes]; - } - child_nodes.map(c => c?.tree() ?? c).forEach(c => presence.cnode(c).up()); - } + child_nodes?.map(c => c?.tree() ?? c).forEach(c => presence.cnode(c).up()); api.send(presence); if (['away', 'chat', 'dnd', 'online', 'xa', undefined].includes(type)) { const mucs = await api.rooms.get(); mucs.forEach(async muc => { const presence = await model.constructPresence(type, muc.getRoomJIDAndNick(), status); - if (child_nodes) { - if (!Array.isArray(child_nodes)) { - child_nodes = [child_nodes]; - } - child_nodes.map(c => c?.tree() ?? c).forEach(c => presence.cnode(c).up()); - } - api.send(presence); + child_nodes?.map(c => c?.tree() ?? c).forEach(c => presence.cnode(c).up()); + muc.sendStatusPresence(presence); }); } }