update
This commit is contained in:
@@ -30,6 +30,7 @@ const ChatPanelInner: React.FC = () => {
|
||||
const { chatPanelOpen, setChatPanelOpen } = useLayout();
|
||||
const { rooms, selectedRoomToken, selectRoom, connected } = useChat();
|
||||
const queryClient = useQueryClient();
|
||||
const markedRoomsRef = React.useRef(new Set<string>());
|
||||
const { data: externalLinks } = useQuery({
|
||||
queryKey: ['external-links'],
|
||||
queryFn: () => configApi.getExternalLinks(),
|
||||
@@ -46,11 +47,17 @@ const ChatPanelInner: React.FC = () => {
|
||||
}).catch(() => {});
|
||||
}, [chatPanelOpen, queryClient]);
|
||||
|
||||
// Mark unread rooms as read in Nextcloud whenever panel is open and rooms update
|
||||
// Mark unread rooms as read in Nextcloud whenever panel is open
|
||||
React.useEffect(() => {
|
||||
if (!chatPanelOpen) return;
|
||||
const unread = rooms.filter((r) => r.unreadMessages > 0);
|
||||
if (!chatPanelOpen) {
|
||||
markedRoomsRef.current.clear();
|
||||
return;
|
||||
}
|
||||
const unread = rooms.filter(
|
||||
(r) => r.unreadMessages > 0 && !markedRoomsRef.current.has(r.token),
|
||||
);
|
||||
if (unread.length === 0) return;
|
||||
unread.forEach((r) => markedRoomsRef.current.add(r.token));
|
||||
Promise.allSettled(unread.map((r) => nextcloudApi.markAsRead(r.token))).then(() => {
|
||||
queryClient.invalidateQueries({ queryKey: ['nextcloud', 'rooms'] });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user