-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sort group member avatar icons correctly to avoid avatar rearranging upon receiving backend response #25416
Sort group member avatar icons correctly to avoid avatar rearranging upon receiving backend response #25416
Changes from 4 commits
990932d
10bebee
83d5baa
fd1f659
e70c1e9
bcaa077
2996bf5
4d93923
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -884,23 +884,30 @@ function getIconsForParticipants(participants, personalDetails) { | |
for (let i = 0; i < participantsList.length; i++) { | ||
const accountID = participantsList[i]; | ||
const avatarSource = UserUtils.getAvatar(lodashGet(personalDetails, [accountID, 'avatar'], ''), accountID); | ||
participantDetails.push([ | ||
accountID, | ||
lodashGet(personalDetails, [accountID, 'displayName']) || lodashGet(personalDetails, [accountID, 'login'], ''), | ||
lodashGet(personalDetails, [accountID, 'firstName'], ''), | ||
avatarSource, | ||
]); | ||
participantDetails.push([accountID, lodashGet(personalDetails, [accountID, 'displayName']) || lodashGet(personalDetails, [accountID, 'login'], ''), avatarSource]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make this a little more readable by pulling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the feedbacks, I am back :) Appreciate your review again. |
||
} | ||
|
||
// Sort all logins by first name (which is the second element in the array) | ||
const sortedParticipantDetails = participantDetails.sort((a, b) => a[2] - b[2]); | ||
const sortedParticipantDetails = _.chain(participantDetails) | ||
.sort((first, second) => { | ||
// First sort by displayName/login | ||
const displayNameLoginOrder = first[1].localeCompare(second[1]); | ||
if (displayNameLoginOrder !== 0) { | ||
return displayNameLoginOrder; | ||
} | ||
|
||
// Then fallback on accountID as the final sorting criteria. | ||
// This will ensure that the order of avatars with same login/displayName | ||
// stay consistent across all users and devices | ||
return first[0] > second[0]; | ||
}) | ||
.value(); | ||
|
||
// Now that things are sorted, gather only the avatars (third element in the array) and return those | ||
const avatars = []; | ||
for (let i = 0; i < sortedParticipantDetails.length; i++) { | ||
const userIcon = { | ||
id: sortedParticipantDetails[i][0], | ||
source: sortedParticipantDetails[i][3], | ||
source: sortedParticipantDetails[i][2], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated from index 3 to 2 for avatar source, because the original index 2 element (firstName) is deemed unnecessary and removed. |
||
type: CONST.ICON_TYPE_AVATAR, | ||
name: sortedParticipantDetails[i][1], | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upon reviewing this again, I found that the original firstName element (index 2) is only used for sorting.
The thing is, when a user has firstName configured, his displayName/login is going to be a string that starts with his firstName.
e.g.
So it is actually redundant to first sort using
firstName
, then sub-sort usingdisplayName/login
.Because we will get the exact same results if we just skip sorting using
firstName
, and start initial sorting usingdisplayName/login
.With that reasoning, I have updated the code to remove firstName element from the array, because not using it for sorting means we do not need it at all.