Remove separate file converse-http-file-upload

It contained only `overrides` and some HTTP upload code was in other
modules.

Current thinking concerning overrides:

Usage of `overrides`, while useful in certain cases, should in general
be discouraged, since it's in essence "monkey patching" which makes it
more difficult to know whats executing at runtime and more difficult to
refactor.

Splitting modules up between XEPs is not always that useful. Some XEPs,
like HTTP Upload (and MAM comes to mind) have their functionality spread
out over single and group chats (and pubsub) and might for practical
purposes be considered "core" enough to not try and keep them in
separate modules (which inevitably requires overrides or a fundamentally
rethinking the architecture).

Where splitting code between modules makes a lot of sense is in keeping
Backbone Models and Views separate (so that alternative view libraries
like Vue could be used) and probably in keeping Single chats, MUC,
PubSub and MIX separate.

updates #161
This commit is contained in:
JC Brand 2018-04-16 21:58:11 +02:00
parent de6ecbf07a
commit dad8eb2f48
8 changed files with 44 additions and 96 deletions

View File

@ -75,7 +75,6 @@ require.config({
"converse-dragresize": "src/converse-dragresize",
"converse-fullscreen": "src/converse-fullscreen",
"converse-headline": "src/converse-headline",
"converse-http-file-upload":"src/converse-http-file-upload",
"converse-mam": "src/converse-mam",
"converse-message-view": "src/converse-message-view",
"converse-minimize": "src/converse-minimize",

View File

@ -20,11 +20,11 @@
"tpl!help_message",
"tpl!info",
"tpl!new_day",
"tpl!toolbar_fileupload",
"tpl!spinner",
"tpl!spoiler_button",
"tpl!status_message",
"tpl!toolbar",
"converse-http-file-upload",
"converse-chatboxes",
"converse-message-view"
], factory);
@ -43,6 +43,7 @@
tpl_help_message,
tpl_info,
tpl_new_day,
tpl_toolbar_fileupload,
tpl_spinner,
tpl_spoiler_button,
tpl_status_message,
@ -240,15 +241,17 @@
is_chatroom: false, // Leaky abstraction from MUC
events: {
'change input.fileupload': 'onFileSelection',
'click .close-chatbox-button': 'close',
'click .new-msgs-indicator': 'viewUnreadMessages',
'click .send-button': 'onFormSubmitted',
'click .toggle-call': 'toggleCall',
'click .toggle-clear': 'clearMessages',
'click .toggle-compose-spoiler': 'toggleComposeSpoilerMessage',
'click .toggle-smiley ul.emoji-picker li': 'insertEmoji',
'click .toggle-smiley': 'toggleEmojiMenu',
'click .toggle-spoiler': 'toggleSpoilerMessage',
'click .toggle-compose-spoiler': 'toggleComposeSpoilerMessage',
'click .upload-file': 'toggleFileUpload',
'keypress .chat-textarea': 'keyPressed'
},
@ -296,6 +299,7 @@
);
this.el.querySelector('.chat-toolbar').innerHTML = toolbar(options);
this.addSpoilerButton(options);
this.addFileUploadButton();
this.insertEmojiPicker();
return this;
},
@ -322,6 +326,22 @@
this.renderToolbar();
},
toggleFileUpload (ev) {
this.el.querySelector('input.fileupload').click();
},
onFileSelection (evt) {
this.model.sendFiles(evt.target.files);
},
addFileUploadButton (options) {
_converse.api.disco.supports(Strophe.NS.HTTPUPLOAD, _converse.domain).then((result) => {
this.el.querySelector('.chat-toolbar').insertAdjacentHTML(
'beforeend',
tpl_toolbar_fileupload({'tooltip_upload_file': __('Choose a file to send')}));
});
},
addSpoilerButton (options) {
/* Asynchronously adds a button for writing spoiler
* messages, based on whether the contact's client supports

View File

@ -38,6 +38,7 @@
Strophe.addNamespace('DELAY', 'urn:xmpp:delay');
Strophe.addNamespace('FORWARD', 'urn:xmpp:forward:0');
Strophe.addNamespace('HINTS', 'urn:xmpp:hints');
Strophe.addNamespace('HTTPUPLOAD', 'urn:xmpp:http:upload:0');
Strophe.addNamespace('MAM', 'urn:xmpp:mam:2');
Strophe.addNamespace('NICK', 'http://jabber.org/protocol/nick');
Strophe.addNamespace('PUBSUB', 'http://jabber.org/protocol/pubsub');

View File

@ -1,74 +0,0 @@
/**
* Adds Support for Http File Upload (XEP-0363)
*
*/
(function (root, factory) {
define([
"converse-core",
"tpl!toolbar_fileupload"
], factory);
}(this, function (converse, tpl_toolbar_fileupload) {
"use strict";
const { Promise, Strophe, _ } = converse.env;
const u = converse.env.utils;
Strophe.addNamespace('HTTPUPLOAD', 'urn:xmpp:http:upload:0');
converse.plugins.add('converse-http-file-upload', {
/* 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.
*/
dependencies: ["converse-chatboxes", "converse-chatview", "converse-muc-views"],
overrides: {
ChatBoxView: {
events: {
'click .upload-file': 'toggleFileUpload',
'change input.fileupload': 'onFileSelection'
},
toggleFileUpload (ev) {
this.el.querySelector('input.fileupload').click();
},
onFileSelection (evt) {
this.model.sendFiles(evt.target.files);
},
addFileUploadButton (options) {
const { __ } = this.__super__._converse;
this.el.querySelector('.chat-toolbar').insertAdjacentHTML(
'beforeend',
tpl_toolbar_fileupload({'tooltip_upload_file': __('Choose a file to send')}));
},
renderToolbar (toolbar, options) {
const { _converse } = this.__super__;
const result = this.__super__.renderToolbar.apply(this, arguments);
_converse.api.disco.supports(Strophe.NS.HTTPUPLOAD, _converse.domain).then((result) => {
if (result.length) {
this.addFileUploadButton();
}
});
return result;
}
},
ChatRoomView: {
events: {
'click .upload-file': 'toggleFileUpload',
'change .input.fileupload': 'onFileSelection'
}
}
}
});
return converse;
}));

View File

@ -3,15 +3,15 @@
//
// Copyright (c) 2012-2018, the Converse.js developers
// Licensed under the Mozilla Public License (MPLv2)
//
(function (root, factory) {
define([
"converse-core",
"xss",
"emojione",
"tpl!action",
"tpl!message",
"tpl!spoiler_message"
"converse-core",
"xss",
"emojione",
"tpl!action",
"tpl!message",
"tpl!spoiler_message"
], factory);
}(this, function (
converse,

View File

@ -497,17 +497,19 @@
className: 'chatbox chatroom hidden',
is_chatroom: true,
events: {
'change .input.fileupload': 'onFileSelection',
'click .close-chatbox-button': 'close',
'click .configure-chatroom-button': 'getAndRenderConfigurationForm',
'click .toggle-smiley': 'toggleEmojiMenu',
'click .toggle-smiley ul.emoji-picker li': 'insertEmoji',
'click .toggle-clear': 'clearChatRoomMessages',
'click .toggle-call': 'toggleCall',
'click .toggle-occupants': 'toggleOccupants',
'click .new-msgs-indicator': 'viewUnreadMessages',
'click .occupant': 'onOccupantClicked',
'keypress .chat-textarea': 'keyPressed',
'click .send-button': 'onFormSubmitted'
'click .send-button': 'onFormSubmitted',
'click .toggle-call': 'toggleCall',
'click .toggle-clear': 'clearChatRoomMessages',
'click .toggle-occupants': 'toggleOccupants',
'click .toggle-smiley ul.emoji-picker li': 'insertEmoji',
'click .toggle-smiley': 'toggleEmojiMenu',
'click .upload-file': 'toggleFileUpload',
'keypress .chat-textarea': 'keyPressed'
},
initialize () {

View File

@ -10,10 +10,11 @@
* encryption of one-on-one chat messages.
*/
(function (root, factory) {
define([ "converse-chatview",
"bootstrap",
"tpl!toolbar_otr",
'otr'
define([
"converse-chatview",
"bootstrap",
"tpl!toolbar_otr",
'otr'
], factory);
}(this, function (converse, bootstrap, tpl_toolbar_otr, otr) {
"use strict";

View File

@ -13,7 +13,6 @@ if (typeof define !== 'undefined') {
"converse-dragresize", // Allows chat boxes to be resized by dragging them
"converse-fullscreen",
"converse-headline", // Support for headline messages
"converse-http-file-upload",// Support for XEP-0363
"converse-mam", // XEP-0313 Message Archive Management
"converse-minimize", // Allows chat boxes to be minimized
"converse-muc", // XEP-0045 Multi-user chat