Track channel state to allow removing channels user is not in
This commit is contained in:
parent
865e5bb41b
commit
7e704b2d73
@ -15,6 +15,11 @@ Chan.Type = {
|
|||||||
SPECIAL: "special",
|
SPECIAL: "special",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Chan.State = {
|
||||||
|
PARTED: 0,
|
||||||
|
JOINED: 1,
|
||||||
|
};
|
||||||
|
|
||||||
let id = 1;
|
let id = 1;
|
||||||
|
|
||||||
function Chan(attr) {
|
function Chan(attr) {
|
||||||
@ -25,6 +30,7 @@ function Chan(attr) {
|
|||||||
key: "",
|
key: "",
|
||||||
topic: "",
|
topic: "",
|
||||||
type: Chan.Type.CHANNEL,
|
type: Chan.Type.CHANNEL,
|
||||||
|
state: Chan.State.PARTED,
|
||||||
firstUnread: 0,
|
firstUnread: 0,
|
||||||
unread: 0,
|
unread: 0,
|
||||||
highlight: 0,
|
highlight: 0,
|
||||||
|
@ -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
|
// 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
|
// 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);
|
network.channels = _.without(network.channels, target);
|
||||||
target.destroy();
|
target.destroy();
|
||||||
this.emit("part", {
|
this.emit("part", {
|
||||||
|
@ -81,6 +81,10 @@ module.exports = function(irc, network) {
|
|||||||
client.manager.identHandler.removeSocket(identSocketId);
|
client.manager.identHandler.removeSocket(identSocketId);
|
||||||
identSocketId = 0;
|
identSocketId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
network.channels.forEach((chan) => {
|
||||||
|
chan.state = Chan.State.PARTED;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (Helper.config.debug.ircFramework) {
|
if (Helper.config.debug.ircFramework) {
|
||||||
|
@ -13,6 +13,7 @@ module.exports = function(irc, network) {
|
|||||||
if (typeof chan === "undefined") {
|
if (typeof chan === "undefined") {
|
||||||
chan = new Chan({
|
chan = new Chan({
|
||||||
name: data.channel,
|
name: data.channel,
|
||||||
|
state: Chan.State.JOINED,
|
||||||
});
|
});
|
||||||
network.channels.push(chan);
|
network.channels.push(chan);
|
||||||
client.save();
|
client.save();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
const Chan = require("../../models/chan");
|
||||||
const Msg = require("../../models/msg");
|
const Msg = require("../../models/msg");
|
||||||
|
|
||||||
module.exports = function(irc, network) {
|
module.exports = function(irc, network) {
|
||||||
@ -25,6 +26,7 @@ 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;
|
||||||
} else {
|
} else {
|
||||||
chan.removeUser(msg.target);
|
chan.removeUser(msg.target);
|
||||||
}
|
}
|
||||||
|
@ -175,6 +175,7 @@ describe("Chan", function() {
|
|||||||
"key",
|
"key",
|
||||||
"messages",
|
"messages",
|
||||||
"name",
|
"name",
|
||||||
|
"state",
|
||||||
"topic",
|
"topic",
|
||||||
"type",
|
"type",
|
||||||
"unread",
|
"unread",
|
||||||
|
Loading…
Reference in New Issue
Block a user