@@ -8,9 +8,12 @@ import {
88} from "@posthog/core/inbox/reportFiltering" ;
99import {
1010 computeInboxTabCounts ,
11+ INBOX_SCOPE_FOR_YOU ,
1112 matchesReviewerScope ,
1213 parseTeammateInboxScope ,
1314} from "@posthog/core/inbox/reportMembership" ;
15+ import { useOptionalAuthenticatedClient } from "@posthog/ui/features/auth/authClient" ;
16+ import { useCurrentUser } from "@posthog/ui/features/auth/useCurrentUser" ;
1417import { useInboxReportsInfinite } from "@posthog/ui/features/inbox/hooks/useInboxReports" ;
1518import { useInboxReviewerScopeStore } from "@posthog/ui/features/inbox/stores/inboxReviewerScopeStore" ;
1619import { useInboxSignalsFilterStore } from "@posthog/ui/features/inbox/stores/inboxSignalsFilterStore" ;
@@ -52,7 +55,16 @@ export function useInboxAllReports(options?: {
5255 const priorityFilter = useInboxSignalsFilterStore ( ( s ) =>
5356 ignoreFilters ? EMPTY_FILTER_ARRAY : s . priorityFilter ,
5457 ) ;
58+ const client = useOptionalAuthenticatedClient ( ) ;
59+ const { data : currentUser } = useCurrentUser ( { client } ) ;
60+
61+ // Reviewer scope is applied server-side via `suggested_reviewers`: "For you"
62+ // filters on the current user, a teammate scope on theirs, "Entire project"
63+ // and the Runs tab (`ignoreScope`) send nothing.
64+ const isForYou = ! ignoreScope && scope === INBOX_SCOPE_FOR_YOU ;
5565 const teammateUuid = ignoreScope ? null : parseTeammateInboxScope ( scope ) ;
66+ const reviewerUuid =
67+ teammateUuid ?? ( isForYou ? ( currentUser ?. uuid ?? null ) : null ) ;
5668
5769 const query = useInboxReportsInfinite (
5870 {
@@ -63,11 +75,16 @@ export function useInboxAllReports(options?: {
6375 ? sourceProductFilter . join ( "," )
6476 : undefined ,
6577 priority : buildPriorityFilterParam ( priorityFilter ) ,
66- suggested_reviewers : teammateUuid
67- ? buildSuggestedReviewerFilterParam ( [ teammateUuid ] )
78+ suggested_reviewers : reviewerUuid
79+ ? buildSuggestedReviewerFilterParam ( [ reviewerUuid ] )
6880 : undefined ,
6981 } ,
7082 {
83+ // "For you" must always carry the current user's `suggested_reviewers`
84+ // filter, so hold the query until that uuid resolves rather than firing a
85+ // throwaway project-wide fetch first. Other scopes don't depend on the
86+ // user and run immediately.
87+ enabled : ! isForYou || reviewerUuid != null ,
7188 refetchInterval : INBOX_REFETCH_INTERVAL_MS ,
7289 refetchIntervalInBackground : false ,
7390 } ,
0 commit comments