@@ -1619,13 +1619,7 @@ function getReportRecipientAccountIDs(report: OnyxEntry<Report>, currentLoginAcc
1619
1619
}
1620
1620
1621
1621
let finalParticipantAccountIDs : number [ ] = [ ] ;
1622
- if ( isMoneyRequestReport ( report ) ) {
1623
- // For money requests i.e the IOU (1:1 person) and Expense (1:* person) reports, use the full `participants`
1624
- // and add the `ownerAccountId`. Money request reports don't add `ownerAccountId` in `participants` array
1625
- const defaultParticipantAccountIDs = Object . keys ( finalReport ?. participants ?? { } ) . map ( Number ) ;
1626
- const setOfParticipantAccountIDs = new Set < number > ( report ?. ownerAccountID ? [ ...defaultParticipantAccountIDs , report . ownerAccountID ] : defaultParticipantAccountIDs ) ;
1627
- finalParticipantAccountIDs = [ ...setOfParticipantAccountIDs ] ;
1628
- } else if ( isTaskReport ( report ) ) {
1622
+ if ( isTaskReport ( report ) ) {
1629
1623
// Task reports `managerID` will change when assignee is changed, in that case the old `managerID` is still present in `participants`
1630
1624
// along with the new one. We only need the `managerID` as a participant here.
1631
1625
finalParticipantAccountIDs = report ?. managerID ? [ report ?. managerID ] : [ ] ;
@@ -1839,19 +1833,32 @@ function getDisplayNameForParticipant(accountID?: number, shouldUseShortForm = f
1839
1833
return shouldUseShortForm ? shortName : longName ;
1840
1834
}
1841
1835
1842
- function getParticipantAccountIDs ( reportID : string , includeOnlyActiveMembers = false ) {
1843
- const report = getReport ( reportID ) ;
1844
- if ( ! report || ! report . participants ) {
1845
- return [ ] ;
1846
- }
1847
- const accountIDStrings = Object . keys ( report . participants ) . filter ( ( accountID ) => {
1848
- if ( ! includeOnlyActiveMembers ) {
1836
+ function getParticipantsAccountIDsForDisplay ( report : OnyxEntry < Report > , shouldExcludeHidden = false , shouldExcludeDeleted = false ) : number [ ] {
1837
+ let participantsEntries = Object . entries ( report ?. participants ?? { } ) ;
1838
+
1839
+ // For 1:1 chat, we don't want to include the current user as a participant in order to not mark 1:1 chats as having multiple participants
1840
+ // For system chat, we want to display Expensify as the only participant
1841
+ const shouldExcludeCurrentUser = isOneOnOneChat ( report ) || isSystemChat ( report ) ;
1842
+
1843
+ if ( shouldExcludeCurrentUser || shouldExcludeHidden || shouldExcludeDeleted ) {
1844
+ participantsEntries = participantsEntries . filter ( ( [ accountID , participant ] ) => {
1845
+ if ( shouldExcludeCurrentUser && Number ( accountID ) === currentUserAccountID ) {
1846
+ return false ;
1847
+ }
1848
+
1849
+ if ( shouldExcludeHidden && participant . hidden ) {
1850
+ return false ;
1851
+ }
1852
+
1853
+ if ( shouldExcludeDeleted && report ?. pendingChatMembers ?. findLast ( ( member ) => member . accountID === accountID ) ?. pendingAction === CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE ) {
1854
+ return false ;
1855
+ }
1856
+
1849
1857
return true ;
1850
- }
1851
- const pendingMember = report ?. pendingChatMembers ?. findLast ( ( member ) => member . accountID === accountID . toString ( ) ) ;
1852
- return ! pendingMember || pendingMember . pendingAction !== CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE ;
1853
- } ) ;
1854
- return accountIDStrings . map ( ( accountID ) => Number ( accountID ) ) ;
1858
+ } ) ;
1859
+ }
1860
+
1861
+ return participantsEntries . map ( ( [ accountID ] ) => Number ( accountID ) ) ;
1855
1862
}
1856
1863
1857
1864
function buildParticipantsFromAccountIDs ( accountIDs : number [ ] ) : Participants {
@@ -1866,18 +1873,14 @@ function buildParticipantsFromAccountIDs(accountIDs: number[]): Participants {
1866
1873
/**
1867
1874
* Returns the report name if the report is a group chat
1868
1875
*/
1869
- function getGroupChatName ( participantAccountIDs ?: number [ ] , shouldApplyLimit = false , reportID = '' ) : string | undefined {
1870
- // If we have a reportID always try to get the name from the report.
1871
- if ( reportID ) {
1872
- const reportKey = `${ ONYXKEYS . COLLECTION . REPORT } ${ reportID } ` ;
1873
- const reportName = allReports ?. [ reportKey ] ?. reportName ;
1874
- if ( reportName ) {
1875
- return reportName ;
1876
- }
1876
+ function getGroupChatName ( participantAccountIDs ?: number [ ] , shouldApplyLimit = false , report ?: OnyxEntry < Report > ) : string | undefined {
1877
+ // If we have a report always try to get the name from the report.
1878
+ if ( report ?. reportName ) {
1879
+ return report . reportName ;
1877
1880
}
1878
1881
1879
1882
// Get participantAccountIDs from participants object
1880
- let participants = participantAccountIDs ?? getParticipantAccountIDs ( reportID ) ;
1883
+ let participants = participantAccountIDs ?? Object . keys ( report ?. participants ?? { } ) . map ( Number ) ;
1881
1884
if ( shouldApplyLimit ) {
1882
1885
participants = participants . slice ( 0 , 5 ) ;
1883
1886
}
@@ -1894,20 +1897,6 @@ function getGroupChatName(participantAccountIDs?: number[], shouldApplyLimit = f
1894
1897
return Localize . translateLocal ( 'groupChat.defaultReportName' , { displayName : getDisplayNameForParticipant ( participants [ 0 ] , false ) } ) ;
1895
1898
}
1896
1899
1897
- function getVisibleChatMemberAccountIDs ( reportID : string ) : number [ ] {
1898
- const report = getReport ( reportID ) ;
1899
- if ( ! report || ! report . participants ) {
1900
- return [ ] ;
1901
- }
1902
- const visibleParticipantAccountIDs = Object . entries ( report . participants ) . reduce < number [ ] > ( ( accountIDs , [ accountID , participant ] ) => {
1903
- if ( participant && ! participant . hidden ) {
1904
- accountIDs . push ( Number ( accountID ) ) ;
1905
- }
1906
- return accountIDs ;
1907
- } , [ ] ) ;
1908
- return visibleParticipantAccountIDs ;
1909
- }
1910
-
1911
1900
function getParticipants ( reportID : string ) {
1912
1901
const report = getReport ( reportID ) ;
1913
1902
if ( ! report ) {
@@ -2064,7 +2053,7 @@ function getIcons(
2064
2053
source : report . avatarUrl || getDefaultGroupAvatar ( report . reportID ) ,
2065
2054
id : - 1 ,
2066
2055
type : CONST . ICON_TYPE_AVATAR ,
2067
- name : getGroupChatName ( undefined , true , report . reportID ?? '-1' ) ,
2056
+ name : getGroupChatName ( undefined , true , report ) ,
2068
2057
} ;
2069
2058
return [ groupChatIcon ] ;
2070
2059
}
@@ -3348,7 +3337,7 @@ function getReportName(report: OnyxEntry<Report>, policy?: OnyxEntry<Policy>): s
3348
3337
}
3349
3338
3350
3339
if ( isGroupChat ( report ) ) {
3351
- return getGroupChatName ( undefined , true , report ?. reportID ) ?? '' ;
3340
+ return getGroupChatName ( undefined , true , report ) ?? '' ;
3352
3341
}
3353
3342
3354
3343
if ( isChatRoom ( report ) || isTaskReport ( report ) ) {
@@ -3480,11 +3469,7 @@ function getParentNavigationSubtitle(report: OnyxEntry<Report>): ParentNavigatio
3480
3469
function navigateToDetailsPage ( report : OnyxEntry < Report > ) {
3481
3470
const isSelfDMReport = isSelfDM ( report ) ;
3482
3471
const isOneOnOneChatReport = isOneOnOneChat ( report ) ;
3483
-
3484
- // For 1:1 chat, we don't want to include currentUser as participants in order to not mark 1:1 chats as having multiple participants
3485
- const participantAccountID = Object . keys ( report ?. participants ?? { } )
3486
- . map ( Number )
3487
- . filter ( ( accountID ) => accountID !== currentUserAccountID || ! isOneOnOneChatReport ) ;
3472
+ const participantAccountID = getParticipantsAccountIDsForDisplay ( report ) ;
3488
3473
3489
3474
if ( isSelfDMReport || isOneOnOneChatReport ) {
3490
3475
Navigation . navigate ( ROUTES . PROFILE . getRoute ( participantAccountID [ 0 ] ) ) ;
@@ -3501,11 +3486,7 @@ function navigateToDetailsPage(report: OnyxEntry<Report>) {
3501
3486
*/
3502
3487
function goBackToDetailsPage ( report : OnyxEntry < Report > ) {
3503
3488
const isOneOnOneChatReport = isOneOnOneChat ( report ) ;
3504
-
3505
- // For 1:1 chat, we don't want to include currentUser as participants in order to not mark 1:1 chats as having multiple participants
3506
- const participantAccountID = Object . keys ( report ?. participants ?? { } )
3507
- . map ( Number )
3508
- . filter ( ( accountID ) => accountID !== currentUserAccountID || ! isOneOnOneChatReport ) ;
3489
+ const participantAccountID = getParticipantsAccountIDsForDisplay ( report ) ;
3509
3490
3510
3491
if ( isOneOnOneChatReport ) {
3511
3492
Navigation . navigate ( ROUTES . PROFILE . getRoute ( participantAccountID [ 0 ] ) ) ;
@@ -3524,9 +3505,7 @@ function goBackFromPrivateNotes(report: OnyxEntry<Report>, session: OnyxEntry<Se
3524
3505
}
3525
3506
const currentUserPrivateNote = report . privateNotes ?. [ session . accountID ] ?. note ?? '' ;
3526
3507
if ( isEmpty ( currentUserPrivateNote ) ) {
3527
- const participantAccountIDs = Object . keys ( report ?. participants ?? { } )
3528
- . map ( Number )
3529
- . filter ( ( accountID ) => accountID !== currentUserAccountID || ! isOneOnOneChat ( report ) ) ;
3508
+ const participantAccountIDs = getParticipantsAccountIDsForDisplay ( report ) ;
3530
3509
3531
3510
if ( isOneOnOneChat ( report ) ) {
3532
3511
Navigation . goBack ( ROUTES . PROFILE . getRoute ( participantAccountIDs [ 0 ] ) ) ;
@@ -7066,7 +7045,7 @@ export {
7066
7045
getOutstandingChildRequest ,
7067
7046
getParentNavigationSubtitle ,
7068
7047
getParsedComment ,
7069
- getParticipantAccountIDs ,
7048
+ getParticipantsAccountIDsForDisplay ,
7070
7049
getParticipants ,
7071
7050
getPendingChatMembers ,
7072
7051
getPersonalDetailsForAccountID ,
@@ -7098,7 +7077,6 @@ export {
7098
7077
getTransactionReportName ,
7099
7078
getTransactionsWithReceipts ,
7100
7079
getUserDetailTooltipText ,
7101
- getVisibleChatMemberAccountIDs ,
7102
7080
getWhisperDisplayNames ,
7103
7081
getWorkspaceAvatar ,
7104
7082
getWorkspaceChats ,
0 commit comments