@@ -4,7 +4,7 @@ import {FallbackAvatar} from '@components/Icon/Expensicons';
44import useOnyx from '@hooks/useOnyx' ;
55import usePolicy from '@hooks/usePolicy' ;
66import useReportIsArchived from '@hooks/useReportIsArchived' ;
7- import { getOriginalMessage , getReportAction , getSortedReportActions , isMoneyRequestAction } from '@libs/ReportActionsUtils' ;
7+ import { getOriginalMessage , getReportAction , isMoneyRequestAction } from '@libs/ReportActionsUtils' ;
88import {
99 getDefaultWorkspaceAvatar ,
1010 getDisplayNameForParticipant ,
@@ -21,7 +21,6 @@ import CONST from '@src/CONST';
2121import ONYXKEYS from '@src/ONYXKEYS' ;
2222import type { OnyxInputOrEntry , Report , ReportAction } from '@src/types/onyx' ;
2323import type { Icon as IconType } from '@src/types/onyx/OnyxCommon' ;
24- import type { OriginalMessageChangePolicy } from '@src/types/onyx/OriginalMessage' ;
2524import useReportPreviewSenderID from './useReportPreviewSenderID' ;
2625
2726function useReportActionAvatars ( {
@@ -63,11 +62,7 @@ function useReportActionAvatars({
6362 action = getReportAction ( reportChatReport ?. reportID , chatReport . parentReportActionID ) ;
6463 }
6564
66- const [ latestChangePolicy ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ action ?. childReportID } ` , {
67- canBeMissing : true ,
68- selector : ( reportActions ) =>
69- getSortedReportActions ( Object . values ( reportActions ?? { } ) . filter ( ( reportAction ) => reportAction . actionName === CONST . REPORT . ACTIONS . TYPE . CHANGE_POLICY ) ) . at ( - 1 ) ,
70- } ) ;
65+ const [ actionChildReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ action ?. childReportID } ` , { canBeMissing : true } ) ;
7166
7267 const isAReportPreviewAction = action ?. actionName === CONST . REPORT . ACTIONS . TYPE . REPORT_PREVIEW ;
7368
@@ -81,9 +76,8 @@ function useReportActionAvatars({
8176
8277 const reportPolicyID = iouReport ?. policyID ?? chatReport ?. policyID ;
8378 const chatReportPolicyIDExists = chatReport ?. policyID === CONST . POLICY . ID_FAKE || ! chatReport ?. policyID ;
84- const latestChangePolicyOM = getOriginalMessage ( latestChangePolicy as ReportAction < typeof CONST . REPORT . ACTIONS . TYPE . CHANGE_POLICY > ) ?? { } ;
85- const { fromPolicy : policyIDBeforeChange , toPolicy : changedPolicyID } = latestChangePolicyOM as OriginalMessageChangePolicy ;
86- const shouldUseChangedPolicyID = ! ! changedPolicyID ;
79+ const changedPolicyID = actionChildReport ?. policyID ?? iouReport ?. policyID ;
80+ const shouldUseChangedPolicyID = ! ! changedPolicyID && changedPolicyID !== chatReport ?. policyID ;
8781 const retrievedPolicyID = chatReportPolicyIDExists ? reportPolicyID : chatReport ?. policyID ;
8882
8983 const policyID = shouldUseChangedPolicyID ? changedPolicyID : ( passedPolicyID ?? retrievedPolicyID ) ;
@@ -289,7 +283,7 @@ function useReportActionAvatars({
289283 const isWorkspaceWithUserAvatar =
290284 avatars . at ( 0 ) ?. type === CONST . ICON_TYPE_WORKSPACE && avatars . at ( 1 ) ?. type === CONST . ICON_TYPE_AVATAR && avatarType === CONST . REPORT_ACTION_AVATARS . TYPE . MULTIPLE ;
291285 // eslint-disable-next-line rulesdir/no-negated-variables
292- const wasReportPreviewMovedToDifferentPolicy = chatReport ?. policyID === policyIDBeforeChange && policyIDBeforeChange !== changedPolicyID && isAReportPreviewAction ;
286+ const wasReportPreviewMovedToDifferentPolicy = shouldUseChangedPolicyID && isAReportPreviewAction ;
293287
294288 if ( shouldUseInvoiceExpenseIcons ) {
295289 avatars = getIconsWithDefaults ( invoiceReport ) ;
0 commit comments