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

View file

@ -31,25 +31,10 @@ new Vue({
},
closeChannel(channel) {
if (channel.type === "lobby") {
eventbus.emit(
"confirm-dialog",
{
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",
});
}
);
socket.emit("input", {
target: Number(channel.id),
text: "/quit",
});
return;
}

View file

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

View file

@ -18,6 +18,7 @@ const Identification = require("./identification");
const changelog = require("./plugins/changelog");
const inputs = require("./plugins/inputs");
const Auth = require("./plugins/auth");
const ClientCertificate = require("./plugins/clientCertificate");
const themes = require("./plugins/packages/themes");
themes.loadLocalThemes();
@ -418,6 +419,26 @@ function initializeClient(socket, client, token, lastMessage, openChannel) {
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) => {
if (_.isPlainObject(data)) {
client.clearHistory(data);