Show quit dialog when using /quit

Beforehand it only showed the dialog when quitting via the contextmenu. This also adds the possibility for the server to ask for dialogs.
This commit is contained in:
Nachtalb 2021-05-22 15:35:24 +02:00 committed by Max Leiter
parent cc0dc6266e
commit a9b3c77da3
No known key found for this signature in database
GPG key ID: A3512F2F2F17EBDA
4 changed files with 48 additions and 33 deletions

View file

@ -3,7 +3,7 @@
<div v-if="data !== null" id="confirm-dialog"> <div v-if="data !== null" id="confirm-dialog">
<div class="confirm-text"> <div class="confirm-text">
<div class="confirm-text-title">{{ data.title }}</div> <div class="confirm-text-title">{{ data.title }}</div>
<p>{{ data.text }}</p> <p v-html="data.text"></p>
</div> </div>
<div class="confirm-buttons"> <div class="confirm-buttons">
<button class="btn btn-cancel" @click="close(false)">Cancel</button> <button class="btn btn-cancel" @click="close(false)">Cancel</button>
@ -52,6 +52,7 @@
<script> <script>
import eventbus from "../js/eventbus"; import eventbus from "../js/eventbus";
import socket from "../js/socket";
export default { export default {
name: "ConfirmDialog", name: "ConfirmDialog",
@ -64,13 +65,23 @@ export default {
mounted() { mounted() {
eventbus.on("escapekey", this.close); eventbus.on("escapekey", this.close);
eventbus.on("confirm-dialog", this.open); eventbus.on("confirm-dialog", this.open);
socket.on("confirm-dialog", this.open);
}, },
destroyed() { destroyed() {
eventbus.off("escapekey", this.close); eventbus.off("escapekey", this.close);
eventbus.off("confirm-dialog", this.open); eventbus.off("confirm-dialog", this.open);
socket.off("confirm-dialog", this.open);
}, },
methods: { methods: {
open(data, callback) { open(data, callback) {
if (data.emit) {
callback = (result) => {
if (result) {
socket.emit(data.emit.target, data.emit.data);
}
};
}
this.data = data; this.data = data;
this.callback = callback; this.callback = callback;
}, },

View file

@ -31,25 +31,10 @@ new Vue({
}, },
closeChannel(channel) { closeChannel(channel) {
if (channel.type === "lobby") { if (channel.type === "lobby") {
eventbus.emit( socket.emit("input", {
"confirm-dialog", target: Number(channel.id),
{ text: "/quit",
title: "Remove network", });
text: `Are you sure you want to quit and remove ${channel.name}? This cannot be undone.`,
button: "Remove network",
},
(result) => {
if (!result) {
return;
}
channel.closed = true;
socket.emit("input", {
target: Number(channel.id),
text: "/quit",
});
}
);
return; return;
} }

View file

@ -1,25 +1,23 @@
"use strict"; "use strict";
const _ = require("lodash");
const ClientCertificate = require("../clientCertificate");
exports.commands = ["quit"]; exports.commands = ["quit"];
exports.allowDisconnected = true; exports.allowDisconnected = true;
exports.input = function (network, chan, cmd, args) { exports.input = function (network, chan, cmd, args) {
const client = this; const client = this;
client.networks = _.without(client.networks, network); client.emit("confirm-dialog", {
network.destroy(); title: "Remove network",
client.save(); text: `Are you sure you want to quit and remove <b>${network.name}</b>? This cannot be undone.`,
client.emit("quit", { button: "Remove network",
network: network.uuid, emit: {
target: "network:quit",
data: {
uuid: network.uuid,
quiteMessage: args[0] ? args.join(" ") : null,
},
},
}); });
const quitMessage = args[0] ? args.join(" ") : null;
network.quit(quitMessage);
ClientCertificate.remove(network.uuid);
return true; return true;
}; };

View file

@ -18,6 +18,7 @@ const Identification = require("./identification");
const changelog = require("./plugins/changelog"); const changelog = require("./plugins/changelog");
const inputs = require("./plugins/inputs"); const inputs = require("./plugins/inputs");
const Auth = require("./plugins/auth"); const Auth = require("./plugins/auth");
const ClientCertificate = require("./plugins/clientCertificate");
const themes = require("./plugins/packages/themes"); const themes = require("./plugins/packages/themes");
themes.loadLocalThemes(); themes.loadLocalThemes();
@ -418,6 +419,26 @@ function initializeClient(socket, client, token, lastMessage, openChannel) {
network.edit(client, data); network.edit(client, data);
}); });
socket.on("network:quit", (data) => {
if (!_.isPlainObject(data)) {
return;
}
const network = _.find(client.networks, {uuid: data.uuid});
client.networks = _.without(client.networks, network);
network.destroy();
client.save();
client.emit("quit", {
network: network.uuid,
});
const quitMessage = data.quitMessage;
network.quit(quitMessage);
ClientCertificate.remove(network.uuid);
});
socket.on("history:clear", (data) => { socket.on("history:clear", (data) => {
if (_.isPlainObject(data)) { if (_.isPlainObject(data)) {
client.clearHistory(data); client.clearHistory(data);