From c972e6813f953eb8f53045fd54bfd6d4e67ab401 Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Wed, 19 Jun 2024 18:16:30 +0100 Subject: [PATCH] fix: should always call subscribe --- .env.production | 2 ++ src/pages/channels/Channel.tsx | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 .env.production diff --git a/.env.production b/.env.production new file mode 100644 index 00000000..327e0600 --- /dev/null +++ b/.env.production @@ -0,0 +1,2 @@ +# VITE_API_URL=http://local.revolt.chat:8000 +VITE_API_URL=https://app.revolt.chat/api diff --git a/src/pages/channels/Channel.tsx b/src/pages/channels/Channel.tsx index c60de584..62857c79 100644 --- a/src/pages/channels/Channel.tsx +++ b/src/pages/channels/Channel.tsx @@ -1,5 +1,6 @@ import { Hash } from "@styled-icons/boxicons-regular"; import { Ghost } from "@styled-icons/boxicons-solid"; +import dayjs from "dayjs"; import { reaction } from "mobx"; import { observer } from "mobx-react-lite"; import { Redirect, useParams } from "react-router-dom"; @@ -181,18 +182,19 @@ const TextChannel = observer(({ channel }: { channel: ChannelI }) => { let lastSubscribed: number | undefined; function subscribe() { if (document.hasFocus()) { - const tenMinutesAgo = new Date(); - tenMinutesAgo.setMinutes(tenMinutesAgo.getMinutes() - 10); - - if (!lastSubscribed || +tenMinutesAgo > lastSubscribed) { + if ( + !lastSubscribed || + dayjs().subtract(10, "minutes").isAfter(lastSubscribed) + ) { + lastSubscribed = +new Date(); channel.server?.subscribe(); - lastSubscribed = +tenMinutesAgo; } } } // Trigger logic every minute const subTimer = setInterval(subscribe, 60e3); + subscribe(); function onFocus() { // Mark channel as read if it's unread