fix: unread count without muted

This commit is contained in:
Tristan Yang
2023-06-12 21:43:22 +08:00
parent e1a45dc710
commit 0151a8ff8c
3 changed files with 60 additions and 38 deletions
+6 -6
View File
@@ -24,8 +24,8 @@ export interface State {
historyChannels: { [cid: number]: string | "reached" };
readUsers: { [uid: number]: number };
readChannels: { [cid: number]: number };
muteUsers: { [uid: number]: { expired_in?: number } | undefined };
muteChannels: { [cid: number]: { expired_in?: number } | undefined };
muteUsers: { [uid: number]: { expired_at?: number } | undefined };
muteChannels: { [cid: number]: { expired_at?: number } | undefined };
autoDeleteMsgUsers: AutoDeleteMsgForUser[];
autoDeleteMsgChannels: AutoDeleteMsgForGroup[];
channelAsides: { [cid: number]: ChannelAside };
@@ -160,15 +160,15 @@ const footprintSlice = createSlice({
}
case "add_users": {
const mutes = payload.add_users;
mutes?.forEach(({ uid, expired_in }) => {
state.muteUsers[uid] = { expired_in };
mutes?.forEach(({ uid, expired_at }) => {
state.muteUsers[uid] = { expired_at };
});
break;
}
case "add_groups": {
const mutes = payload.add_groups;
mutes?.forEach(({ gid, expired_in }) => {
state.muteChannels[gid] = { expired_in };
mutes?.forEach(({ gid, expired_at }) => {
state.muteChannels[gid] = { expired_at };
});
break;
}
+52 -30
View File
@@ -7,45 +7,57 @@ import getUnreadCount from "../routes/chat/utils";
let total = 0;
let title = "";
const UnreadTabTip = () => {
const { userData, dmMids, channelMids, messageData, readChannels, readUsers, loginUid } =
useAppSelector((store) => {
return {
userData: store.users.byId,
dmMids: store.userMessage.byId,
channelMids: store.channelMessage,
messageData: store.message,
readChannels: store.footprint.readChannels,
readUsers: store.footprint.readUsers,
loginUid: store.authData.user?.uid ?? 0
};
});
const {
muteChannels,
muteUsers,
userData,
dmMids,
channelMids,
messageData,
readChannels,
readUsers,
loginUid
} = useAppSelector((store) => {
return {
userData: store.users.byId,
dmMids: store.userMessage.byId,
channelMids: store.channelMessage,
messageData: store.message,
readChannels: store.footprint.readChannels,
readUsers: store.footprint.readUsers,
muteChannels: store.footprint.muteChannels,
muteUsers: store.footprint.muteUsers,
loginUid: store.authData.user?.uid ?? 0
};
});
useEffect(() => {
total = 0;
// dm
Object.entries(dmMids).forEach(([id, mids]) => {
if (userData[+id]) {
const { unreads = 0 } = getUnreadCount({
mids,
readIndex: readUsers[+id],
messageData,
loginUid
});
if (unreads > 0) {
console.log("unreadsss", id, mids);
if (!muteUsers[id]) {
if (userData[+id]) {
const { unreads = 0 } = getUnreadCount({
mids,
readIndex: readUsers[+id],
messageData,
loginUid
});
total += unreads;
}
total += unreads;
}
});
// channel
Object.entries(channelMids).map(([id, mids]) => {
const { unreads = 0 } = getUnreadCount({
mids,
readIndex: readChannels[+id],
messageData,
loginUid
});
total += unreads;
if (!muteChannels[id]) {
const { unreads = 0 } = getUnreadCount({
mids,
readIndex: readChannels[+id],
messageData,
loginUid
});
total += unreads;
}
});
const handler = () => {
console.log("changed", document.hidden, total);
@@ -66,7 +78,17 @@ const UnreadTabTip = () => {
return () => {
document.removeEventListener("visibilitychange", handler);
};
}, [userData, dmMids, channelMids, readChannels, messageData, loginUid, readUsers]);
}, [
userData,
dmMids,
channelMids,
readChannels,
messageData,
loginUid,
readUsers,
muteChannels,
muteUsers
]);
return null;
};
+2 -2
View File
@@ -11,11 +11,11 @@ export type ContentTypeKey = "text" | "markdown" | "file" | "audio" | "archive";
export interface MuteDTO {
add_users?: {
uid: number;
expired_in?: number;
expired_at?: number;
}[];
add_groups?: {
gid: number;
expired_in?: number;
expired_at?: number;
}[];
remove_users?: number[];
remove_groups?: number[];