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
:title="channel.name"
class="name">{{ channel.name }}</span>
<span v-if="channel.type === 'channel' && channel.state === 0">(parted)</span>
<span
v-if="channel.unread"
:class="{ highlight: channel.highlight }"

View File

@ -5,7 +5,7 @@ const socket = require("../socket");
const templates = require("../../views");
const sidebar = $("#sidebar");
const utils = require("../utils");
const {vueApp, initChannel} = require("../vue");
const {vueApp, initChannel, findChannel} = require("../vue");
socket.on("network", function(data) {
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);
network.status.connected = data.connected;
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) {

View File

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

View File

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