diff --git a/src/actions/streaming.ts b/src/actions/streaming.ts index 23b426cd8..d6f6ea55e 100644 --- a/src/actions/streaming.ts +++ b/src/actions/streaming.ts @@ -99,10 +99,9 @@ interface TimelineStreamOpts { const connectTimelineStream = ( timelineId: string, path: string, - pollingRefresh: ((dispatch: AppDispatch, done?: () => void) => void) | null = null, accept: ((status: APIEntity) => boolean) | null = null, opts?: TimelineStreamOpts, -) => connectStream(path, pollingRefresh, (dispatch: AppDispatch, getState: () => RootState) => { +) => connectStream(path, (dispatch: AppDispatch, getState: () => RootState) => { const locale = getLocale(getState()); return { diff --git a/src/api/hooks/streaming/useCommunityStream.ts b/src/api/hooks/streaming/useCommunityStream.ts index 0ee8b3335..77b0a0ce5 100644 --- a/src/api/hooks/streaming/useCommunityStream.ts +++ b/src/api/hooks/streaming/useCommunityStream.ts @@ -10,7 +10,6 @@ function useCommunityStream({ onlyMedia, enabled }: UseCommunityStreamOpts = {}) `community${onlyMedia ? ':media' : ''}`, `public:local${onlyMedia ? ':media' : ''}`, undefined, - undefined, { enabled }, ); } diff --git a/src/api/hooks/streaming/useDirectStream.ts b/src/api/hooks/streaming/useDirectStream.ts index cf343a09b..dea64d4e3 100644 --- a/src/api/hooks/streaming/useDirectStream.ts +++ b/src/api/hooks/streaming/useDirectStream.ts @@ -9,7 +9,6 @@ function useDirectStream() { 'direct', 'direct', null, - null, { enabled: isLoggedIn }, ); } diff --git a/src/api/hooks/streaming/useListStream.ts b/src/api/hooks/streaming/useListStream.ts index e6808ffd8..8cb02bc81 100644 --- a/src/api/hooks/streaming/useListStream.ts +++ b/src/api/hooks/streaming/useListStream.ts @@ -9,7 +9,6 @@ function useListStream(listId: string) { `list:${listId}`, `list&list=${listId}`, null, - null, { enabled: isLoggedIn }, ); } diff --git a/src/api/hooks/streaming/usePublicStream.ts b/src/api/hooks/streaming/usePublicStream.ts index cfc9e63af..356ed07e8 100644 --- a/src/api/hooks/streaming/usePublicStream.ts +++ b/src/api/hooks/streaming/usePublicStream.ts @@ -10,7 +10,6 @@ function usePublicStream({ onlyMedia, language }: UsePublicStreamOpts = {}) { `public${onlyMedia ? ':media' : ''}`, `public${onlyMedia ? ':media' : ''}`, null, - null, { enabled: !language }, // TODO: support language streaming ); } diff --git a/src/api/hooks/streaming/useTimelineStream.ts b/src/api/hooks/streaming/useTimelineStream.ts index 28aedbecf..c47e2c5bd 100644 --- a/src/api/hooks/streaming/useTimelineStream.ts +++ b/src/api/hooks/streaming/useTimelineStream.ts @@ -9,7 +9,7 @@ import { getAccessToken } from 'soapbox/utils/auth.ts'; function useTimelineStream(...args: Parameters) { // TODO: get rid of streaming.ts and move the actual opts here. const [timelineId, path] = args; - const { enabled = true } = args[4] ?? {}; + const { enabled = true } = args[3] ?? {}; const dispatch = useAppDispatch(); const { instance } = useInstance(); diff --git a/src/api/hooks/streaming/useUserStream.ts b/src/api/hooks/streaming/useUserStream.ts index 1030403d2..2736761e7 100644 --- a/src/api/hooks/streaming/useUserStream.ts +++ b/src/api/hooks/streaming/useUserStream.ts @@ -1,12 +1,8 @@ -import { expandNotifications } from 'soapbox/actions/notifications.ts'; -import { expandHomeTimeline } from 'soapbox/actions/timelines.ts'; import { useStatContext } from 'soapbox/contexts/stat-context.tsx'; import { useLoggedIn } from 'soapbox/hooks/useLoggedIn.ts'; import { useTimelineStream } from './useTimelineStream.ts'; -import type { AppDispatch } from 'soapbox/store.ts'; - function useUserStream() { const { isLoggedIn } = useLoggedIn(); const statContext = useStatContext(); @@ -14,16 +10,9 @@ function useUserStream() { return useTimelineStream( 'home', 'user', - refresh, null, { statContext, enabled: isLoggedIn }, ); } -/** Refresh home timeline and notifications. */ -function refresh(dispatch: AppDispatch, done?: () => void) { - return dispatch(expandHomeTimeline({}, () => - dispatch(expandNotifications({}, done)))); -} - export { useUserStream }; \ No newline at end of file diff --git a/src/stream.ts b/src/stream.ts index 165de6b55..7329b962f 100644 --- a/src/stream.ts +++ b/src/stream.ts @@ -4,19 +4,14 @@ import { getAccessToken } from 'soapbox/utils/auth.ts'; import type { AppDispatch, RootState } from 'soapbox/store.ts'; -const randomIntUpTo = (max: number) => Math.floor(Math.random() * Math.floor(max)); - interface ConnectStreamCallbacks { onConnect(): void; onDisconnect(): void; onReceive(websocket: Websocket, data: unknown): void; } -type PollingRefreshFn = (dispatch: AppDispatch, done?: () => void) => void - export function connectStream( path: string, - pollingRefresh: PollingRefreshFn | null = null, callbacks: (dispatch: AppDispatch, getState: () => RootState) => ConnectStreamCallbacks, ) { return (dispatch: AppDispatch, getState: () => RootState) => { @@ -24,23 +19,6 @@ export function connectStream( const accessToken = getAccessToken(getState()); const { onConnect, onDisconnect, onReceive } = callbacks(dispatch, getState); - let polling: NodeJS.Timeout | null = null; - - const setupPolling = () => { - if (pollingRefresh) { - pollingRefresh(dispatch, () => { - polling = setTimeout(() => setupPolling(), 20000 + randomIntUpTo(20000)); - }); - } - }; - - const clearPolling = () => { - if (polling) { - clearTimeout(polling); - polling = null; - } - }; - let subscription: Websocket; // If the WebSocket fails to be created, don't crash the whole page, @@ -48,18 +26,10 @@ export function connectStream( try { subscription = getStream(streamingAPIBaseURL!, accessToken!, path, { connected() { - if (pollingRefresh) { - clearPolling(); - } - onConnect(); }, disconnected() { - if (pollingRefresh) { - polling = setTimeout(() => setupPolling(), randomIntUpTo(40000)); - } - onDisconnect(); }, @@ -68,11 +38,6 @@ export function connectStream( }, reconnected() { - if (pollingRefresh) { - clearPolling(); - pollingRefresh(dispatch); - } - onConnect(); }, @@ -85,8 +50,6 @@ export function connectStream( if (subscription) { subscription.close(); } - - clearPolling(); }; return disconnect;