forked from abner/for-legacy-web
Fix unreads and mark as read.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user