From 0d9c184f19dd26fc9bc7e7c8b112e02c5261fe71 Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Thu, 16 May 2024 22:15:39 +0200 Subject: [PATCH] server: fix time handling The framework may emit messages which do not have a time stamp. We tried to unconditionally convert the time field, fix that. The Msg constructor replaces falsey time fields with the current date so we can also remove the duplication from that codepath. --- server/plugins/irc-events/message.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/server/plugins/irc-events/message.ts b/server/plugins/irc-events/message.ts index 2e496624..f35538f0 100644 --- a/server/plugins/irc-events/message.ts +++ b/server/plugins/irc-events/message.ts @@ -17,7 +17,7 @@ type HandleInput = { ident: string; target: string; type: MessageType; - time: number; + time?: number; text?: string; from_server?: boolean; message: string; @@ -25,7 +25,7 @@ type HandleInput = { }; function convertForHandle(type: MessageType, data: MessageEventArgs): HandleInput { - return {...data, time: data.time ? data.time : new Date().getTime(), type: type}; + return {...data, type: type}; } export default function (irc, network) { @@ -36,19 +36,16 @@ export default function (irc, network) { }); irc.on("action", function (data) { - data.type = MessageType.ACTION; - handleMessage(data); + handleMessage(convertForHandle(MessageType.ACTION, data)); }); irc.on("privmsg", function (data) { - data.type = MessageType.MESSAGE; - handleMessage(data); + handleMessage(convertForHandle(MessageType.MESSAGE, data)); }); irc.on("wallops", function (data) { data.from_server = true; - data.type = MessageType.WALLOPS; - handleMessage(data); + handleMessage(convertForHandle(MessageType.WALLOPS, data)); }); function handleMessage(data: HandleInput) { @@ -129,7 +126,7 @@ export default function (irc, network) { // msg is constructed down here because `from` is being copied in the constructor const msg = new Msg({ type: data.type, - time: new Date(data.time), + time: data.time ? new Date(data.time) : undefined, text: data.message, self: self, from: from,