Archived
1
0

update livechan to allow attachments

This commit is contained in:
Jeff Becker 2016-07-04 11:52:43 -04:00
parent 13e0010419
commit 4a8861761d
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B

View File

@ -905,12 +905,17 @@ Chat.prototype.onNotifyShow = function () {
Chat.prototype.readImage = function (elem, callback) { Chat.prototype.readImage = function (elem, callback) {
var self = this; var self = this;
var reader = new FileReader();
if (elem.files.length > 0 ) { if (elem.files.length > 0 ) {
var reader = new FileReader();
var file = elem.files[0]; var file = elem.files[0];
callback(file, file.name); reader.onloadend = function(ev) {
if (ev.target.readyState == FileReader.DONE) {
callback(window.btoa(ev.target.result), file.name, file.type);
}
}
reader.readAsBinaryString(file);
} else { } else {
callback(null, null); callback(null, null, null);
} }
} }
@ -956,17 +961,21 @@ Chat.prototype.sendInput = function(event) {
var message = inputElem.message.value; var message = inputElem.message.value;
var name = inputElem.name.value; var name = inputElem.name.value;
var convo = inputElem.convo.value; var convo = inputElem.convo.value;
connection.send({Type: "post", Post: { self.readImage(inputElem.file, function(fdata, fname, ftype) {
Message: message, if (fdata) {
Name: name, connection.send({Type: "post", Post: {
}}); message: message,
for (var idx = 0 ; idx < inputElem.file.files.length; idx ++ ) { name: name,
console.log("send file "+ idx); files: [{name: fname, data: fdata, type: ftype}],
connection.send(inputElem.file.files[idx]); }});
} } else {
inputElem.file.value = ""; connection.send({Type: "post", Post: {
//TODO: don't clear this when doing captcha message: message,
inputElem.message.value = ''; name: name, }});
}
inputElem.file.value = "";
inputElem.message.value = '';
});
inputElem.submit.disabled = true; inputElem.submit.disabled = true;
var i = parseInt(self.options.cooldown); var i = parseInt(self.options.cooldown);
// fallback // fallback