xmpp.chapril.org-conversejs/src/converse-muc-embedded.js

70 lines
2.7 KiB
JavaScript
Raw Normal View History

2017-02-02 19:29:38 +01:00
// Converse.js (A browser based XMPP chat client)
// http://conversejs.org
//
// Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com>
// Licensed under the Mozilla Public License (MPLv2)
//
2017-01-16 22:15:07 +01:00
(function (root, factory) {
define(["converse-core", "converse-muc"], factory);
2017-01-16 22:15:07 +01:00
}(this, function (converse) {
"use strict";
2017-04-28 19:57:23 +02:00
var Backbone = converse.env.Backbone,
_ = converse.env._;
2017-01-16 22:15:07 +01:00
converse.plugins.add('converse-muc-embedded', {
overrides: {
// Overrides mentioned here will be picked up by converse.js's
// plugin architecture they will replace existing methods on the
// relevant objects or classes.
//
// New functions which don't exist yet can also be added.
ChatBoxes: {
onConnected: function () {
// Override to avoid storing or fetching chat boxes from session
// storage.
var _converse = this.__super__._converse;
this.browserStorage = new Backbone.BrowserStorage[_converse.storage](
converse.env.b64_sha1('converse.chatboxes-'+_converse.bare_jid));
this.registerMessageHandler();
/* This is disabled:
*
* this.fetch({
* add: true,
* success: this.onChatBoxesFetched.bind(this)
* });
*/
this.onChatBoxesFetched(new Backbone.Collection());
}
},
ChatRoomView: {
insertIntoDOM: function () {
if (!document.body.contains(this.el)) {
var container = document.querySelector('#converse-embedded-chat');
container.innerHTML = '';
container.appendChild(this.el);
}
2017-01-16 22:15:07 +01:00
return this;
}
}
},
initialize: function () {
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
var _converse = this._converse;
if (!_.isArray(_converse.auto_join_rooms)) {
throw new Error("converse-muc-embedded: auto_join_rooms must be an Array");
}
if (_converse.auto_join_rooms.length !== 1) {
throw new Error("converse-muc-embedded: It doesn't make "+
"sense to have the auto_join_rooms setting to zero or "+
"more then one, since only one chat room can be open "+
"at any time.")
}
}
2017-01-16 22:15:07 +01:00
});
}));