fork
Configure Feed
Select the types of activity you want to include in your feed.
Live video on the AT Protocol
fork
Configure Feed
Select the types of activity you want to include in your feed.
1import { useMemo } from "react";
2import { StreamplaceAgent } from "streamplace";
3import { useStreamplaceStore, useUrl } from "./streamplace-store";
4
5export function usePDSAgent(): StreamplaceAgent | null {
6 const oauthSession = useStreamplaceStore((state) => state.oauthSession);
7 // oauthsession is
8 // - undefined when loading
9 // - null when logged out, and
10 // - SessionManager when logged in
11 return useMemo(() => {
12 if (!oauthSession) {
13 if (oauthSession === undefined) return null;
14 // TODO: change once we allow unauthed requests + profile indexing
15 // it's bluesky's AppView b/c otherwise we'd have goosewithpipe.jpg
16 // showing up everywhere
17 return new StreamplaceAgent("https://public.api.bsky.app"); // nodeUrl);
18 }
19
20 return new StreamplaceAgent(oauthSession);
21 }, [oauthSession]);
22}
23
24// can be unauthed, but will always use the current node URL
25export function usePossiblyUnauthedPDSAgent(): StreamplaceAgent | null {
26 const nodeUrl = useUrl();
27 const oauthSession = useStreamplaceStore((state) => state.oauthSession);
28 // oauthsession is
29 // - undefined when loading
30 // - null when logged out, and
31 // - SessionManager when logged in
32 return useMemo(() => {
33 if (!oauthSession) {
34 return new StreamplaceAgent(nodeUrl);
35 }
36
37 return new StreamplaceAgent(oauthSession);
38 }, [oauthSession]);
39}
40
41// always returns an unauthenticated agent pointed at the public bluesky API
42// probably should not be used in most places, but in case we have a bug it may be useful
43export function useUnauthenticatedBlueskyAppViewAgent(): StreamplaceAgent {
44 return useMemo(() => {
45 return new StreamplaceAgent("https://public.api.bsky.app");
46 }, []);
47}