mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-27 09:30:55 -05:00
Compare commits
1 commit
b2985ae155
...
c6daf0592f
Author | SHA1 | Date | |
---|---|---|---|
|
c6daf0592f |
4 changed files with 7 additions and 89 deletions
4
.env
4
.env
|
@ -1,5 +1,5 @@
|
||||||
# VITE_API_URL=https://api.revolt.chat
|
# VITE_API_URL=https://api.revolt.chat
|
||||||
# VITE_API_URL=https://app.revolt.chat/api
|
VITE_API_URL=https://app.revolt.chat/api
|
||||||
# VITE_API_URL=http://local.revolt.chat:8000
|
# VITE_API_URL=http://local.revolt.chat:8000
|
||||||
VITE_API_URL=https://revolt.chat/api
|
# VITE_API_URL=https://revolt.chat/api
|
||||||
VITE_THEMES_URL=https://themes.revolt.chat
|
VITE_THEMES_URL=https://themes.revolt.chat
|
||||||
|
|
|
@ -12,7 +12,7 @@ import { IconButton, Preloader } from "@revoltchat/ui";
|
||||||
import { determineFileSize } from "../../../../lib/fileSize";
|
import { determineFileSize } from "../../../../lib/fileSize";
|
||||||
|
|
||||||
import { modalController } from "../../../modals/ModalController";
|
import { modalController } from "../../../modals/ModalController";
|
||||||
import { clientController, useClient } from "../../ClientController";
|
import { useClient } from "../../ClientController";
|
||||||
import { takeError } from "../error";
|
import { takeError } from "../error";
|
||||||
|
|
||||||
type BehaviourType =
|
type BehaviourType =
|
||||||
|
@ -67,16 +67,9 @@ export async function uploadFile(
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("file", file);
|
formData.append("file", file);
|
||||||
|
|
||||||
const client = clientController.getActiveSession()?.client;
|
|
||||||
const sesToken =
|
|
||||||
typeof client?.session === "string"
|
|
||||||
? client.session
|
|
||||||
: client?.session?.token;
|
|
||||||
|
|
||||||
const res = await Axios.post(`${autumnURL}/${tag}`, formData, {
|
const res = await Axios.post(`${autumnURL}/${tag}`, formData, {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "multipart/form-data",
|
"Content-Type": "multipart/form-data",
|
||||||
"X-Session-Token": sesToken,
|
|
||||||
},
|
},
|
||||||
...config,
|
...config,
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { Hash } from "@styled-icons/boxicons-regular";
|
import { Hash } from "@styled-icons/boxicons-regular";
|
||||||
import { Ghost } from "@styled-icons/boxicons-solid";
|
import { Ghost } from "@styled-icons/boxicons-solid";
|
||||||
import dayjs from "dayjs";
|
|
||||||
import { reaction } from "mobx";
|
import { reaction } from "mobx";
|
||||||
import { observer } from "mobx-react-lite";
|
import { observer } from "mobx-react-lite";
|
||||||
import { Redirect, useParams } from "react-router-dom";
|
import { Redirect, useParams } from "react-router-dom";
|
||||||
|
@ -164,7 +163,6 @@ const TextChannel = observer(({ channel }: { channel: ChannelI }) => {
|
||||||
|
|
||||||
const checkUnread = () =>
|
const checkUnread = () =>
|
||||||
channel.unread &&
|
channel.unread &&
|
||||||
document.hasFocus() &&
|
|
||||||
channel.client.unreads!.markRead(
|
channel.client.unreads!.markRead(
|
||||||
channel._id,
|
channel._id,
|
||||||
channel.last_message_id!,
|
channel.last_message_id!,
|
||||||
|
@ -178,46 +176,6 @@ const TextChannel = observer(({ channel }: { channel: ChannelI }) => {
|
||||||
);
|
);
|
||||||
}, [channel]);
|
}, [channel]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let lastSubscribed: number | undefined;
|
|
||||||
function subscribe() {
|
|
||||||
if (document.hasFocus()) {
|
|
||||||
if (
|
|
||||||
!lastSubscribed ||
|
|
||||||
dayjs().subtract(10, "minutes").isAfter(lastSubscribed)
|
|
||||||
) {
|
|
||||||
lastSubscribed = +new Date();
|
|
||||||
channel.server?.subscribe();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trigger logic every minute
|
|
||||||
const subTimer = setInterval(subscribe, 60e3);
|
|
||||||
subscribe();
|
|
||||||
|
|
||||||
function onFocus() {
|
|
||||||
// Mark channel as read if it's unread
|
|
||||||
if (channel.unread) {
|
|
||||||
channel.client.unreads!.markRead(
|
|
||||||
channel._id,
|
|
||||||
channel.last_message_id!,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Subscribe to channel if expired
|
|
||||||
subscribe();
|
|
||||||
}
|
|
||||||
|
|
||||||
addEventListener("focus", onFocus);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
removeEventListener("focus", onFocus);
|
|
||||||
clearInterval(subTimer);
|
|
||||||
};
|
|
||||||
}, [channel]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AgeGate
|
<AgeGate
|
||||||
type="channel"
|
type="channel"
|
||||||
|
|
|
@ -103,43 +103,10 @@ export const Members = ({ server }: Props) => {
|
||||||
const [query, setQuery] = useState("");
|
const [query, setQuery] = useState("");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function fetch() {
|
server
|
||||||
server
|
.fetchMembers()
|
||||||
.fetchMembers()
|
.then((data) => data.members)
|
||||||
.then((data) => data.members)
|
.then(setData);
|
||||||
.then(setData);
|
|
||||||
}
|
|
||||||
|
|
||||||
fetch();
|
|
||||||
|
|
||||||
// Members may be invalidated if we stop receiving events
|
|
||||||
// This is not very accurate, this should be tracked within
|
|
||||||
// revolt.js so we know the true validity.
|
|
||||||
let valid = true,
|
|
||||||
invalidationTimer: number;
|
|
||||||
|
|
||||||
function waitToInvalidate() {
|
|
||||||
invalidationTimer = setTimeout(() => {
|
|
||||||
valid = false;
|
|
||||||
}, 15 * 60e3) as never; // 15 minutes
|
|
||||||
}
|
|
||||||
|
|
||||||
function cancelInvalidation() {
|
|
||||||
if (!valid) {
|
|
||||||
fetch();
|
|
||||||
valid = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
clearTimeout(invalidationTimer);
|
|
||||||
}
|
|
||||||
|
|
||||||
addEventListener("blur", waitToInvalidate);
|
|
||||||
addEventListener("focus", cancelInvalidation);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
removeEventListener("blur", waitToInvalidate);
|
|
||||||
removeEventListener("focus", cancelInvalidation);
|
|
||||||
};
|
|
||||||
}, [server, setData]);
|
}, [server, setData]);
|
||||||
|
|
||||||
const members = useMemo(
|
const members = useMemo(
|
||||||
|
|
Loading…
Reference in a new issue