From 73bf2f88ea5be305f6d067e9281bab5cf83171e7 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Thu, 16 Jun 2016 17:20:11 +0200 Subject: [PATCH] Bugfix. The rooms.get method didn't work properly because the method it was delegating to was applicable to private chats only. --- src/converse-muc.js | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/converse-muc.js b/src/converse-muc.js index 50e2b2218..b88257ae0 100755 --- a/src/converse-muc.js +++ b/src/converse-muc.js @@ -1381,6 +1381,18 @@ } /* ------------------------------------------------------------ */ + var _transform = function (jid, nick, fetcher) { + jid = jid.toLowerCase(); + return converse.wrappedChatBox(fetcher({ + 'id': jid, + 'jid': jid, + 'name': Strophe.unescapeNode(Strophe.getNodeFromJid(jid)), + 'nick': nick, + 'type': 'chatroom', + 'box_id': b64_sha1(jid) + })); + }; + /* We extend the default converse.js API to add methods specific to MUC * chat rooms. @@ -1405,37 +1417,31 @@ } }, 'open': function (jids, nick) { + var fetcher = converse.chatboxviews.showChat.bind(converse.chatboxviews); if (!nick) { nick = Strophe.getNodeFromJid(converse.bare_jid); } if (typeof nick !== "string") { throw new TypeError('rooms.open: invalid nick, must be string'); } - var _transform = function (jid) { - jid = jid.toLowerCase(); - return converse.wrappedChatBox(converse.chatboxviews.showChat({ - 'id': jid, - 'jid': jid, - 'name': Strophe.unescapeNode(Strophe.getNodeFromJid(jid)), - 'nick': nick, - 'type': 'chatroom', - 'box_id': b64_sha1(jid) - })); - }; if (typeof jids === "undefined") { throw new TypeError('rooms.open: You need to provide at least one JID'); } else if (typeof jids === "string") { - return _transform(jids); + return _transform(jids, nick, fetcher); } - return _.map(jids, _transform); + return _.map(jids, _.partial(_transform, _, nick, fetcher)); }, - 'get': function (jids) { + 'get': function (jids, nick) { + var fetcher = converse.chatboxviews.getChatBox.bind(converse.chatboxviews); + if (!nick) { + nick = Strophe.getNodeFromJid(converse.bare_jid); + } if (typeof jids === "undefined") { throw new TypeError("rooms.get: You need to provide at least one JID"); } else if (typeof jids === "string") { - return converse.wrappedChatBox(converse.chatboxes.getChatBox(jids, true)); + return _transform(jids, nick, fetcher); } - return _.map(jids, _.partial(converse.wrappedChatBox, _.bind(converse.chatboxes.getChatBox, converse.chatboxes, _, true))); + return _.map(jids, _.partial(_transform, _, nick, fetcher)); } } });