mirror of
https://github.com/thelounge/thelounge.git
synced 2024-06-11 02:02:18 +02:00
Add confirm dialog for uploading long lines as a file
This commit is contained in:
parent
b6819b6dfc
commit
2b0beac1d9
|
@ -267,47 +267,65 @@ export default {
|
||||||
this.setInputSize();
|
this.setInputSize();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const sendMessage = () => {
|
||||||
|
resetInput();
|
||||||
|
|
||||||
|
// Store new message in history if last message isn't already equal
|
||||||
|
if (this.channel.inputHistory[1] !== text) {
|
||||||
|
this.channel.inputHistory.splice(1, 0, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit input history to a 100 entries
|
||||||
|
if (this.channel.inputHistory.length > 100) {
|
||||||
|
this.channel.inputHistory.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (text[0] === "/") {
|
||||||
|
const args = text.substr(1).split(" ");
|
||||||
|
const cmd = args.shift().toLowerCase();
|
||||||
|
|
||||||
|
if (
|
||||||
|
Object.prototype.hasOwnProperty.call(commands, cmd) &&
|
||||||
|
commands[cmd].input(args)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
socket.emit("input", {target, text});
|
||||||
|
};
|
||||||
|
|
||||||
if (this.$store.state.serverConfiguration.fileUpload) {
|
if (this.$store.state.serverConfiguration.fileUpload) {
|
||||||
const lines = 1 + (text.match(/\n/g) || "").length;
|
const lines = 1 + (text.match(/\n/g) || "").length;
|
||||||
|
|
||||||
// TODO: Offer a confirmation to user whether they want to upload
|
|
||||||
if (lines > 3 || text.length > 700) {
|
if (lines > 3 || text.length > 700) {
|
||||||
resetInput();
|
eventbus.emit(
|
||||||
|
"confirm-dialog",
|
||||||
|
{
|
||||||
|
title: "Upload as file?",
|
||||||
|
text: `You're trying to send a lot of text. Would you like to upload it?`,
|
||||||
|
button: "Upload",
|
||||||
|
},
|
||||||
|
(result) => {
|
||||||
|
if (!result) {
|
||||||
|
sendMessage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const file = new File([text], "paste.txt", {
|
resetInput();
|
||||||
type: "text/plain",
|
|
||||||
});
|
const file = new File([text], "paste.txt", {
|
||||||
upload.triggerUpload([file]);
|
type: "text/plain",
|
||||||
|
});
|
||||||
|
upload.triggerUpload([file]);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resetInput();
|
sendMessage();
|
||||||
|
|
||||||
// Store new message in history if last message isn't already equal
|
|
||||||
if (this.channel.inputHistory[1] !== text) {
|
|
||||||
this.channel.inputHistory.splice(1, 0, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Limit input history to a 100 entries
|
|
||||||
if (this.channel.inputHistory.length > 100) {
|
|
||||||
this.channel.inputHistory.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (text[0] === "/") {
|
|
||||||
const args = text.substr(1).split(" ");
|
|
||||||
const cmd = args.shift().toLowerCase();
|
|
||||||
|
|
||||||
if (
|
|
||||||
Object.prototype.hasOwnProperty.call(commands, cmd) &&
|
|
||||||
commands[cmd].input(args)
|
|
||||||
) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
socket.emit("input", {target, text});
|
|
||||||
},
|
},
|
||||||
onUploadInputChange() {
|
onUploadInputChange() {
|
||||||
const files = Array.from(this.$refs.uploadInput.files);
|
const files = Array.from(this.$refs.uploadInput.files);
|
||||||
|
|
Loading…
Reference in a new issue