Zero error milestone.

This commit is contained in:
Paul
2021-07-30 22:40:49 +01:00
parent c21453b281
commit 4c9554c5e9
41 changed files with 242 additions and 370 deletions

View File

@@ -1,11 +1,12 @@
import { autorun } from "mobx";
import { Channel } from "revolt.js/dist/maps/Channels";
import { useLayoutEffect } from "preact/hooks";
import { Channel } from "../../../mobx";
import { dispatch } from "../../../redux";
import { Unreads } from "../../../redux/reducers/unreads";
import { useClient } from "../../../context/revoltjs/RevoltClient";
import { HookContext, useForceUpdate } from "../../../context/revoltjs/hooks";
type UnreadProps = {
channel: Channel;
@@ -16,7 +17,10 @@ export function useUnreads({ channel, unreads }: UnreadProps) {
const client = useClient();
useLayoutEffect(() => {
function checkUnread(target?: Channel) {
function checkUnread(
target: Channel,
last_message: Channel["last_message"],
) {
if (!target) return;
if (target._id !== channel._id) return;
if (
@@ -46,10 +50,7 @@ export function useUnreads({ channel, unreads }: UnreadProps) {
}
}
checkUnread(channel);
client.channels.addListener("mutation", checkUnread);
return () => client.channels.removeListener("mutation", checkUnread);
return autorun(() => checkUnread(channel!, channel!.last_message));
}, [channel, unreads]);
}