Commit 9f0dfcdb authored by JC Brand's avatar JC Brand

Wait before firing `roomsAutoJoined` event

parent f7ef334f
...@@ -2652,25 +2652,24 @@ converse.plugins.add('converse-muc', { ...@@ -2652,25 +2652,24 @@ converse.plugins.add('converse-muc', {
return api.rooms.get(jid, attrs, true); return api.rooms.get(jid, attrs, true);
}; };
/** /* Automatically join groupchats, based on the
* Automatically join groupchats, based on the
* "auto_join_rooms" configuration setting, which is an array * "auto_join_rooms" configuration setting, which is an array
* of strings (groupchat JIDs) or objects (with groupchat JID and other * of strings (groupchat JIDs) or objects (with groupchat JID and other settings).
* settings).
*/ */
function autoJoinRooms () { async function autoJoinRooms () {
api.settings.get('auto_join_rooms').forEach(groupchat => { await Promise.all(api.settings.get('auto_join_rooms').map(muc => {
if (isString(groupchat)) { if (isString(muc)) {
if (_converse.chatboxes.where({'jid': groupchat}).length) { if (_converse.chatboxes.where({'jid': muc}).length) {
return; return Promise.resolve();
} }
api.rooms.open(groupchat); return api.rooms.open(muc);
} else if (isObject(groupchat)) { } else if (isObject(muc)) {
api.rooms.open(groupchat.jid, clone(groupchat)); return api.rooms.open(muc.jid, clone(muc));
} else { } else {
log.error('Invalid groupchat criteria specified for "auto_join_rooms"'); log.error('Invalid muc criteria specified for "auto_join_rooms"');
return Promise.resolve();
} }
}); }));
/** /**
* Triggered once any rooms that have been configured to be automatically joined, * Triggered once any rooms that have been configured to be automatically joined,
* specified via the _`auto_join_rooms` setting, have been entered. * specified via the _`auto_join_rooms` setting, have been entered.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment