Last active
August 29, 2015 14:14
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
@rui-wang-codebase
Sorry for the late response, Gist doesn't ping users when they're mentioned here, take a look here conversejs/converse.js#156 (comment) the API was changed a bit.
Cheers,
Guillermo
@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
@gbonvehi could you please help me? I am new to javascript and could not get the plugin working. is there any instruction on how to use that?
Here is my webpage, I actually didn't use the plugin, and directly try to use it as a function. (I'm still not very clear about the plugin mechanism. After many errors trying, I chose this way).
and it has an error: "ERROR: User connection callback caused an exception: TypeError: converse.chatboxes is undefined”
but I look at converse.js, that should have been created by the converse.initialize function...:-(
any input will be greatly appreciated.