2022-06-18 20:25:21 -04:00
|
|
|
import Msg, {MessageType} from "../../models/msg";
|
|
|
|
import User from "../../models/user";
|
|
|
|
import type {IrcEventHandler} from "../../client";
|
|
|
|
import {ChanState} from "../../models/chan";
|
2016-10-09 15:14:02 -04:00
|
|
|
|
2022-06-18 20:25:21 -04:00
|
|
|
export default <IrcEventHandler>function (irc, network) {
|
2017-11-10 15:44:14 -05:00
|
|
|
const client = this;
|
|
|
|
|
2020-03-21 16:55:36 -04:00
|
|
|
irc.on("join", function (data) {
|
2017-11-10 15:44:14 -05:00
|
|
|
let chan = network.getChannel(data.channel);
|
|
|
|
|
2014-09-13 17:29:45 -04:00
|
|
|
if (typeof chan === "undefined") {
|
2018-04-27 06:16:23 -04:00
|
|
|
chan = client.createChannel({
|
2017-11-15 01:35:15 -05:00
|
|
|
name: data.channel,
|
2022-06-18 20:25:21 -04:00
|
|
|
state: ChanState.JOINED,
|
2014-09-13 17:29:45 -04:00
|
|
|
});
|
2018-03-12 08:42:59 -04:00
|
|
|
|
2014-09-13 17:29:45 -04:00
|
|
|
client.emit("join", {
|
2018-04-26 05:06:01 -04:00
|
|
|
network: network.uuid,
|
2017-12-03 09:29:50 -05:00
|
|
|
chan: chan.getFilteredClone(true),
|
2018-03-12 08:42:59 -04:00
|
|
|
index: network.addChannel(chan),
|
2014-09-13 17:29:45 -04:00
|
|
|
});
|
2018-03-12 08:42:59 -04:00
|
|
|
client.save();
|
2017-04-01 04:33:17 -04:00
|
|
|
|
2017-11-28 12:56:53 -05:00
|
|
|
chan.loadMessages(client, network);
|
|
|
|
|
2017-04-01 04:33:17 -04:00
|
|
|
// Request channels' modes
|
|
|
|
network.irc.raw("MODE", chan.name);
|
2018-03-02 05:29:40 -05:00
|
|
|
} else if (data.nick === irc.user.nick) {
|
2022-06-18 20:25:21 -04:00
|
|
|
chan.state = ChanState.JOINED;
|
2018-07-19 14:03:53 -04:00
|
|
|
|
|
|
|
client.emit("channel:state", {
|
|
|
|
chan: chan.id,
|
|
|
|
state: chan.state,
|
|
|
|
});
|
2014-09-13 17:29:45 -04:00
|
|
|
}
|
2017-11-10 15:44:14 -05:00
|
|
|
|
|
|
|
const user = new User({nick: data.nick});
|
|
|
|
const msg = new Msg({
|
2016-03-12 04:36:55 -05:00
|
|
|
time: data.time,
|
2017-11-10 15:44:14 -05:00
|
|
|
from: user,
|
2016-03-07 16:09:42 -05:00
|
|
|
hostmask: data.ident + "@" + data.hostname,
|
2020-11-18 18:25:28 -05:00
|
|
|
gecos: data.gecos,
|
|
|
|
account: data.account,
|
2022-06-18 20:25:21 -04:00
|
|
|
type: MessageType.JOIN,
|
2017-11-15 01:35:15 -05:00
|
|
|
self: data.nick === irc.user.nick,
|
2014-09-13 17:29:45 -04:00
|
|
|
});
|
2016-04-19 06:20:18 -04:00
|
|
|
chan.pushMessage(client, msg);
|
2017-11-10 15:44:14 -05:00
|
|
|
|
2017-11-16 15:32:03 -05:00
|
|
|
chan.setUser(new User({nick: data.nick}));
|
2017-11-10 15:44:14 -05:00
|
|
|
client.emit("users", {
|
|
|
|
chan: chan.id,
|
|
|
|
});
|
2014-09-13 17:29:45 -04:00
|
|
|
});
|
|
|
|
};
|