Synchornize channel state to the client

This commit is contained in:
Pavel Djundik 2018-07-19 21:03:53 +03:00 committed by Pavel Djundik
parent f2cbd1efed
commit 853f67ab40
4 changed files with 24 additions and 1 deletions

View File

@ -6,6 +6,7 @@
<span <span
:title="channel.name" :title="channel.name"
class="name">{{ channel.name }}</span> class="name">{{ channel.name }}</span>
<span v-if="channel.type === 'channel' && channel.state === 0">(parted)</span>
<span <span
v-if="channel.unread" v-if="channel.unread"
:class="{ highlight: channel.highlight }" :class="{ highlight: channel.highlight }"

View File

@ -5,7 +5,7 @@ const socket = require("../socket");
const templates = require("../../views"); const templates = require("../../views");
const sidebar = $("#sidebar"); const sidebar = $("#sidebar");
const utils = require("../utils"); const utils = require("../utils");
const {vueApp, initChannel} = require("../vue"); const {vueApp, initChannel, findChannel} = require("../vue");
socket.on("network", function(data) { socket.on("network", function(data) {
const network = data.networks[0]; const network = data.networks[0];
@ -35,6 +35,18 @@ socket.on("network:status", function(data) {
const network = vueApp.networks.find((n) => n.uuid === data.network); const network = vueApp.networks.find((n) => n.uuid === data.network);
network.status.connected = data.connected; network.status.connected = data.connected;
network.status.secure = data.secure; network.status.secure = data.secure;
if (!data.connected) {
network.channels.forEach((channel) => channel.state = 0);
}
});
socket.on("channel:state", function(data) {
const channel = findChannel(data.chan);
if (channel) {
channel.channel.state = data.state;
}
}); });
socket.on("network:info", function(data) { socket.on("network:info", function(data) {

View File

@ -29,6 +29,11 @@ module.exports = function(irc, network) {
network.irc.raw("MODE", chan.name); network.irc.raw("MODE", chan.name);
} else if (data.nick === irc.user.nick) { } else if (data.nick === irc.user.nick) {
chan.state = Chan.State.JOINED; chan.state = Chan.State.JOINED;
client.emit("channel:state", {
chan: chan.id,
state: chan.state,
});
} }
const user = new User({nick: data.nick}); const user = new User({nick: data.nick});

View File

@ -27,6 +27,11 @@ module.exports = function(irc, network) {
if (data.kicked === irc.user.nick) { if (data.kicked === irc.user.nick) {
chan.users = new Map(); chan.users = new Map();
chan.state = Chan.State.PARTED; chan.state = Chan.State.PARTED;
client.emit("channel:state", {
chan: chan.id,
state: chan.state,
});
} else { } else {
chan.removeUser(msg.target); chan.removeUser(msg.target);
} }