Add notification config
This commit is contained in:
parent
510dc8ac05
commit
adf3a2d3fe
|
@ -0,0 +1,4 @@
|
||||||
|
allowXSS: true
|
||||||
|
maxDuration: 60000
|
||||||
|
defaultDuration: 7000
|
||||||
|
allTarget: all
|
|
@ -1,16 +1,35 @@
|
||||||
import { ChannelList } from "../../../../channel/ChannelList";
|
import { ChannelList } from "../../../../channel/ChannelList";
|
||||||
|
import { loadConfig } from "../../../../util/config";
|
||||||
import { ServerEventListener } from "../../../../util/types";
|
import { ServerEventListener } from "../../../../util/types";
|
||||||
import { socketsBySocketID } from "../../../Socket";
|
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"> = {
|
export const notification: ServerEventListener<"notification"> = {
|
||||||
id: "notification",
|
id: "notification",
|
||||||
callback: async (msg, socket) => {
|
callback: async (msg, socket) => {
|
||||||
// Send notification to user/channel
|
// Send notification to user/channel
|
||||||
if (typeof msg.targetChannel == "undefined" && typeof msg.targetUser == "undefined") return;
|
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") {
|
if (typeof msg.targetChannel !== "undefined") {
|
||||||
for (const ch of ChannelList.getList().values()) {
|
for (const ch of ChannelList.getList().values()) {
|
||||||
if (ch.getID() == msg.targetChannel) {
|
if (ch.getID() == msg.targetChannel || msg.targetChannel == config.allTarget) {
|
||||||
ch.sendNotification(msg);
|
ch.sendNotification(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue