@@ -111,17 +111,7 @@ function generateAccountID(searchValue: string): number {
111111 return hashText ( searchValue , 2 ** 32 ) ;
112112}
113113
114- /**
115- * Helper method to return the default avatar associated with the given accountID
116- */
117- function getDefaultAvatar ( accountID = - 1 , avatarURL ?: string ) : IconAsset | undefined {
118- if ( accountID === CONST . ACCOUNT_ID . CONCIERGE ) {
119- return ConciergeAvatar ;
120- }
121- if ( accountID === CONST . ACCOUNT_ID . NOTIFICATIONS ) {
122- return NotificationsAvatar ;
123- }
124-
114+ function getAccountIDHashBucket ( accountID = - 1 , avatarURL ?: string ) {
125115 // There are 24 possible default avatars, so we choose which one this user has based
126116 // on a simple modulo operation of their login number. Note that Avatar count starts at 1.
127117
@@ -135,7 +125,21 @@ function getDefaultAvatar(accountID = -1, avatarURL?: string): IconAsset | undef
135125 } else if ( accountID > 0 ) {
136126 accountIDHashBucket = ( ( accountID % CONST . DEFAULT_AVATAR_COUNT ) + 1 ) as AvatarRange ;
137127 }
128+ return accountIDHashBucket ;
129+ }
130+
131+ /**
132+ * Helper method to return the default avatar associated with the given accountID
133+ */
134+ function getDefaultAvatar ( accountID = - 1 , avatarURL ?: string ) : IconAsset | undefined {
135+ if ( accountID === CONST . ACCOUNT_ID . CONCIERGE ) {
136+ return ConciergeAvatar ;
137+ }
138+ if ( accountID === CONST . ACCOUNT_ID . NOTIFICATIONS ) {
139+ return NotificationsAvatar ;
140+ }
138141
142+ const accountIDHashBucket = getAccountIDHashBucket ( accountID , avatarURL ) ;
139143 if ( ! accountIDHashBucket ) {
140144 return ;
141145 }
@@ -146,13 +150,12 @@ function getDefaultAvatar(accountID = -1, avatarURL?: string): IconAsset | undef
146150/**
147151 * Helper method to return default avatar URL associated with the accountID
148152 */
149- function getDefaultAvatarURL ( accountID : string | number = '' ) : string {
153+ function getDefaultAvatarURL ( accountID : string | number = '' , avatarURL ?: string ) : string {
150154 if ( Number ( accountID ) === CONST . ACCOUNT_ID . CONCIERGE ) {
151155 return CONST . CONCIERGE_ICON_URL ;
152156 }
153157
154- // Note that Avatar count starts at 1 which is why 1 has to be added to the result (or else 0 would result in a broken avatar link)
155- const accountIDHashBucket = ( Number ( accountID ) % CONST . DEFAULT_AVATAR_COUNT ) + 1 ;
158+ const accountIDHashBucket = getAccountIDHashBucket ( Number ( accountID ) || - 1 , avatarURL ) ;
156159 const avatarPrefix = `default-avatar` ;
157160
158161 return `${ CONST . CLOUDFRONT_URL } /images/avatars/${ avatarPrefix } _${ accountIDHashBucket } .png` ;
@@ -196,7 +199,7 @@ function getAvatar(avatarSource?: AvatarSource, accountID?: number): AvatarSourc
196199 * @param accountID - the accountID of the user
197200 */
198201function getAvatarUrl ( avatarSource : AvatarSource | undefined , accountID : number ) : AvatarSource {
199- return isDefaultAvatar ( avatarSource ) ? getDefaultAvatarURL ( accountID ) : avatarSource ;
202+ return isDefaultAvatar ( avatarSource ) ? getDefaultAvatarURL ( accountID , avatarSource ) : avatarSource ;
200203}
201204
202205/**
0 commit comments