Commit 95a0b91a authored by JC Brand's avatar JC Brand

Update 'rooms' api to allow user to pass in room attributes.

parent 1ee7d06a
...@@ -1396,7 +1396,7 @@ ...@@ -1396,7 +1396,7 @@
return true; return true;
}, },
getChatBox: function (jid, create) { getChatBox: function (jid, create, attrs) {
/* Returns a chat box or optionally return a newly /* Returns a chat box or optionally return a newly
* created one if one doesn't exist. * created one if one doesn't exist.
* *
...@@ -1413,14 +1413,14 @@ ...@@ -1413,14 +1413,14 @@
converse.log('Could not get roster item for JID '+bare_jid, 'error'); converse.log('Could not get roster item for JID '+bare_jid, 'error');
return; return;
} }
chatbox = this.create({ chatbox = this.create(_.extend({
'id': bare_jid, 'id': bare_jid,
'jid': bare_jid, 'jid': bare_jid,
'fullname': _.isEmpty(roster_item.get('fullname'))? jid: roster_item.get('fullname'), 'fullname': _.isEmpty(roster_item.get('fullname'))? jid: roster_item.get('fullname'),
'image_type': roster_item.get('image_type'), 'image_type': roster_item.get('image_type'),
'image': roster_item.get('image'), 'image': roster_item.get('image'),
'url': roster_item.get('url') 'url': roster_item.get('url')
}); }, attrs || {}));
} }
return chatbox; return chatbox;
} }
......
...@@ -1602,16 +1602,15 @@ ...@@ -1602,16 +1602,15 @@
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
var _transform = function (jid, nick, fetcher) { var _transform = function (jid, attrs, fetcher) {
jid = jid.toLowerCase(); jid = jid.toLowerCase();
return converse.wrappedChatBox(fetcher({ return converse.wrappedChatBox(fetcher(_.extend({
'id': jid, 'id': jid,
'jid': jid, 'jid': jid,
'name': Strophe.unescapeNode(Strophe.getNodeFromJid(jid)), 'name': Strophe.unescapeNode(Strophe.getNodeFromJid(jid)),
'nick': nick,
'type': 'chatroom', 'type': 'chatroom',
'box_id': b64_sha1(jid) 'box_id': b64_sha1(jid)
})); }, attrs)));
}; };
...@@ -1637,16 +1636,26 @@ ...@@ -1637,16 +1636,26 @@
}); });
} }
}, },
'open': function (jids, nick) { 'open': function (jids, attrs) {
if (typeof attrs === "string") {
attrs = {'nick': attrs};
} else if (typeof attrs === "undefined") {
attrs = {};
}
var fetcher = converse.chatboxviews.showChat.bind(converse.chatboxviews); var fetcher = converse.chatboxviews.showChat.bind(converse.chatboxviews);
if (typeof jids === "undefined") { if (typeof jids === "undefined") {
throw new TypeError('rooms.open: You need to provide at least one JID'); throw new TypeError('rooms.open: You need to provide at least one JID');
} else if (typeof jids === "string") { } else if (typeof jids === "string") {
return _transform(jids, nick, fetcher); return _transform(jids, attrs, fetcher);
} }
return _.map(jids, _.partial(_transform, _, nick, fetcher)); return _.map(jids, _.partial(_transform, _, attrs, fetcher));
}, },
'get': function (jids, nick, create) { 'get': function (jids, attrs, create) {
if (typeof attrs === "string") {
attrs = {'nick': attrs};
} else if (typeof attrs === "undefined") {
attrs = {};
}
if (typeof jids === "undefined") { if (typeof jids === "undefined") {
var result = []; var result = [];
converse.chatboxes.each(function (chatbox) { converse.chatboxes.each(function (chatbox) {
...@@ -1657,13 +1666,13 @@ ...@@ -1657,13 +1666,13 @@
return result; return result;
} }
var fetcher = _.partial(converse.chatboxviews.getChatBox.bind(converse.chatboxviews), _, create); var fetcher = _.partial(converse.chatboxviews.getChatBox.bind(converse.chatboxviews), _, create);
if (!nick) { if (!attrs.nick) {
nick = Strophe.getNodeFromJid(converse.bare_jid); attrs.nick = Strophe.getNodeFromJid(converse.bare_jid);
} }
if (typeof jids === "string") { if (typeof jids === "string") {
return _transform(jids, nick, fetcher); return _transform(jids, attrs, fetcher);
} }
return _.map(jids, _.partial(_transform, _, nick, fetcher)); return _.map(jids, _.partial(_transform, _, attrs, fetcher));
} }
} }
}); });
......
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