From 3b1d27636d8a373d378994f106bcbc4354bacce9 Mon Sep 17 00:00:00 2001 From: worlword Date: Thu, 12 Apr 2018 19:44:52 +0200 Subject: [PATCH] problem fixed, that file-upload would not start. Also did some code cleanup --- src/converse-chatboxes.js | 24 ++++-------------------- src/converse-chatview.js | 8 +++----- src/converse-http-file-upload.js | 26 ++++++++------------------ src/templates/toolbar_fileupload.html | 2 +- 4 files changed, 16 insertions(+), 44 deletions(-) diff --git a/src/converse-chatboxes.js b/src/converse-chatboxes.js index 21a717016..054b95fca 100644 --- a/src/converse-chatboxes.js +++ b/src/converse-chatboxes.js @@ -131,22 +131,16 @@ sendFile (file, chatbox) { const self = this; - console.log('Send file via http upload'); const request_slot_url = 'upload.' + _converse.domain; _converse.api.disco.supports(Strophe.NS.HTTPUPLOAD, request_slot_url) .then((result) => { chatbox.showHelpMessages([__('The file upload starts now')],'info'); self.requestSlot(file, request_slot_url, function(data) { if (!data) { - // general error - console.log('Unknown error while requesting upload slot.'); alert(__('File upload failed. Please check the log.')); } else if (data.error) { - // specific error - console.log('The XMPP-Server return an error of the type: ' + data.error.type); alert(__('File upload failed. Please check the log.')); } else if (data.get && data.put) { - console.log('slot received, start upload to ' + data.put); self.uploadFile(data.put, file, function() { console.log(data.put); chatbox.onMessageSubmitted(data.put, null, file); @@ -175,7 +169,7 @@ }); }, - uploadFile (url, file, success_cb) { + uploadFile (url, file, callback) { console.log("uploadFile start"); const xmlhttp = new XMLHttpRequest(); const contentType = 'application/octet-stream'; @@ -183,13 +177,11 @@ if (xmlhttp.readyState === XMLHttpRequest.DONE) { console.log("Status: " + xmlhttp.status); if (xmlhttp.status === 200 || xmlhttp.status === 201) { - console.log('file successful uploaded'); - if (success_cb) { - success_cb(); + if (callback) { + callback(); } } else { - console.log('error while uploading file to ' + url); alert(__('Could not upload File please try again.')); } } @@ -198,13 +190,8 @@ xmlhttp.open('PUT', url, true); xmlhttp.setRequestHeader("Content-type", contentType); xmlhttp.send(file); - - console.log("uploadFile end"); }, - - /** - * Process successful response to slot request. - */ + successfulRequestSlotCB (stanza, cb) { const slot = stanza.getElementsByTagName('slot')[0]; @@ -220,9 +207,6 @@ } }, - /** - * Process failed response to slot request. - */ failedRequestSlotCB (stanza, cb) { alert(__('Could not upload File please try again.')); }, diff --git a/src/converse-chatview.js b/src/converse-chatview.js index fe7cd2cf2..1e6389476 100644 --- a/src/converse-chatview.js +++ b/src/converse-chatview.js @@ -116,8 +116,7 @@ 'call': false, 'clear': true, 'emoji': true, - 'spoiler': true, - 'fileUpload': true + 'spoiler': true }, }); emojione.imagePathPNG = _converse.emojione_image_path; @@ -379,7 +378,6 @@ 'label_toggle_spoiler': label_toggle_spoiler, 'show_call_button': _converse.visible_toolbar_buttons.call, 'show_spoiler_button': _converse.visible_toolbar_buttons.spoiler, - 'show_fileUpload_button': _converse.visible_toolbar_buttons.fileUpload, 'use_emoji': _converse.visible_toolbar_buttons.emoji, }); }, @@ -818,7 +816,7 @@ return stanza; }, - sendMessage (message, file=null) { + sendMessage (message, file = null) { /* Responsible for sending off a text message. * * Parameters: @@ -828,7 +826,7 @@ // Especially in the OTR case. var messageStanza; if (file !== null) { - messageStanza = this.createFileMessageStanza(message, this.model.get('jid')); + messageStanza = this.model.createFileMessageStanza(message, this.model.get('jid')); } else { messageStanza = this.createMessageStanza(message); diff --git a/src/converse-http-file-upload.js b/src/converse-http-file-upload.js index 7578d4692..6e0e0f7f3 100644 --- a/src/converse-http-file-upload.js +++ b/src/converse-http-file-upload.js @@ -22,7 +22,6 @@ overrides: { ChatBoxView: { - events: { 'click .toggle-fileUpload': 'toggleFileUpload', 'change .fileUpload_input': 'handleFileSelect' @@ -35,18 +34,6 @@ tpl_toolbar_fileupload({'label_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, 'upload.' + _converse.domain) - .then((result) => { - if (result.supported) { - this.addFileUploadButton(); - } - }); - return result; - }, - toggleFileUpload (ev) { this.el.querySelector('.fileUpload_input').click(); }, @@ -55,21 +42,24 @@ var files = evt.target.files; var file = files[0]; this.model.sendFile(file, this); - } + }, + + renderToolbar (toolbar, options) { + const result = this.__super__.renderToolbar.apply(this, arguments); + this.addFileUploadButton(); + return result; + }, }, ChatRoomView: { events: { 'click .toggle-fileUpload': 'toggleFileUpload', - 'change .fileUpload_input': 'handleFileSelect', + 'change .fileUpload_input': 'handleFileSelect' } } }, initialize () { - /* The initialize function gets called as soon as the plugin is - * loaded by converse.js's plugin machinery. - */ const { _converse } = this, { __ } = _converse; } diff --git a/src/templates/toolbar_fileupload.html b/src/templates/toolbar_fileupload.html index 0d8997183..691d19011 100644 --- a/src/templates/toolbar_fileupload.html +++ b/src/templates/toolbar_fileupload.html @@ -1,4 +1,4 @@
  • -
  • \ No newline at end of file +