fix: should always call subscribe

This commit is contained in:
Paul Makles 2024-06-19 18:16:30 +01:00
parent 61304f18c2
commit c972e6813f
No known key found for this signature in database
2 changed files with 9 additions and 5 deletions

2
.env.production Normal file
View file

@ -0,0 +1,2 @@
# VITE_API_URL=http://local.revolt.chat:8000
VITE_API_URL=https://app.revolt.chat/api

View file

@ -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