diff --git a/app/soapbox/actions/streaming.ts b/app/soapbox/actions/streaming.ts index 8173752cf..1d71d8d98 100644 --- a/app/soapbox/actions/streaming.ts +++ b/app/soapbox/actions/streaming.ts @@ -193,9 +193,6 @@ const connectTimelineStream = ( const connectHashtagStream = (id: string, tag: string, accept: (status: APIEntity) => boolean) => connectTimelineStream(`hashtag:${id}`, `hashtag&tag=${tag}`, null, accept); -const connectDirectStream = () => - connectTimelineStream('direct', 'direct'); - const connectListStream = (id: string) => connectTimelineStream(`list:${id}`, `list&list=${id}`); @@ -207,7 +204,6 @@ export { STREAMING_FOLLOW_RELATIONSHIPS_UPDATE, connectTimelineStream, connectHashtagStream, - connectDirectStream, connectListStream, connectGroupStream, type TimelineStreamOpts, diff --git a/app/soapbox/api/hooks/index.ts b/app/soapbox/api/hooks/index.ts index 9569318a7..214607f6d 100644 --- a/app/soapbox/api/hooks/index.ts +++ b/app/soapbox/api/hooks/index.ts @@ -48,5 +48,6 @@ export { useUpdateGroupTag } from './groups/useUpdateGroupTag'; export { useUserStream } from './streaming/useUserStream'; export { useCommunityStream } from './streaming/useCommunityStream'; export { usePublicStream } from './streaming/usePublicStream'; +export { useDirectStream } from './streaming/useDirectStream'; export { useRemoteStream } from './streaming/useRemoteStream'; export { useNostrStream } from './streaming/useNostrStream'; \ No newline at end of file diff --git a/app/soapbox/api/hooks/streaming/useDirectStream.ts b/app/soapbox/api/hooks/streaming/useDirectStream.ts new file mode 100644 index 000000000..e97fc8860 --- /dev/null +++ b/app/soapbox/api/hooks/streaming/useDirectStream.ts @@ -0,0 +1,7 @@ +import { useTimelineStream } from './useTimelineStream'; + +function useDirectStream() { + return useTimelineStream('direct', 'direct'); +} + +export { useDirectStream }; \ No newline at end of file diff --git a/app/soapbox/features/conversations/index.tsx b/app/soapbox/features/conversations/index.tsx index 12b418eb0..1f6774ab9 100644 --- a/app/soapbox/features/conversations/index.tsx +++ b/app/soapbox/features/conversations/index.tsx @@ -3,7 +3,7 @@ import { defineMessages, useIntl } from 'react-intl'; import { directComposeById } from 'soapbox/actions/compose'; import { mountConversations, unmountConversations, expandConversations } from 'soapbox/actions/conversations'; -import { connectDirectStream } from 'soapbox/actions/streaming'; +import { useDirectStream } from 'soapbox/api/hooks'; import AccountSearch from 'soapbox/components/account-search'; import { Column } from 'soapbox/components/ui'; import { useAppDispatch } from 'soapbox/hooks'; @@ -19,15 +19,14 @@ const ConversationsTimeline = () => { const intl = useIntl(); const dispatch = useAppDispatch(); + useDirectStream(); + useEffect(() => { dispatch(mountConversations()); dispatch(expandConversations()); - const disconnect = dispatch(connectDirectStream()); - return () => { dispatch(unmountConversations()); - disconnect(); }; }, []); diff --git a/app/soapbox/features/direct-timeline/index.tsx b/app/soapbox/features/direct-timeline/index.tsx index eee31a829..ba8ba1cb0 100644 --- a/app/soapbox/features/direct-timeline/index.tsx +++ b/app/soapbox/features/direct-timeline/index.tsx @@ -2,8 +2,8 @@ import React, { useEffect } from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import { directComposeById } from 'soapbox/actions/compose'; -import { connectDirectStream } from 'soapbox/actions/streaming'; import { expandDirectTimeline } from 'soapbox/actions/timelines'; +import { useDirectStream } from 'soapbox/api/hooks'; import AccountSearch from 'soapbox/components/account-search'; import { Column } from 'soapbox/components/ui'; import { useAppSelector, useAppDispatch } from 'soapbox/hooks'; @@ -20,13 +20,10 @@ const DirectTimeline = () => { const dispatch = useAppDispatch(); const next = useAppSelector(state => state.timelines.get('direct')?.next); + useDirectStream(); + useEffect(() => { dispatch(expandDirectTimeline()); - const disconnect = dispatch(connectDirectStream()); - - return (() => { - disconnect(); - }); }, []); const handleSuggestion = (accountId: string) => {