Track channel state to allow removing channels user is not in

This commit is contained in:
Pavel Djundik 2018-02-13 12:30:26 +02:00
parent 865e5bb41b
commit 7e704b2d73
6 changed files with 17 additions and 1 deletions

View File

@ -15,6 +15,11 @@ Chan.Type = {
SPECIAL: "special",
};
Chan.State = {
PARTED: 0,
JOINED: 1,
};
let id = 1;
function Chan(attr) {
@ -25,6 +30,7 @@ function Chan(attr) {
key: "",
topic: "",
type: Chan.Type.CHANNEL,
state: Chan.State.PARTED,
firstUnread: 0,
unread: 0,
highlight: 0,

View File

@ -29,7 +29,9 @@ exports.input = function(network, chan, cmd, args) {
// If target is not a channel or we are not connected, instantly remove the channel
// Otherwise send part to the server and wait for response
if (target.type !== Chan.Type.CHANNEL || !network.irc || !network.irc.connection || !network.irc.connection.connected) {
if (target.type !== Chan.Type.CHANNEL
|| target.state === Chan.State.PARTED
|| !network.irc || !network.irc.connection || !network.irc.connection.connected) {
network.channels = _.without(network.channels, target);
target.destroy();
this.emit("part", {

View File

@ -81,6 +81,10 @@ module.exports = function(irc, network) {
client.manager.identHandler.removeSocket(identSocketId);
identSocketId = 0;
}
network.channels.forEach((chan) => {
chan.state = Chan.State.PARTED;
});
});
if (Helper.config.debug.ircFramework) {

View File

@ -13,6 +13,7 @@ module.exports = function(irc, network) {
if (typeof chan === "undefined") {
chan = new Chan({
name: data.channel,
state: Chan.State.JOINED,
});
network.channels.push(chan);
client.save();

View File

@ -1,5 +1,6 @@
"use strict";
const Chan = require("../../models/chan");
const Msg = require("../../models/msg");
module.exports = function(irc, network) {
@ -25,6 +26,7 @@ module.exports = function(irc, network) {
if (data.kicked === irc.user.nick) {
chan.users = new Map();
chan.state = Chan.State.PARTED;
} else {
chan.removeUser(msg.target);
}

View File

@ -175,6 +175,7 @@ describe("Chan", function() {
"key",
"messages",
"name",
"state",
"topic",
"type",
"unread",