Fix unreads and mark as read.

This commit is contained in:
Paul
2021-09-14 21:09:42 +01:00
parent fc03336ea3
commit 4b8ad44aa9
4 changed files with 11 additions and 14 deletions

View File

@@ -1,7 +1,7 @@
import { reaction } from "mobx";
import { Channel } from "revolt.js/dist/maps/Channels";
import { useLayoutEffect } from "preact/hooks";
import { useLayoutEffect, useRef } from "preact/hooks";
import { dispatch } from "../../../redux";
import { Unreads } from "../../../redux/reducers/unreads";
@@ -12,6 +12,7 @@ type UnreadProps = {
};
export function useUnreads({ channel, unreads }: UnreadProps) {
const firstLoad = useRef(true);
useLayoutEffect(() => {
function checkUnread(target: Channel) {
if (!target) return;
@@ -35,7 +36,8 @@ export function useUnreads({ channel, unreads }: UnreadProps) {
message,
});
channel.ack(message);
channel.ack(message, firstLoad.current);
firstLoad.current = false;
}
}
}

View File

@@ -170,18 +170,13 @@ function ContextMenus(props: Props) {
)
return;
const message =
typeof data.channel.last_message === "string"
? data.channel.last_message
: data.channel.last_message!._id;
dispatch({
type: "UNREADS_MARK_READ",
channel: data.channel._id,
message,
message: data.channel.last_message_id!,
});
data.channel.ack(message);
data.channel.ack(undefined, true);
}
break;
case "mark_server_as_read":