problem fixed, that file-upload would not start. Also did some code cleanup
This commit is contained in:
parent
ca40cf6541
commit
3b1d27636d
@ -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.'));
|
||||
},
|
||||
|
@ -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,
|
||||
});
|
||||
},
|
||||
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user