@@ -9,8 +9,6 @@ import CONST from '../CONST';
9
9
import * as ReportUtils from './reportUtils' ;
10
10
import * as Localize from './Localize' ;
11
11
import Permissions from './Permissions' ;
12
- import md5 from './md5' ;
13
- import * as Expensicons from '../components/Icon/Expensicons' ;
14
12
15
13
/**
16
14
* OptionsListUtils is used to build a list options passed to the OptionsList component. Several different UI views can
@@ -78,22 +76,9 @@ Onyx.connect({
78
76
} ,
79
77
} ) ;
80
78
81
- /**
82
- * Helper method to return a default avatar
83
- *
84
- * @param {String } [login]
85
- * @returns {String }
86
- */
87
- function getDefaultAvatar ( login = '' ) {
88
- // There are 8 possible default avatars, so we choose which one this user has based
89
- // on a simple hash of their login (which is converted from HEX to INT)
90
- const loginHashBucket = ( parseInt ( md5 ( login ) . substring ( 0 , 4 ) , 16 ) % 8 ) + 1 ;
91
- return `${ CONST . CLOUDFRONT_URL } /images/avatars/avatar_${ loginHashBucket } .png` ;
92
- }
93
-
94
79
// We are initializing a default avatar here so that we use the same default color for each user we are inviting. This
95
80
// will update when the OptionsListUtils re-loads. But will stay the same color for the life of the JS session.
96
- const defaultAvatarForUserToInvite = getDefaultAvatar ( ) ;
81
+ const defaultAvatarForUserToInvite = ReportUtils . getDefaultAvatar ( ) ;
97
82
98
83
/**
99
84
* Adds expensify SMS domain (@expensify.sms) if login is a phone number and if it's not included yet
@@ -124,7 +109,7 @@ function getPersonalDetailsForLogins(logins, personalDetails) {
124
109
personalDetail = {
125
110
login,
126
111
displayName : login ,
127
- avatar : getDefaultAvatar ( login ) ,
112
+ avatar : ReportUtils . getDefaultAvatar ( login ) ,
128
113
} ;
129
114
}
130
115
@@ -206,51 +191,23 @@ function hasReportDraftComment(report) {
206
191
&& lodashGet ( reportsWithDraft , `${ ONYXKEYS . COLLECTION . REPORTS_WITH_DRAFT } ${ report . reportID } ` , false ) ;
207
192
}
208
193
209
- /**
210
- * Get the Avatar urls or return the icon according to the chat type
211
- *
212
- * @param {Object } report
213
- * @returns {Array<*> }
214
- */
215
- function getAvatarSources ( report ) {
216
- return _ . map ( lodashGet ( report , 'icons' , [ '' ] ) , ( source ) => {
217
- if ( source ) {
218
- return source ;
219
- }
220
- if ( ReportUtils . isArchivedRoom ( report ) ) {
221
- return Expensicons . DeletedRoomAvatar ;
222
- }
223
- if ( ReportUtils . isAdminRoom ( report ) ) {
224
- return Expensicons . AdminRoomAvatar ;
225
- }
226
- if ( ReportUtils . isAnnounceRoom ( report ) ) {
227
- return Expensicons . AnnounceRoomAvatar ;
228
- }
229
- if ( ReportUtils . isChatRoom ( report ) ) {
230
- return Expensicons . ActiveRoomAvatar ;
231
- }
232
- if ( ReportUtils . isPolicyExpenseChat ( report ) ) {
233
- return Expensicons . Workspace ;
234
- }
235
- return Expensicons . Profile ;
236
- } ) ;
237
- }
238
-
239
194
/**
240
195
* Creates a report list option
241
196
*
242
- * @param {Array<Object> } personalDetailList
197
+ * @param {Array<String> } logins
198
+ * @param {Object } personalDetails
243
199
* @param {Object } report
244
200
* @param {Object } options
245
201
* @param {Boolean } [options.showChatPreviewLine]
246
202
* @param {Boolean } [options.forcePolicyNamePreview]
247
203
* @returns {Object }
248
204
*/
249
- function createOption ( personalDetailList , report , {
205
+ function createOption ( logins , personalDetails , report , {
250
206
showChatPreviewLine = false , forcePolicyNamePreview = false ,
251
207
} ) {
252
208
const isChatRoom = ReportUtils . isChatRoom ( report ) ;
253
209
const isPolicyExpenseChat = ReportUtils . isPolicyExpenseChat ( report ) ;
210
+ const personalDetailList = getPersonalDetailsForLogins ( logins , personalDetails ) ;
254
211
const isArchivedRoom = ReportUtils . isArchivedRoom ( report ) ;
255
212
const hasMultipleParticipants = personalDetailList . length > 1 || isChatRoom || isPolicyExpenseChat ;
256
213
const personalDetail = personalDetailList [ 0 ] ;
@@ -271,7 +228,6 @@ function createOption(personalDetailList, report, {
271
228
272
229
const tooltipText = ReportUtils . getReportParticipantsTitle ( lodashGet ( report , [ 'participants' ] , [ ] ) ) ;
273
230
const subtitle = ReportUtils . getChatRoomSubtitle ( report , policies ) ;
274
- let icons = getAvatarSources ( report ) ;
275
231
let text ;
276
232
let alternateText ;
277
233
if ( isChatRoom || isPolicyExpenseChat ) {
@@ -287,15 +243,11 @@ function createOption(personalDetailList, report, {
287
243
alternateText = ( showChatPreviewLine && lastMessageText )
288
244
? lastMessageText
289
245
: Str . removeSMSDomain ( personalDetail . login ) ;
290
- if ( ! report ) {
291
- // If the report doesn't exist then we're creating a list of users to invite (using the personalDetailList)
292
- icons = [ personalDetail . avatar ] ;
293
- }
294
246
}
295
247
return {
296
248
text,
297
249
alternateText,
298
- icons,
250
+ icons : ReportUtils . getIcons ( report , personalDetails , policies , lodashGet ( personalDetail , [ 'avatar' ] ) ) ,
299
251
tooltipText,
300
252
ownerEmail : lodashGet ( report , [ 'ownerEmail' ] ) ,
301
253
subtitle,
@@ -471,23 +423,21 @@ function getOptions(reports, personalDetails, activeReportID, {
471
423
return ;
472
424
}
473
425
474
- const reportPersonalDetails = getPersonalDetailsForLogins ( logins , personalDetails ) ;
475
-
476
426
// Save the report in the map if this is a single participant so we can associate the reportID with the
477
427
// personal detail option later. Individuals should not be associated with single participant
478
428
// policyExpenseChats or chatRooms since those are not people.
479
429
if ( logins . length <= 1 && ! ReportUtils . isPolicyExpenseChat ( report ) && ! ReportUtils . isChatRoom ( report ) ) {
480
430
reportMapForLogins [ logins [ 0 ] ] = report ;
481
431
}
482
432
const isSearchingSomeonesPolicyExpenseChat = ! report . isOwnPolicyExpenseChat && searchValue !== '' ;
483
- allReportOptions . push ( createOption ( reportPersonalDetails , report , {
433
+ allReportOptions . push ( createOption ( logins , personalDetails , report , {
484
434
showChatPreviewLine,
485
435
forcePolicyNamePreview : isPolicyExpenseChat ? isSearchingSomeonesPolicyExpenseChat : forcePolicyNamePreview ,
486
436
} ) ) ;
487
437
} ) ;
488
438
489
439
const allPersonalDetailsOptions = _ . map ( personalDetails , personalDetail => (
490
- createOption ( [ personalDetail ] , reportMapForLogins [ personalDetail . login ] , {
440
+ createOption ( [ personalDetail . login ] , personalDetails , reportMapForLogins [ personalDetail . login ] , {
491
441
showChatPreviewLine,
492
442
forcePolicyNamePreview,
493
443
} )
@@ -603,8 +553,7 @@ function getOptions(reports, personalDetails, activeReportID, {
603
553
const login = ( Str . isValidPhone ( searchValue ) && ! searchValue . includes ( '+' ) )
604
554
? `+${ countryCodeByIP } ${ searchValue } `
605
555
: searchValue ;
606
- const userInvitePersonalDetails = getPersonalDetailsForLogins ( [ login ] , personalDetails ) ;
607
- userToInvite = createOption ( userInvitePersonalDetails , null , {
556
+ userToInvite = createOption ( [ login ] , personalDetails , null , {
608
557
showChatPreviewLine,
609
558
} ) ;
610
559
userToInvite . icons = [ defaultAvatarForUserToInvite ] ;
@@ -817,47 +766,9 @@ function getCurrencyListForSections(currencyOptions, searchValue) {
817
766
} ;
818
767
}
819
768
820
- /**
821
- * Returns the appropriate icons for the given chat report using personalDetails if applicable
822
- *
823
- * @param {Object } report
824
- * @param {Object } personalDetails
825
- * @returns {Array<String> }
826
- */
827
- function getReportIcons ( report , personalDetails ) {
828
- // Default rooms have a specific avatar so we can return any non-empty array
829
- if ( ReportUtils . isChatRoom ( report ) ) {
830
- return [ '' ] ;
831
- }
832
-
833
- if ( ReportUtils . isPolicyExpenseChat ( report ) ) {
834
- const policyExpenseChatAvatarURL = lodashGet ( policies , [
835
- `${ ONYXKEYS . COLLECTION . POLICY } ${ report . policyID } ` , 'avatarURL' ,
836
- ] ) ;
837
-
838
- // Return the workspace avatar if the user is the owner of the policy expense chat
839
- if ( report . isOwnPolicyExpenseChat ) {
840
- return [ policyExpenseChatAvatarURL ] ;
841
- }
842
-
843
- // If the user is an admin, return avatar url of the other participant of the report
844
- // (their workspace chat) and the avatar url of the workspace
845
- return [ lodashGet ( personalDetails , [ report . ownerEmail , 'avatarThumbnail' ] ) , policyExpenseChatAvatarURL ] ;
846
- }
847
-
848
- const sortedParticipants = _ . map ( report . participants , dmParticipant => ( {
849
- firstName : lodashGet ( personalDetails , [ dmParticipant , 'firstName' ] , '' ) ,
850
- avatar : lodashGet ( personalDetails , [ dmParticipant , 'avatarThumbnail' ] , '' )
851
- || getDefaultAvatar ( dmParticipant ) ,
852
- } ) )
853
- . sort ( ( first , second ) => first . firstName - second . firstName ) ;
854
- return _ . map ( sortedParticipants , item => item . avatar ) ;
855
- }
856
-
857
769
export {
858
770
addSMSDomainIfPhoneNumber ,
859
771
isCurrentUser ,
860
- getAvatarSources ,
861
772
getSearchOptions ,
862
773
getNewChatOptions ,
863
774
getSidebarOptions ,
@@ -866,6 +777,4 @@ export {
866
777
getCurrencyListForSections ,
867
778
getIOUConfirmationOptionsFromMyPersonalDetail ,
868
779
getIOUConfirmationOptionsFromParticipants ,
869
- getDefaultAvatar ,
870
- getReportIcons ,
871
780
} ;
0 commit comments