pleroma/app/soapbox/api/hooks/streaming/useUserStream.ts

31 lines
926 B
TypeScript
Raw Normal View History

2023-07-22 10:49:02 -07:00
import { fetchAnnouncements } from 'soapbox/actions/announcements';
import { expandNotifications } from 'soapbox/actions/notifications';
import { expandHomeTimeline } from 'soapbox/actions/timelines';
import { useStatContext } from 'soapbox/contexts/stat-context';
import { useLoggedIn } from 'soapbox/hooks';
2023-07-22 10:49:02 -07:00
import { useTimelineStream } from './useTimelineStream';
import type { AppDispatch } from 'soapbox/store';
function useUserStream() {
const { isLoggedIn } = useLoggedIn();
2023-07-22 10:49:02 -07:00
const statContext = useStatContext();
return useTimelineStream(
'home',
'user',
refresh,
null,
{ statContext, enabled: isLoggedIn },
);
2023-07-22 10:49:02 -07:00
}
/** Refresh home timeline and notifications. */
function refresh(dispatch: AppDispatch, done?: () => void) {
return dispatch(expandHomeTimeline({}, () =>
dispatch(expandNotifications({}, () =>
dispatch(fetchAnnouncements(done))))));
}
export { useUserStream };