thelounge/src/plugins/irc-events/join.ts

61 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-05-05 00:41:57 +02:00
import Msg, {MessageType} from "../../models/msg";
import User from "../../models/user";
2022-05-05 00:41:57 +02:00
import type {IrcEventHandler} from "../../client";
import {ChanState} from "../../models/chan";
2022-05-05 00:41:57 +02:00
export default <IrcEventHandler>function (irc, network) {
const client = this;
irc.on("join", function (data) {
let chan = network.getChannel(data.channel);
2014-09-13 23:29:45 +02:00
if (typeof chan === "undefined") {
chan = client.createChannel({
name: data.channel,
state: ChanState.JOINED,
2014-09-13 23:29:45 +02:00
});
2014-09-13 23:29:45 +02:00
client.emit("join", {
network: network.uuid,
chan: chan.getFilteredClone(true),
index: network.addChannel(chan),
2014-09-13 23:29:45 +02:00
});
client.save();
2017-04-01 10:33:17 +02:00
2017-11-28 18:56:53 +01:00
chan.loadMessages(client, network);
2017-04-01 10:33:17 +02:00
// Request channels' modes
network.irc.raw("MODE", chan.name);
} else if (data.nick === irc.user.nick) {
chan.state = ChanState.JOINED;
2022-06-03 05:02:24 +02:00
// Don't react to our own join
if (data.batch?.type !== "chathistory") {
network.irc.chatHistory.latest(chan.name);
}
client.emit("channel:state", {
chan: chan.id,
state: chan.state,
});
2014-09-13 23:29:45 +02:00
}
const user = new User({nick: data.nick});
const msg = new Msg({
2016-03-12 10:36:55 +01:00
time: data.time,
from: user,
hostmask: data.ident + "@" + data.hostname,
gecos: data.gecos,
account: data.account,
type: MessageType.JOIN,
self: data.nick === irc.user.nick,
2014-09-13 23:29:45 +02:00
});
chan.pushMessage(client, msg);
2017-11-16 21:32:03 +01:00
chan.setUser(new User({nick: data.nick}));
client.emit("users", {
chan: chan.id,
});
2014-09-13 23:29:45 +02:00
});
};