nicolium: some markers support
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
@ -162,12 +162,16 @@ const useUserStream = () => {
|
||||
case 'announcement.delete':
|
||||
deleteAnnouncement(event.payload);
|
||||
break;
|
||||
case 'marker':
|
||||
queryClient.setQueryData(
|
||||
queryKeys.markers.notifications,
|
||||
event.payload.notifications ?? null,
|
||||
);
|
||||
case 'marker': {
|
||||
for (const timeline in event.payload) {
|
||||
queryClient.setQueryData(
|
||||
queryKeys.markers.timeline(timeline as 'home' | 'notifications'),
|
||||
event.payload[timeline] ?? null,
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
||||
@ -19,17 +19,17 @@ import { useOwnAccount } from '@/hooks/use-own-account';
|
||||
import { prefetchFollowRequests } from '@/queries/accounts/use-follow-requests';
|
||||
import { queryClient } from '@/queries/client';
|
||||
import { prefetchCustomEmojis } from '@/queries/instance/use-custom-emojis';
|
||||
import {
|
||||
usePrefetchNotifications,
|
||||
usePrefetchNotificationsMarker,
|
||||
} from '@/queries/notifications/use-notifications';
|
||||
import { usePrefetchNotificationsMarker } from '@/queries/markers/use-markers';
|
||||
import { usePrefetchNotifications } from '@/queries/notifications/use-notifications';
|
||||
import { useFilters } from '@/queries/settings/use-filters';
|
||||
import { scheduledStatusesQueryOptions } from '@/queries/statuses/scheduled-statuses';
|
||||
import { useShoutboxSubscription } from '@/stores/shoutbox';
|
||||
import { useIsDropdownMenuOpen } from '@/stores/ui';
|
||||
import { getVapidKey } from '@/utils/auth';
|
||||
import { isStandalone } from '@/utils/state';
|
||||
|
||||
// Dummy import, to make sure that <Status /> ends up in the application bundle.
|
||||
// Without this it ends up in ~8 very commonly used bundles.
|
||||
import '@/components/statuses/status';
|
||||
import {
|
||||
ModalRoot,
|
||||
AccountHoverCard,
|
||||
@ -37,9 +37,6 @@ import {
|
||||
DropdownNavigation,
|
||||
StatusHoverCard,
|
||||
} from './util/async-components';
|
||||
// Dummy import, to make sure that <Status /> ends up in the application bundle.
|
||||
// Without this it ends up in ~8 very commonly used bundles.
|
||||
import '@/components/statuses/status';
|
||||
import GlobalHotkeys from './util/global-hotkeys';
|
||||
|
||||
const UI: React.FC = React.memo(() => {
|
||||
|
||||
@ -375,7 +375,10 @@ const notifications = {
|
||||
|
||||
const markers = {
|
||||
root: ['markers'] as const,
|
||||
notifications: ['markers', 'notifications'] as TaggedKey<['markers', 'notifications'], Marker>,
|
||||
timeline: (timeline: 'home' | 'notifications') => {
|
||||
const key = ['markers', timeline] as const;
|
||||
return key as TaggedKey<typeof key, Marker>;
|
||||
},
|
||||
};
|
||||
|
||||
const search = {
|
||||
|
||||
@ -1,20 +1,46 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { useClient } from '@/hooks/use-client';
|
||||
import { useLoggedIn } from '@/hooks/use-logged-in';
|
||||
|
||||
import { queryKeys } from '../keys';
|
||||
|
||||
const useNotificationsMarker = () => {
|
||||
const useMarker = (timeline: 'home' | 'notifications') => {
|
||||
const client = useClient();
|
||||
const { me } = useLoggedIn();
|
||||
|
||||
return useQuery({
|
||||
queryKey: queryKeys.markers.notifications,
|
||||
queryFn: async () =>
|
||||
(await client.timelines.getMarkers(['notifications'])).notifications ?? null,
|
||||
queryKey: queryKeys.markers.timeline(timeline),
|
||||
queryFn: async () => (await client.timelines.getMarkers([timeline]))[timeline] ?? null,
|
||||
enabled: !!me,
|
||||
});
|
||||
};
|
||||
|
||||
export { useNotificationsMarker };
|
||||
const useNotificationsMarker = () => useMarker('notifications');
|
||||
|
||||
const useHomeTimelineMarker = () => useMarker('home');
|
||||
|
||||
const usePrefetchMarker = (timeline: 'home' | 'notifications') => {
|
||||
const client = useClient();
|
||||
const queryClient = useQueryClient();
|
||||
const { me } = useLoggedIn();
|
||||
|
||||
useEffect(() => {
|
||||
if (!me) return;
|
||||
queryClient.prefetchQuery({
|
||||
queryKey: queryKeys.markers.timeline(timeline),
|
||||
queryFn: async () => (await client.timelines.getMarkers([timeline]))[timeline] ?? null,
|
||||
});
|
||||
}, [me, timeline]);
|
||||
};
|
||||
|
||||
const usePrefetchHomeTimelineMarker = () => usePrefetchMarker('home');
|
||||
const usePrefetchNotificationsMarker = () => usePrefetchMarker('notifications');
|
||||
|
||||
export {
|
||||
useNotificationsMarker,
|
||||
useHomeTimelineMarker,
|
||||
usePrefetchHomeTimelineMarker,
|
||||
usePrefetchNotificationsMarker,
|
||||
};
|
||||
|
||||
@ -149,21 +149,6 @@ const useNotification = (notification: NotificationGroup) => {
|
||||
}, [notification, status, target, accounts.data]);
|
||||
};
|
||||
|
||||
const usePrefetchNotificationsMarker = () => {
|
||||
const client = useClient();
|
||||
const queryClient = useQueryClient();
|
||||
const { me } = useLoggedIn();
|
||||
|
||||
useEffect(() => {
|
||||
if (!me) return;
|
||||
queryClient.prefetchQuery({
|
||||
queryKey: queryKeys.markers.notifications,
|
||||
queryFn: async () =>
|
||||
(await client.timelines.getMarkers(['notifications'])).notifications ?? null,
|
||||
});
|
||||
}, [me]);
|
||||
};
|
||||
|
||||
const useProcessStreamNotification = () => {
|
||||
const intl = useIntl();
|
||||
const { data: filters = [] } = useFiltersByContext('notifications');
|
||||
@ -261,7 +246,7 @@ const useMarkNotificationsReadMutation = () => {
|
||||
mutationFn: async (lastReadId?: string | null) => {
|
||||
if (!lastReadId) return;
|
||||
|
||||
const currentMarker = queryClient.getQueryData(queryKeys.markers.notifications);
|
||||
const currentMarker = queryClient.getQueryData(queryKeys.markers.timeline('notifications'));
|
||||
if (currentMarker && compareId(currentMarker.last_read_id, lastReadId) >= 0) {
|
||||
return;
|
||||
}
|
||||
@ -274,7 +259,10 @@ const useMarkNotificationsReadMutation = () => {
|
||||
},
|
||||
onSuccess: (markers) => {
|
||||
if (markers?.notifications) {
|
||||
queryClient.setQueryData(queryKeys.markers.notifications, markers.notifications);
|
||||
queryClient.setQueryData(
|
||||
queryKeys.markers.timeline('notifications'),
|
||||
markers.notifications,
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -359,6 +347,5 @@ export {
|
||||
useNotification,
|
||||
useNotificationsUnreadCount,
|
||||
usePrefetchNotifications,
|
||||
usePrefetchNotificationsMarker,
|
||||
useProcessStreamNotification,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user