-
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
fix: remove getDisplayNameForTypingIndicator #31495
fix: remove getDisplayNameForTypingIndicator #31495
Conversation
return null; | ||
} | ||
|
||
const firstUserTyping = usersTyping[0]; | ||
const firstUserTypingID = Number.isNaN(firstUserTyping) ? PersonalDetailsUtils.getAccountIDsByLogins([firstUserTyping])[0] : firstUserTyping; |
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.
What is the data structure of usersTyping[0]
?
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.
@fabioh8010 usersTyping is an array of the ids of the users typing in the report, so the usersTyping[0] is a string or a number
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.
I'm having some difficult to understand what this line is doing 😅
For example, are you using Number.isNaN(firstUserTyping)
for checking if string or number?
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.
yes, it was the logic from the removed method that I moved here. But I forgot to wrap the usersTyping[0] in Number as it is supposed to be a string (I will check it for sure)
return null; | ||
} | ||
|
||
const firstUserTyping = usersTyping[0]; | ||
const firstUserTypingID = Number.isNaN(firstUserTyping) ? PersonalDetailsUtils.getAccountIDsByLogins([firstUserTyping])[0] : firstUserTyping; |
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.
PersonalDetailsUtils.getAccountIDsByLogins
does a traverse on the personalDetails
- imo worth memoising this call, could you please try it?
@situchan friendly bump 🙂 |
/** Information about the network */ | ||
network: networkPropTypes.isRequired, | ||
|
||
...withLocalizePropTypes, | ||
}; | ||
|
||
const defaultProps = { | ||
userTypingStatuses: {}, | ||
}; | ||
|
||
function ReportTypingIndicator(props) { |
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.
As we're touching this component, can we destructure props?
const usersTyping = useMemo(() => _.filter(_.keys(props.userTypingStatuses), (loginOrAccountID) => props.userTypingStatuses[loginOrAccountID]), [props.userTypingStatuses]); | ||
const usersTyping = useMemo(() => _.filter(_.keys(userTypingStatuses), (loginOrAccountID) => userTypingStatuses[loginOrAccountID]), [userTypingStatuses]); | ||
const firstUserTyping = usersTyping[0]; | ||
const firstUserTypingID = useMemo( |
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.
Please move old comment to here
// If the user is typing on OldDot, firstUserTyping will be a string (the user's login)
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.
I think we can optimize a bit like this:
// If we are offline, the user typing statuses are not up-to-date so do not show them | ||
if (props.network.isOffline) { | ||
if (isOffline) { |
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.
if (isOffline) { | |
if (isOffline || !firstUserTyping) { |
const numUsersTyping = _.size(usersTyping); | ||
|
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.
const numUsersTyping = _.size(usersTyping); |
@@ -44,8 +49,8 @@ function ReportTypingIndicator(props) { | |||
case 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.
replace switch/case with ? :
return usersTyping.length === 1 ? <TextWithEllipsis /> : <Text />
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.
as the components for this are not one-liners I'd rather do it with an if statement, it'll be more readable
@situchan changes applied 🙂 |
When type message from oldDot, it says "Someone is typing..." Screen.Recording.2023-12-01.at.7.15.05.PM.mov |
ok so I know what the issue is. In old logic, it fallback to this:
@koko57 we should apply same to new logic |
@situchan fixed! |
leadingTextParentStyle={styles.chatItemComposeSecondaryRowOffset} | ||
/> | ||
); | ||
// If the user is typing on OldDot, firstUserTyping will be a string (the user's login) |
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.
// If the user is typing on OldDot, firstUserTyping will be a string (the user's login) | |
// If the user is typing on OldDot, firstUserTyping will be a string (the user's displayName) |
/> | ||
); | ||
// If the user is typing on OldDot, firstUserTyping will be a string (the user's login) | ||
const firstUserTypingDisplayName = ReportUtils.getDisplayNameForParticipant(firstUserTypingID, false, false) || firstUserTyping; |
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.
I don't think this will work when users don't know each other.
There's case when Somone is typing...
but with this change, it will never happen
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.
I have 2 solutions in mind:
getAccountIDsByLogins
accepts 2nd parameter -shouldGenerateAccountID
. If it's obvious that 1st param is notlogin
butdisplayName
, no need to generate random accountID but just return 0 or null. And then update this line like this:
const firstUserTypingDisplayName = firstUserTypingID ? ReportUtils.getDisplayNameForParticipant(firstUserTypingID, false, false) : firstUserTyping;
- check displayName if it comes from oldDot by doing email/phone validation
I prefer 1st one since user can still set any random email as display name
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.
@situchan can even such a scenario occur? How could I reproduce it?
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.
which one are you not able to reproduce?
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.
Here's repro step:
- on A, create new chat with B
- A sends any message to B
- on B, type something
- Observe chat on A
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.
Please don't set display name on both accounts and try again
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.
I think the purpose of hidden logic is to secure sensitive info (login
in our case)
So if display name not set, show "Hidden"
if display name set, show that display name
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.
but for one of them it was set automatically
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.
Maybe you logged with google?
Btw you can unset display name in setting
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.
I unset it, still the same. I'll get back to it on Monday
Screen.Recording.2023-12-01.at.18.40.35.mp4
const firstUserTypingID = useMemo( | ||
() => (firstUserTyping && isUserTypingADisplayName ? PersonalDetailsUtils.getAccountIDsByLogins([firstUserTyping])[0] : firstUserTyping), | ||
[firstUserTyping, isUserTypingADisplayName], | ||
); |
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.
As per below line, this code block will never run.
const firstUserTypingDisplayName = isUserTypingADisplayName ? firstUserTyping : ReportUtils.getDisplayNameForParticipant(firstUserTypingID, false, false);
This will cause regression of displaying email instead of displayName whenfirstUserTyping
is login
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.
do we have such a case? Can you reproduce it for me? For all the users I have in the OldDot firstUserTyping is an id of digits.
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.
I am not sure about that case too. But I am just concerned about deprecating this old code which tries to find user info with login
App/src/libs/actions/PersonalDetails.ts
Lines 71 to 79 in 617c2dd
// If the user is typing on OldDot, userAccountIDOrLogin will be a string (the user's login), | |
// so Number(string) is NaN. Search for personalDetails by login to get the display name. | |
if (Number.isNaN(accountID)) { | |
const detailsByLogin = Object.entries(allPersonalDetails ?? {}).find(([, value]) => value?.login === userAccountIDOrLogin)?.[1]; | |
// It's possible for displayName to be empty string, so we must use "||" to fallback to userAccountIDOrLogin. | |
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | |
return detailsByLogin?.displayName || userAccountIDOrLogin; | |
} |
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.
This old code should have been simplified like this if there's not such case of login
if (Number.isNaN(accountID)) {
return userAccountIDOrLogin;
}
Does my concern make sense?
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.
but from the old code we would still return userAccountIDOrLogin (whatever is saved as firstUserTyping) to be shown and here we also show it
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.
What I'd like to confirm is that the old code was redundant and could be simplified like this:
if (Number.isNaN(accountID)) {
return userAccountIDOrLogin;
}
/> | ||
); | ||
// If the user is typing on OldDot, firstUserTyping will be a string (the user's displayName) | ||
const firstUserTypingDisplayName = isUserTypingADisplayName ? firstUserTyping : ReportUtils.getDisplayNameForParticipant(firstUserTypingID, false, false); |
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.
If there's no case of login
as firstUserTyping
, this code can be updated like this:
const firstUserTypingDisplayName = isUserTypingADisplayName ? firstUserTyping : ReportUtils.getDisplayNameForParticipant(firstUserTypingID, false, false); | |
const firstUserTypingDisplayName = isUserTypingADisplayName ? firstUserTyping : ReportUtils.getDisplayNameForParticipant(firstUserTyping, false, false); |
And remove unnecessary firstUserTypingID
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.
So is there a posibility that firstUserTyping is a login or not? In which case then? Maybe I'm missing something
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.
Do you agree with my code suggestion above?
@puneetlath can you please confirm in backend App/src/libs/actions/PersonalDetails.ts Lines 71 to 79 in 617c2dd
This old code which gets personal details by login doesn't make sense to me. Not able to find this case. userAccountIDOrLogin could be simply returned
|
Oh interesting. It looks like the back-end does still use login for reportUserIsTyping. We should update it to use accountID. |
Upon testing, I think it's not |
@puneetlath @situchan what's the final decision about this login/display name logic? |
@puneetlath @situchan friendly bump 🙂 I think that this logic @situchan question here doesn't cause this regression. |
Anything pending from me? |
My apologies for the delay. Yes, it looks like only login is not sent in |
@situchan so as we're not getting login I'm not insisting on the logic I've added. I applied the changes removing this check. Asking for re-review 🙂 |
please fix lint |
@situchan fixed! |
Reviewer Checklist
Screenshots/VideosAndroid: Nativedesktop-android-hidden-user.movAndroid: mWeb ChromeiOS: Nativeios.moviOS: mWeb Safarimsafari.movMacOS: Chrome / Safarinewdot.movolddot.movMacOS: Desktopdesktop-android-hidden-user.mov |
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.
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.
Great job with this. Sorry for the delays on my side.
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by https://github.com/puneetlath in version: 1.4.21-0 🚀
|
🚀 Deployed to production by https://github.com/marcaaron in version: 1.4.21-4 🚀
|
1 similar comment
🚀 Deployed to production by https://github.com/marcaaron in version: 1.4.21-4 🚀
|
🚀 Deployed to production by https://github.com/marcaaron in version: 1.4.21-4 🚀
|
First PR for #31312
Details
Fixed Issues
$ #31312
PROPOSAL: $ #31312 (comment)
Tests
[Typing User Name] is typing...
Offline tests
N/A
QA Steps
[Typing User Name] is typing...
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop