-
-
Save knixeur/376078bd6b702255a7e7 to your computer and use it in GitHub Desktop.
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); |
@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).
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>converse.js</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<link rel="stylesheet" media="screen" href="converse.css">
<script data-main="main" src="require.js"></script>
<script src="converse.js"></script>
</head>
<body>
<div id="conversejs"></div>
<script>
require(['converse'], function (converse) {
converse.initialize({
allow_otr: true,
auto_list_rooms: false,
auto_subscribe: false,
bosh_service_url: 'http://127.0.0.1:5280/http-bind/',
debug: true,
show_controlbox_by_default: true,
hide_muc_server: false,
i18n: locales['en'],
prebind: false,
show_controlbox_by_default: true,
xhr_user_search: false,
});
var jids = [ '[email protected]' ];
converse.listen.on('ready', function(event) {
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);
});
console.log(converse);
});
</script>
</body>
</html>
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.
@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
Check https://gist.github.com/gbonvehi/a9d8882c8bf536693e3a