Commit 789b47dd authored by JC Brand's avatar JC Brand

Bugfix. Don't create view for chat which fails validation

Use-case is when an invalid MUC gets opened in singleton mode.
Without this fix a new chat with spinner appears, even though it
shouldn't.
parent a6567504
......@@ -2152,6 +2152,7 @@ converse.plugins.add('converse-muc-views', {
}
}
/************************ BEGIN Event Handlers ************************/
_converse.api.listen.on('chatBoxViewsInitialized', () => {
......@@ -2161,12 +2162,16 @@ converse.plugins.add('converse-muc-views', {
}
_converse.chatboxviews.delegate('click', 'a.open-chatroom', openChatRoomFromURIClicked);
const that = _converse.chatboxviews;
_converse.chatboxes.on('add', item => {
if (!that.get(item.get('id')) && item.get('type') === _converse.CHATROOMS_TYPE) {
return that.add(item.get('id'), new _converse.ChatRoomView({'model': item}));
function addView (model) {
const views = _converse.chatboxviews;
if (!views.get(model.get('id')) &&
model.get('type') === _converse.CHATROOMS_TYPE &&
model.isValid()
) {
return views.add(model.get('id'), new _converse.ChatRoomView({'model': model}));
}
});
}
_converse.chatboxes.on('add', addView);
});
_converse.api.listen.on('clearSession', () => {
......
......@@ -372,9 +372,12 @@ converse.plugins.add('converse-chatboxes', {
if (!attrs.jid) {
return 'Ignored ChatBox without JID';
}
const auto_join = _converse.auto_join_private_chats.concat(_converse.auto_join_rooms);
const room_jids = _converse.auto_join_rooms.map(s => _.isObject(s) ? s.jid : s);
const auto_join = _converse.auto_join_private_chats.concat(room_jids);
if (_converse.singleton && !_.includes(auto_join, attrs.jid)) {
return "Ignored ChatBox that's not being auto joined in singleton mode";
const msg = `${attrs.jid} is not allowed because singleton is true and it's not being auto_joined`;
_converse.log(msg, Strophe.LogLevel.WARN);
return msg;
}
},
......@@ -1119,6 +1122,10 @@ converse.plugins.add('converse-chatboxes', {
_converse.log(response.responseText);
}
});
if (!chatbox.isValid()) {
chatbox.destroy();
return null;
}
}
return chatbox;
}
......@@ -1269,9 +1276,15 @@ converse.plugins.add('converse-chatboxes', {
if (_.isString(jids)) {
const chat = await _converse.api.chats.create(jids, attrs);
return chat.maybeShow(force);
if (chat) {
return chat.maybeShow(force);
}
return chat;
} else if (Array.isArray(jids)) {
return Promise.all(jids.map(j => _converse.api.chats.create(j, attrs).then(c => c.maybeShow(force))));
return Promise.all(
jids.map(j => _converse.api.chats.create(j, attrs).then(c => c ? c.maybeShow(force) : null))
.filter(c => c)
);
}
const err_msg = "chats.open: You need to provide at least one JID";
_converse.log(err_msg, Strophe.LogLevel.ERROR);
......
......@@ -1837,14 +1837,18 @@ converse.plugins.add('converse-muc', {
* }
* );
*/
'open': async function (jids, attrs, force=false) {
async open (jids, attrs, force=false) {
await _converse.api.waitUntil('chatBoxesFetched');
if (_.isUndefined(jids)) {
const err_msg = 'rooms.open: You need to provide at least one JID';
_converse.log(err_msg, Strophe.LogLevel.ERROR);
throw(new TypeError(err_msg));
} else if (_.isString(jids)) {
return _converse.api.rooms.create(jids, attrs).maybeShow(force);
const room = _converse.api.rooms.create(jids, attrs);
if (room) {
room.maybeShow(force);
}
return room;
} else {
return _.map(jids, jid => _converse.api.rooms.create(jid, attrs).maybeShow(force));
}
......@@ -1873,7 +1877,7 @@ converse.plugins.add('converse-muc', {
* )
* });
*/
'get' (jids, attrs, create) {
get (jids, attrs, create) {
if (_.isString(attrs)) {
attrs = {'nick': attrs};
} else if (_.isUndefined(attrs)) {
......
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