2022-06-19 00:25:21 +00:00
|
|
|
import {IrcEventHandler} from "../../client";
|
|
|
|
import {ChanType} from "../../models/chan";
|
|
|
|
import Msg, {MessageType} from "../../models/msg";
|
2017-07-10 16:01:20 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
export default <IrcEventHandler>function (irc, network) {
|
2017-07-10 16:01:20 +00:00
|
|
|
const client = this;
|
2018-06-20 16:32:19 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
irc.on("away", (data) => handleAway(MessageType.AWAY, data));
|
|
|
|
irc.on("back", (data) => handleAway(MessageType.BACK, data));
|
2018-06-20 16:32:19 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
function handleAway(type: MessageType, data) {
|
2017-07-10 16:01:20 +00:00
|
|
|
const away = data.message;
|
|
|
|
|
2018-06-20 16:32:19 +00:00
|
|
|
if (data.self) {
|
|
|
|
const msg = new Msg({
|
|
|
|
self: true,
|
|
|
|
type: type,
|
|
|
|
text: away,
|
|
|
|
time: data.time,
|
|
|
|
});
|
|
|
|
|
|
|
|
network.channels[0].pushMessage(client, msg, true);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-10 16:01:20 +00:00
|
|
|
network.channels.forEach((chan) => {
|
2018-06-20 16:45:27 +00:00
|
|
|
let user;
|
2017-07-10 16:01:20 +00:00
|
|
|
|
2018-06-20 16:45:27 +00:00
|
|
|
switch (chan.type) {
|
2022-06-19 00:25:21 +00:00
|
|
|
case ChanType.QUERY: {
|
2019-07-17 09:33:59 +00:00
|
|
|
if (data.nick.toLowerCase() !== chan.name.toLowerCase()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-06-20 16:45:27 +00:00
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
if (chan.userAway === away) {
|
|
|
|
return;
|
|
|
|
}
|
2018-08-26 20:14:09 +00:00
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
// Store current away message on channel model,
|
|
|
|
// because query windows have no users
|
|
|
|
chan.userAway = away;
|
2018-08-26 20:14:09 +00:00
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
user = chan.getUser(data.nick);
|
2018-06-20 16:45:27 +00:00
|
|
|
|
2019-11-02 14:53:41 +00:00
|
|
|
const msg = new Msg({
|
|
|
|
type: type,
|
|
|
|
text: away || "",
|
|
|
|
time: data.time,
|
|
|
|
from: user,
|
|
|
|
});
|
|
|
|
|
|
|
|
chan.pushMessage(client, msg);
|
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
break;
|
2019-11-02 14:53:41 +00:00
|
|
|
}
|
2018-06-20 16:45:27 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
case ChanType.CHANNEL: {
|
2019-07-17 09:33:59 +00:00
|
|
|
user = chan.findUser(data.nick);
|
2018-06-20 16:45:27 +00:00
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
if (!user || user.away === away) {
|
|
|
|
return;
|
|
|
|
}
|
2018-06-20 16:45:27 +00:00
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
user.away = away;
|
2018-08-26 20:14:09 +00:00
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
break;
|
2019-11-02 14:53:41 +00:00
|
|
|
}
|
2017-07-10 16:01:20 +00:00
|
|
|
}
|
|
|
|
});
|
2018-06-20 16:32:19 +00:00
|
|
|
}
|
2017-07-10 16:01:20 +00:00
|
|
|
};
|