converse-http-file-upload.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. (function (root, factory) {
  2. define([
  3. "converse-core",
  4. "tpl!toolbar_fileupload"
  5. ], factory);
  6. }(this, function (converse, tpl_toolbar_fileupload) {
  7. "use strict";
  8. const { Promise, Strophe, _ } = converse.env;
  9. const u = converse.env.utils;
  10. Strophe.addNamespace('HTTPUPLOAD', 'urn:xmpp:http:upload:0');
  11. converse.plugins.add('converse-http-file-upload', {
  12. /* Plugin dependencies are other plugins which might be
  13. * overridden or relied upon, and therefore need to be loaded before
  14. * this plugin.
  15. *
  16. * If the setting "strict_plugin_dependencies" is set to true,
  17. * an error will be raised if the plugin is not found. By default it's
  18. * false, which means these plugins are only loaded opportunistically.
  19. *
  20. * NB: These plugins need to have already been loaded via require.js.
  21. */
  22. dependencies: ["converse-chatview"],
  23. overrides: {
  24. ChatBoxView: {
  25. addFileUploadButton (options) {
  26. const { __ } = this.__super__._converse;
  27. this.el.querySelector('.chat-toolbar').insertAdjacentHTML(
  28. 'beforeend',
  29. tpl_toolbar_fileupload({'tooltip_upload_file': __('Choose a file to send')}));
  30. },
  31. renderToolbar (toolbar, options) {
  32. const { _converse } = this.__super__;
  33. const result = this.__super__.renderToolbar.apply(this, arguments);
  34. _converse.api.disco.supports(Strophe.NS.HTTPUPLOAD, _converse.domain)
  35. .then((result) => {
  36. if (result.length) {
  37. this.addFileUploadButton();
  38. }
  39. });
  40. return result;
  41. }
  42. }
  43. },
  44. initialize () {
  45. /* The initialize function gets called as soon as the plugin is
  46. * loaded by converse.js's plugin machinery.
  47. */
  48. const { _converse } = this;
  49. }
  50. });
  51. }));