Skip to content

Instantly share code, notes, and snippets.

@knixeur
Last active August 29, 2015 14:14
Show Gist options
  • Save knixeur/376078bd6b702255a7e7 to your computer and use it in GitHub Desktop.
Save knixeur/376078bd6b702255a7e7 to your computer and use it in GitHub Desktop.
A simple plugin that let's you open chats or join rooms when converse is initialized
function converseAutoJoinChatPlugin( converse ) {
var jids = [ '[email protected]' ];
converse.on('ready', function() {
var _transform = function (jid) {
var chatbox = converse.chatboxes.get(jid);
if (!chatbox) {
var roster_item = converse.roster.get(jid);
if (roster_item === undefined) {
// Assume MUC
converse.chatboxes.create({
'id': jid,
'jid': jid,
'name': Strophe.unescapeNode(Strophe.getNodeFromJid(jid)),
'nick': Strophe.unescapeNode(Strophe.getNodeFromJid(converse.jid)),
'chatroom': true,
'box_id' : b64_sha1(jid)
});
}
converse.chatboxes.create({
'id': jid,
'jid': jid,
'fullname': _.isEmpty(roster_item.get('fullname'))? jid: roster_item.get('fullname'),
'image_type': roster_item.get('image_type'),
'image': roster_item.get('image'),
'url': roster_item.get('url')
});
}
};
if (typeof jids === "string") {
_transform(jids);
}
_.map(jids, _transform);
});
};
converse.plugins.add('converseAutoJoinChatPlugin', converseAutoJoinChatPlugin);
@themaverik
Copy link

@gbonvehi, thanks for the plugin
I want to develop a plugin for filtering messages using the 'message' event. can you help me with this...thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment