2018-04-11 15:29:41 +02:00
|
|
|
/**
|
|
|
|
* Adds Support for Http File Upload (XEP-0363)
|
|
|
|
*
|
|
|
|
*/
|
2018-03-28 18:38:22 +02:00
|
|
|
(function (root, factory) {
|
2018-03-29 20:22:05 +02:00
|
|
|
define([
|
|
|
|
"converse-core",
|
|
|
|
"tpl!toolbar_fileupload"
|
|
|
|
], factory);
|
|
|
|
}(this, function (converse, tpl_toolbar_fileupload) {
|
2018-03-28 18:38:22 +02:00
|
|
|
"use strict";
|
|
|
|
|
2018-03-29 16:12:19 +02:00
|
|
|
const { Promise, Strophe, _ } = converse.env;
|
|
|
|
const u = converse.env.utils;
|
|
|
|
|
|
|
|
Strophe.addNamespace('HTTPUPLOAD', 'urn:xmpp:http:upload:0');
|
|
|
|
|
2018-03-28 18:38:22 +02:00
|
|
|
converse.plugins.add('converse-http-file-upload', {
|
2018-03-29 16:12:19 +02:00
|
|
|
/* Plugin dependencies are other plugins which might be
|
|
|
|
* overridden or relied upon, and therefore need to be loaded before
|
|
|
|
* this plugin.
|
|
|
|
*
|
|
|
|
* If the setting "strict_plugin_dependencies" is set to true,
|
|
|
|
* an error will be raised if the plugin is not found. By default it's
|
|
|
|
* false, which means these plugins are only loaded opportunistically.
|
|
|
|
*
|
|
|
|
* NB: These plugins need to have already been loaded via require.js.
|
|
|
|
*/
|
2018-04-11 17:09:32 +02:00
|
|
|
dependencies: ["converse-chatboxes", "converse-chatview", "converse-muc-views"],
|
2018-03-29 16:12:19 +02:00
|
|
|
|
|
|
|
overrides: {
|
|
|
|
ChatBoxView: {
|
2018-04-11 17:09:32 +02:00
|
|
|
events: {
|
2018-04-14 07:50:29 +02:00
|
|
|
'click .upload-file': 'toggleFileUpload',
|
2018-04-14 21:13:02 +02:00
|
|
|
'change input.fileupload': 'onFileSelection'
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
toggleFileUpload (ev) {
|
|
|
|
this.el.querySelector('input.fileupload').click();
|
|
|
|
},
|
|
|
|
|
|
|
|
onFileSelection (evt) {
|
|
|
|
this.model.sendFiles(evt.target.files);
|
2018-04-11 17:09:32 +02:00
|
|
|
},
|
|
|
|
|
2018-03-29 16:12:19 +02:00
|
|
|
addFileUploadButton (options) {
|
2018-03-29 20:22:05 +02:00
|
|
|
const { __ } = this.__super__._converse;
|
|
|
|
this.el.querySelector('.chat-toolbar').insertAdjacentHTML(
|
|
|
|
'beforeend',
|
|
|
|
tpl_toolbar_fileupload({'tooltip_upload_file': __('Choose a file to send')}));
|
2018-03-29 16:12:19 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
renderToolbar (toolbar, options) {
|
|
|
|
const { _converse } = this.__super__;
|
|
|
|
const result = this.__super__.renderToolbar.apply(this, arguments);
|
2018-04-14 21:13:02 +02:00
|
|
|
_converse.api.disco.supports(Strophe.NS.HTTPUPLOAD, _converse.domain).then((result) => {
|
|
|
|
if (result.length) {
|
|
|
|
this.addFileUploadButton();
|
|
|
|
}
|
|
|
|
});
|
2018-03-29 16:12:19 +02:00
|
|
|
return result;
|
|
|
|
}
|
2018-04-11 17:09:32 +02:00
|
|
|
},
|
2018-03-28 18:38:22 +02:00
|
|
|
|
2018-04-11 17:09:32 +02:00
|
|
|
ChatRoomView: {
|
|
|
|
events: {
|
2018-04-14 07:50:29 +02:00
|
|
|
'click .upload-file': 'toggleFileUpload',
|
2018-04-14 21:13:02 +02:00
|
|
|
'change .input.fileupload': 'onFileSelection'
|
2018-04-11 17:09:32 +02:00
|
|
|
}
|
|
|
|
}
|
2018-03-28 18:38:22 +02:00
|
|
|
}
|
|
|
|
});
|
2018-04-11 15:29:41 +02:00
|
|
|
return converse;
|
2018-03-28 18:38:22 +02:00
|
|
|
}));
|