Skip to content

Commit

Permalink
server: fix time handling
Browse files Browse the repository at this point in the history
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.

(cherry picked from commit 0d9c184)
  • Loading branch information
brunnre8 authored and f0x52 committed May 20, 2024
1 parent 652a17d commit 5c1ab79
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions server/plugins/irc-events/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ type HandleInput = {
ident: string;
target: string;
type: MessageType;
time: number;
time?: number;
text?: string;
from_server?: boolean;
message: string;
group?: string;
};

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 <IrcEventHandler>function (irc, network) {
Expand All @@ -36,19 +36,16 @@ export default <IrcEventHandler>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) {
Expand Down Expand Up @@ -129,7 +126,7 @@ export default <IrcEventHandler>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,
Expand Down

0 comments on commit 5c1ab79

Please sign in to comment.