mirror of
https://github.com/revoltchat/revite.git
synced 2024-12-25 23:22:06 -05:00
fix: should always call subscribe
This commit is contained in:
parent
61304f18c2
commit
c972e6813f
2 changed files with 9 additions and 5 deletions
2
.env.production
Normal file
2
.env.production
Normal file
|
@ -0,0 +1,2 @@
|
|||
# VITE_API_URL=http://local.revolt.chat:8000
|
||||
VITE_API_URL=https://app.revolt.chat/api
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue