@@ -85,6 +85,7 @@ const QUERY_KEYS = {
8585 } ,
8686 feed : [ 'feed' ] ,
8787 inbox : [ 'inbox' ] ,
88+ globalFeed : [ 'global_feed' ] ,
8889 postsByAccount : [ 'account_posts' ] ,
8990 postsLikedByAccount : [ 'account_liked_posts' ] ,
9091 notifications : ( handle : string ) => [ 'notifications' , handle ] ,
@@ -97,6 +98,7 @@ function updateLikeCache(queryClient: QueryClient, id: string, liked: boolean) {
9798 const queryKeys = [
9899 QUERY_KEYS . feed ,
99100 QUERY_KEYS . inbox ,
101+ QUERY_KEYS . globalFeed ,
100102 QUERY_KEYS . postsLikedByAccount ,
101103 QUERY_KEYS . profilePosts ( null )
102104 ] ;
@@ -166,6 +168,7 @@ function updateFollowCache(queryClient: QueryClient, handle: string, authorHandl
166168 const queryKeys = [
167169 QUERY_KEYS . feed ,
168170 QUERY_KEYS . inbox ,
171+ QUERY_KEYS . globalFeed ,
169172 QUERY_KEYS . profilePosts ( 'index' )
170173 ] ;
171174
@@ -493,6 +496,7 @@ function updateReplyCache(queryClient: QueryClient, id: string, delta: number) {
493496 const queryKeys = [
494497 QUERY_KEYS . feed ,
495498 QUERY_KEYS . inbox ,
499+ QUERY_KEYS . globalFeed ,
496500 QUERY_KEYS . profilePosts ( 'index' ) ,
497501 QUERY_KEYS . postsLikedByAccount
498502 ] ;
@@ -744,6 +748,7 @@ export function useBlockMutationForUser(handle: string) {
744748 ) ;
745749 queryClient . invalidateQueries ( { queryKey : QUERY_KEYS . feed } ) ;
746750 queryClient . invalidateQueries ( { queryKey : QUERY_KEYS . inbox } ) ;
751+ queryClient . invalidateQueries ( { queryKey : QUERY_KEYS . globalFeed } ) ;
747752 } ,
748753 onError ( error : { message : string , statusCode : number } ) {
749754 if ( error . statusCode === 429 ) {
@@ -789,6 +794,7 @@ function updateRepostCache(queryClient: QueryClient, id: string, reposted: boole
789794 const queryKeys = [
790795 QUERY_KEYS . feed ,
791796 QUERY_KEYS . inbox ,
797+ QUERY_KEYS . globalFeed ,
792798 QUERY_KEYS . profilePosts ( null )
793799 ] ;
794800
@@ -1718,6 +1724,42 @@ export function useInboxForUser(options: {enabled: boolean}) {
17181724 return { inboxQuery, updateInboxActivity} ;
17191725}
17201726
1727+ export function useGlobalFeedForUser ( options : { enabled : boolean } ) {
1728+ const queryKey = QUERY_KEYS . globalFeed ;
1729+ const queryClient = useQueryClient ( ) ;
1730+
1731+ const globalFeedQuery = useInfiniteQuery ( {
1732+ queryKey,
1733+ enabled : options . enabled ,
1734+ staleTime : 20 * 1000 , // 20s
1735+ async queryFn ( { pageParam} : { pageParam ?: string } ) {
1736+ const siteUrl = await getSiteUrl ( ) ;
1737+ const api = createActivityPubAPI ( 'index' , siteUrl ) ;
1738+ return api . getGlobalFeed ( pageParam ) . then ( ( response ) => {
1739+ return {
1740+ posts : response . posts . map ( mapPostToActivity ) ,
1741+ next : response . next
1742+ } ;
1743+ } ) ;
1744+ } ,
1745+ getNextPageParam ( prevPage ) {
1746+ return prevPage . next ;
1747+ }
1748+ } ) ;
1749+
1750+ const updateGlobalFeedActivity = ( id : string , updated : Partial < Activity > ) => {
1751+ updateActivityInPaginatedCollection (
1752+ queryClient ,
1753+ queryKey ,
1754+ 'posts' ,
1755+ id ,
1756+ activity => ( { ...activity , ...updated } )
1757+ ) ;
1758+ } ;
1759+
1760+ return { globalFeedQuery, updateGlobalFeedActivity} ;
1761+ }
1762+
17211763export function usePostsByAccount ( profileHandle : string , options : { enabled : boolean } ) {
17221764 const queryKey = QUERY_KEYS . profilePosts ( profileHandle === 'me' ? 'index' : profileHandle ) ;
17231765 const queryClient = useQueryClient ( ) ;
0 commit comments