Streaming: allow connecting if not logged in, gate certain topics
This commit is contained in:
parent
53c8858fa6
commit
85c8f674b4
5 changed files with 41 additions and 6 deletions
|
@ -1,7 +1,17 @@
|
|||
import { useLoggedIn } from 'soapbox/hooks';
|
||||
|
||||
import { useTimelineStream } from './useTimelineStream';
|
||||
|
||||
function useDirectStream() {
|
||||
return useTimelineStream('direct', 'direct');
|
||||
const { isLoggedIn } = useLoggedIn();
|
||||
|
||||
return useTimelineStream(
|
||||
'direct',
|
||||
'direct',
|
||||
null,
|
||||
null,
|
||||
{ enabled: isLoggedIn },
|
||||
);
|
||||
}
|
||||
|
||||
export { useDirectStream };
|
|
@ -1,9 +1,16 @@
|
|||
import { useLoggedIn } from 'soapbox/hooks';
|
||||
|
||||
import { useTimelineStream } from './useTimelineStream';
|
||||
|
||||
function useListStream(listId: string) {
|
||||
const { isLoggedIn } = useLoggedIn();
|
||||
|
||||
return useTimelineStream(
|
||||
`list:${listId}`,
|
||||
`list&list=${listId}`,
|
||||
null,
|
||||
null,
|
||||
{ enabled: isLoggedIn },
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,20 @@
|
|||
import { useFeatures } from 'soapbox/hooks';
|
||||
import { useFeatures, useLoggedIn } from 'soapbox/hooks';
|
||||
|
||||
import { useTimelineStream } from './useTimelineStream';
|
||||
|
||||
function useNostrStream() {
|
||||
const features = useFeatures();
|
||||
const enabled = features.nostrSign && Boolean(window.nostr);
|
||||
return useTimelineStream('nostr', 'nostr', null, null, { enabled });
|
||||
const { isLoggedIn } = useLoggedIn();
|
||||
|
||||
return useTimelineStream(
|
||||
'nostr',
|
||||
'nostr',
|
||||
null,
|
||||
null,
|
||||
{
|
||||
enabled: isLoggedIn && features.nostrSign && Boolean(window.nostr),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export { useNostrStream };
|
|
@ -17,7 +17,7 @@ function useTimelineStream(...args: Parameters<typeof connectTimelineStream>) {
|
|||
const streamingUrl = instance.urls.get('streaming_api');
|
||||
|
||||
const connect = () => {
|
||||
if (enabled && accessToken && streamingUrl && !stream.current) {
|
||||
if (enabled && streamingUrl && !stream.current) {
|
||||
stream.current = dispatch(connectTimelineStream(...args));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -2,14 +2,23 @@ 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';
|
||||
|
||||
import { useTimelineStream } from './useTimelineStream';
|
||||
|
||||
import type { AppDispatch } from 'soapbox/store';
|
||||
|
||||
function useUserStream() {
|
||||
const { isLoggedIn } = useLoggedIn();
|
||||
const statContext = useStatContext();
|
||||
return useTimelineStream('home', 'user', refresh, null, { statContext });
|
||||
|
||||
return useTimelineStream(
|
||||
'home',
|
||||
'user',
|
||||
refresh,
|
||||
null,
|
||||
{ statContext, enabled: isLoggedIn },
|
||||
);
|
||||
}
|
||||
|
||||
/** Refresh home timeline and notifications. */
|
||||
|
|
Loading…
Reference in a new issue