Add notification config

This commit is contained in:
Hri7566 2024-07-12 17:29:24 -04:00
parent 510dc8ac05
commit adf3a2d3fe
2 changed files with 24 additions and 1 deletions

4
config/notifications.yml Normal file
View File

@ -0,0 +1,4 @@
allowXSS: true
maxDuration: 60000
defaultDuration: 7000
allTarget: all

View File

@ -1,16 +1,35 @@
import { ChannelList } from "../../../../channel/ChannelList";
import { loadConfig } from "../../../../util/config";
import { ServerEventListener } from "../../../../util/types";
import { socketsBySocketID } from "../../../Socket";
const config = loadConfig<{
allowXSS: boolean;
maxDuration: number;
defaultDuration: number;
allTarget: string;
}>("config/notifications.yml", {
allowXSS: true,
maxDuration: 60000,
defaultDuration: 7000,
allTarget: "all"
});
export const notification: ServerEventListener<"notification"> = {
id: "notification",
callback: async (msg, socket) => {
// Send notification to user/channel
if (typeof msg.targetChannel == "undefined" && typeof msg.targetUser == "undefined") return;
if (msg.duration) {
if (msg.duration > config.maxDuration) msg.duration = config.maxDuration;
} else {
msg.duration = config.defaultDuration;
}
if (typeof msg.targetChannel !== "undefined") {
for (const ch of ChannelList.getList().values()) {
if (ch.getID() == msg.targetChannel) {
if (ch.getID() == msg.targetChannel || msg.targetChannel == config.allTarget) {
ch.sendNotification(msg);
}
}