diff --git a/app/javascript/mastodon/actions/streaming.js b/app/javascript/mastodon/actions/streaming.js index 207c9ff400..bf7a30cee5 100644 --- a/app/javascript/mastodon/actions/streaming.js +++ b/app/javascript/mastodon/actions/streaming.js @@ -40,7 +40,6 @@ const randomUpTo = max => * @param {function(Function, Function): Promise} [options.fallback] * @param {function(): void} [options.fillGaps] * @param {function(import("mastodon/api_types/statuses").ApiStatusJSON): boolean} [options.accept] - * @returns {function(): void} */ export const connectTimelineStream = (timelineId, channelName, params = {}, options = {}) => { const { messages } = getLocale(); @@ -147,16 +146,12 @@ async function refreshHomeTimelineAndNotification(dispatch) { await dispatch(fetchAnnouncements()); } -/** - * @returns {function(): void} - */ export const connectUserStream = () => connectTimelineStream('home', 'user', {}, { fallback: refreshHomeTimelineAndNotification, fillGaps: fillHomeTimelineGaps }); /** * @param {Object} options * @param {boolean} [options.onlyMedia] - * @returns {function(): void} */ export const connectCommunityStream = ({ onlyMedia } = {}) => connectTimelineStream(`community${onlyMedia ? ':media' : ''}`, `public:local${onlyMedia ? ':media' : ''}`, {}, { fillGaps: () => (fillCommunityTimelineGaps({ onlyMedia })) }); @@ -165,7 +160,6 @@ export const connectCommunityStream = ({ onlyMedia } = {}) => * @param {Object} options * @param {boolean} [options.onlyMedia] * @param {boolean} [options.onlyRemote] - * @returns {function(): void} */ export const connectPublicStream = ({ onlyMedia, onlyRemote } = {}) => connectTimelineStream(`public${onlyRemote ? ':remote' : ''}${onlyMedia ? ':media' : ''}`, `public${onlyRemote ? ':remote' : ''}${onlyMedia ? ':media' : ''}`, {}, { fillGaps: () => fillPublicTimelineGaps({ onlyMedia, onlyRemote }) }); @@ -175,20 +169,15 @@ export const connectPublicStream = ({ onlyMedia, onlyRemote } = {}) => * @param {string} tagName * @param {boolean} onlyLocal * @param {function(object): boolean} accept - * @returns {function(): void} */ export const connectHashtagStream = (columnId, tagName, onlyLocal, accept) => connectTimelineStream(`hashtag:${columnId}${onlyLocal ? ':local' : ''}`, `hashtag${onlyLocal ? ':local' : ''}`, { tag: tagName }, { accept }); -/** - * @returns {function(): void} - */ export const connectDirectStream = () => connectTimelineStream('direct', 'direct'); /** * @param {string} listId - * @returns {function(): void} */ export const connectListStream = listId => connectTimelineStream(`list:${listId}`, 'list', { list: listId }, { fillGaps: () => fillListTimelineGaps(listId) }); @@ -199,7 +188,6 @@ export const connectListStream = listId => * @param {boolean} [options.withReplies] * @param {string} [options.tagged] * @param {boolean} [options.onlyMedia] - * @returns {function(): void} */ export const connectProfileStream = (accountId, { withReplies, tagged, onlyMedia }) => connectTimelineStream(`account:${accountId}${onlyMedia ? ':media' : ''}${withReplies ? ':with_replies' : ''}${tagged ? `:${tagged}` : ''}`, 'profile', { account_id: accountId }, { diff --git a/app/javascript/mastodon/features/account_gallery/index.tsx b/app/javascript/mastodon/features/account_gallery/index.tsx index d288efcf0d..9b3fbcbd6f 100644 --- a/app/javascript/mastodon/features/account_gallery/index.tsx +++ b/app/javascript/mastodon/features/account_gallery/index.tsx @@ -4,6 +4,7 @@ import { FormattedMessage } from 'react-intl'; import { useParams } from 'react-router-dom'; +import type { ThunkAction, UnknownAction } from '@reduxjs/toolkit'; import { createSelector } from '@reduxjs/toolkit'; import type { Map as ImmutableMap } from 'immutable'; import { List as ImmutableList } from 'immutable'; @@ -160,8 +161,16 @@ export const AccountGallery: React.FC<{ if (signedIn) { disconnect = dispatch( - connectProfileStream(accountId, { onlyMedia: true }), - ) as unknown as () => void; + // The `as` is needed because `typescript-eslint` is confused by the types defined + // in JSDoc, it forces the type to be correct here, otherwise we get a + // `@typescript-eslint/no-confusing-void-expression` error + connectProfileStream(accountId, { onlyMedia: true }) as ThunkAction< + () => void, + RootState, + undefined, + UnknownAction + >, + ); } } diff --git a/app/javascript/mastodon/stream.js b/app/javascript/mastodon/stream.js index 59b2fd7582..7600ce24ea 100644 --- a/app/javascript/mastodon/stream.js +++ b/app/javascript/mastodon/stream.js @@ -142,11 +142,10 @@ const channelNameWithInlineParams = (channelName, params) => { * @param {string} channelName * @param {Object.} params * @param {function(Function, Function): { onConnect: (function(): void), onReceive: (function(StreamEvent): void), onDisconnect: (function(): void) }} callbacks - * @returns {function(): void} + * @returns {import('@reduxjs/toolkit').ThunkAction<() => void, import('./store').RootState, undefined, import('@reduxjs/toolkit').UnknownAction>} */ -// @ts-expect-error export const connectStream = (channelName, params, callbacks) => (dispatch, getState) => { - const streamingAPIBaseURL = getState().getIn(['meta', 'streaming_api_base_url']); + const streamingAPIBaseURL = getState().meta.get('streaming_api_base_url'); const accessToken = getAccessToken(); const { onConnect, onReceive, onDisconnect } = callbacks(dispatch, getState);