From 9030a2f010d06232c5bee1d071998327081060d6 Mon Sep 17 00:00:00 2001 From: chylex Date: Thu, 15 Feb 2024 13:02:21 +0100 Subject: [PATCH] Update message timestamp processing for latest Discord update Closes #249 --- app/Resources/Tracker/scripts/state.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/app/Resources/Tracker/scripts/state.js b/app/Resources/Tracker/scripts/state.js index 826550a..0561c6a 100644 --- a/app/Resources/Tracker/scripts/state.js +++ b/app/Resources/Tracker/scripts/state.js @@ -48,6 +48,16 @@ const STATE = (function() { }); }; + const getDate = function(date) { + if (date instanceof Date) { + return date; + } + else { + // noinspection JSUnresolvedReference + return date.toDate(); + } + }; + const trackingStateChangedListeners = []; let isTracking = false; @@ -69,8 +79,8 @@ const STATE = (function() { * @property {String} channel_id * @property {DiscordUser} author * @property {String} content - * @property {Timestamp} timestamp - * @property {Timestamp|null} editedTimestamp + * @property {Date} timestamp + * @property {Date|null} editedTimestamp * @property {DiscordAttachment[]} attachments * @property {Object[]} embeds * @property {DiscordMessageReaction[]} [reactions] @@ -106,11 +116,6 @@ const STATE = (function() { * @property {Boolean} animated */ - /** - * @name Timestamp - * @property {Function} toDate - */ - return { setup(port, token) { serverPort = port; @@ -223,12 +228,12 @@ const STATE = (function() { sender: msg.author.id, channel: msg.channel_id, text: msg.content, - timestamp: msg.timestamp.toDate().getTime() + timestamp: getDate(msg.timestamp).getTime() }; if (msg.editedTimestamp !== null) { // noinspection JSUnusedGlobalSymbols - obj.editTimestamp = msg.editedTimestamp.toDate().getTime(); + obj.editTimestamp = getDate(msg.editedTimestamp).getTime(); } if (msg.messageReference !== null) {