resolve issues with new features
This commit is contained in:
@@ -17,6 +17,7 @@ import { Link } from 'react-router-dom';
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { configApi } from '../../services/config';
|
||||
import { notificationsApi } from '../../services/notifications';
|
||||
import { nextcloudApi } from '../../services/nextcloud';
|
||||
import { safeOpenUrl } from '../../utils/safeOpenUrl';
|
||||
import ChatRoomList from './ChatRoomList';
|
||||
import ChatMessageView from './ChatMessageView';
|
||||
@@ -36,12 +37,27 @@ const ChatPanelInner: React.FC = () => {
|
||||
});
|
||||
const nextcloudUrl = externalLinks?.nextcloud;
|
||||
|
||||
// Keep a ref to rooms so the effect can access the latest list without
|
||||
// re-running every time room data refreshes.
|
||||
const roomsRef = React.useRef(rooms);
|
||||
roomsRef.current = rooms;
|
||||
|
||||
React.useEffect(() => {
|
||||
if (chatPanelOpen) {
|
||||
// Dismiss our internal notification-centre entries
|
||||
notificationsApi.dismissByType('nextcloud_talk').then(() => {
|
||||
queryClient.invalidateQueries({ queryKey: ['notifications'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['unreadNotificationCount'] });
|
||||
}).catch(() => {});
|
||||
|
||||
// Also mark all unread rooms as read directly in Nextcloud so that
|
||||
// Nextcloud's own notification badges clear as well.
|
||||
roomsRef.current
|
||||
.filter((r) => r.unreadMessages > 0)
|
||||
.forEach((r) => {
|
||||
nextcloudApi.markAsRead(r.token).catch(() => {});
|
||||
});
|
||||
queryClient.invalidateQueries({ queryKey: ['nextcloud', 'rooms'] });
|
||||
}
|
||||
}, [chatPanelOpen, queryClient]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user