thelounge/server/plugins/irc-events/topic.ts
Max Leiter dd05ee3a65
TypeScript and Vue 3 (#4559)
Co-authored-by: Eric Nemchik <eric@nemchik.com>
Co-authored-by: Pavel Djundik <xPaw@users.noreply.github.com>
2022-06-18 17:25:21 -07:00

46 lines
998 B
TypeScript

import {IrcEventHandler} from "../../client";
import Msg, {MessageType} from "../../models/msg";
export default <IrcEventHandler>function (irc, network) {
const client = this;
irc.on("topic", function (data) {
const chan = network.getChannel(data.channel);
if (typeof chan === "undefined") {
return;
}
const msg = new Msg({
time: data.time,
type: MessageType.TOPIC,
from: data.nick && chan.getUser(data.nick),
text: data.topic,
self: data.nick === irc.user.nick,
});
chan.pushMessage(client, msg);
chan.topic = data.topic;
client.emit("topic", {
chan: chan.id,
topic: chan.topic,
});
});
irc.on("topicsetby", function (data) {
const chan = network.getChannel(data.channel);
if (typeof chan === "undefined") {
return;
}
const msg = new Msg({
type: MessageType.TOPIC_SET_BY,
from: chan.getUser(data.nick),
when: new Date(data.when * 1000),
self: data.nick === irc.user.nick,
});
chan.pushMessage(client, msg);
});
};