@@ -62,6 +62,10 @@ function useReportActionAvatars({
6262 action = getReportAction ( reportChatReport ?. reportID , chatReport . parentReportActionID ) ;
6363 }
6464
65+ const [ actionChildReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ action ?. childReportID } ` , { canBeMissing : true } ) ;
66+
67+ const isAReportPreviewAction = action ?. actionName === CONST . REPORT . ACTIONS . TYPE . REPORT_PREVIEW ;
68+
6569 const isReportArchived = useReportIsArchived ( iouReport ?. reportID ) ;
6670
6771 const reportPreviewSenderID = useReportPreviewSenderID ( {
@@ -70,19 +74,26 @@ function useReportActionAvatars({
7074 chatReport,
7175 } ) ;
7276
73- const policyID = passedPolicyID ?? ( chatReport ?. policyID === CONST . POLICY . ID_FAKE || ! chatReport ?. policyID ? ( iouReport ?. policyID ?? chatReport ?. policyID ) : chatReport ?. policyID ) ;
77+ const reportPolicyID = iouReport ?. policyID ?? chatReport ?. policyID ;
78+ const chatReportPolicyIDExists = chatReport ?. policyID === CONST . POLICY . ID_FAKE || ! chatReport ?. policyID ;
79+ const changedPolicyID = actionChildReport ?. policyID ?? iouReport ?. policyID ;
80+ const shouldUseChangedPolicyID = ! ! changedPolicyID && changedPolicyID !== chatReport ?. policyID ;
81+ const retrievedPolicyID = chatReportPolicyIDExists ? reportPolicyID : chatReport ?. policyID ;
82+
83+ const policyID = shouldUseChangedPolicyID ? changedPolicyID : ( passedPolicyID ?? retrievedPolicyID ) ;
7484 const policy = usePolicy ( policyID ) ;
7585
7686 const invoiceReceiverPolicyID = chatReport ?. invoiceReceiver && 'policyID' in chatReport . invoiceReceiver ? chatReport . invoiceReceiver . policyID : undefined ;
7787 const invoiceReceiverPolicy = usePolicy ( invoiceReceiverPolicyID ) ;
7888
7989 const { chatReportIDAdmins, chatReportIDAnnounce, workspaceAccountID} = policy ?? { } ;
80- const [ policyChatReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ chatReportIDAnnounce ?? chatReportIDAdmins } ` , { canBeMissing : true } ) ;
90+
91+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
92+ const [ policyChatReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ chatReportIDAnnounce || chatReportIDAdmins } ` , { canBeMissing : true } ) ;
8193
8294 const delegatePersonalDetails = action ?. delegateAccountID ? personalDetails ?. [ action ?. delegateAccountID ] : undefined ;
8395 const actorAccountID = getReportActionActorAccountID ( action , iouReport , chatReport , delegatePersonalDetails ) ;
8496
85- const isAReportPreviewAction = action ?. actionName === CONST . REPORT . ACTIONS . TYPE . REPORT_PREVIEW ;
8697 const isAInvoiceReport = isInvoiceReport ( iouReport ?? null ) ;
8798
8899 const shouldUseActorAccountID = isAInvoiceReport && ! isAReportPreviewAction ;
@@ -267,6 +278,13 @@ function useReportActionAvatars({
267278
268279 let avatars = [ primaryAvatar , secondaryAvatar ] ;
269280
281+ const isUserWithWorkspaceAvatar =
282+ avatarType === CONST . REPORT_ACTION_AVATARS . TYPE . SUBSCRIPT && avatars . at ( 0 ) ?. type === CONST . ICON_TYPE_AVATAR && avatars . at ( 1 ) ?. type === CONST . ICON_TYPE_WORKSPACE ;
283+ const isWorkspaceWithUserAvatar =
284+ avatars . at ( 0 ) ?. type === CONST . ICON_TYPE_WORKSPACE && avatars . at ( 1 ) ?. type === CONST . ICON_TYPE_AVATAR && avatarType === CONST . REPORT_ACTION_AVATARS . TYPE . MULTIPLE ;
285+ // eslint-disable-next-line rulesdir/no-negated-variables
286+ const wasReportPreviewMovedToDifferentPolicy = shouldUseChangedPolicyID && isAReportPreviewAction ;
287+
270288 if ( shouldUseInvoiceExpenseIcons ) {
271289 avatars = getIconsWithDefaults ( invoiceReport ) ;
272290 } else if ( shouldUseMappedAccountIDs ) {
@@ -278,14 +296,13 @@ function useReportActionAvatars({
278296 if ( avatars . every ( ( { type} ) => type === CONST . ICON_TYPE_WORKSPACE ) ) {
279297 avatarType = isAReportPreviewAction ? CONST . REPORT_ACTION_AVATARS . TYPE . MULTIPLE : CONST . REPORT_ACTION_AVATARS . TYPE . SUBSCRIPT ;
280298 // But if it is a report preview between workspace and another user it should never be displayed as a multiple avatar
281- } else if (
282- avatars . at ( 0 ) ?. type === CONST . ICON_TYPE_WORKSPACE &&
283- avatars . at ( 1 ) ?. type === CONST . ICON_TYPE_AVATAR &&
284- avatarType === CONST . REPORT_ACTION_AVATARS . TYPE . MULTIPLE &&
285- isAReportPreviewAction
286- ) {
299+ } else if ( isWorkspaceWithUserAvatar && isAReportPreviewAction ) {
287300 avatarType = CONST . REPORT_ACTION_AVATARS . TYPE . SUBSCRIPT ;
288301 }
302+ } else if ( isUserWithWorkspaceAvatar && wasReportPreviewMovedToDifferentPolicy ) {
303+ const policyChatReportIcon = { ...getWorkspaceIcon ( policyChatReport , policy ) , id : policyID , name : policy ?. name } ;
304+ const [ firstAvatar ] = avatars ;
305+ avatars = [ firstAvatar , policyChatReportIcon ] ;
289306 }
290307
291308 return {
0 commit comments