Make sure we're connected to MUC before sending status update

This commit is contained in:
JC Brand 2021-12-17 20:54:18 +01:00
parent c3aafdf341
commit 6ee3ddbc8c
2 changed files with 17 additions and 15 deletions

View File

@ -1908,10 +1908,20 @@ const ChatRoomMixin = {
return true;
},
/**
* When sending a status update presence (i.e. based on the `<show>`
* 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 () {

View File

@ -18,28 +18,20 @@ export default {
*/
async send (type, to, status, child_nodes) {
await api.waitUntil('statusInitialized');
const model= _converse.xmppstatus
const presence = await model.constructPresence(type, to, status);
if (child_nodes) {
if (!Array.isArray(child_nodes)) {
if (child_nodes && !Array.isArray(child_nodes)) {
child_nodes = [child_nodes];
}
child_nodes.map(c => c?.tree() ?? c).forEach(c => presence.cnode(c).up());
}
const model= _converse.xmppstatus
const presence = await model.constructPresence(type, to, status);
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);
});
}
}