From a57d229f1fd88f721cf9662db01636d434b6ae17 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Fri, 17 Nov 2023 18:34:18 +0100 Subject: [PATCH 01/13] fix: remove getDisplayNameForTypingIndicator --- src/libs/actions/PersonalDetails.ts | 26 ---------- .../home/report/ReportTypingIndicator.js | 47 +++++++++---------- 2 files changed, 22 insertions(+), 51 deletions(-) diff --git a/src/libs/actions/PersonalDetails.ts b/src/libs/actions/PersonalDetails.ts index 2d51fbb9e8d2..725159c1c7f3 100644 --- a/src/libs/actions/PersonalDetails.ts +++ b/src/libs/actions/PersonalDetails.ts @@ -59,31 +59,6 @@ function getDisplayName(login: string, personalDetail: Pick 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; - } - - const detailsByAccountID = allPersonalDetails?.[accountID]; - - // It's possible for displayName to be empty string, so we must use "||" to fallback to login or defaultDisplayName. - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - return detailsByAccountID?.displayName || detailsByAccountID?.login || defaultDisplayName; -} - /** * Gets the first and last name from the user's personal details. * If the login is the same as the displayName, then they don't exist, @@ -584,7 +559,6 @@ export { extractFirstAndLastNameFromAvailableDetails, getCountryISO, getDisplayName, - getDisplayNameForTypingIndicator, getPrivatePersonalDetails, openPersonalDetailsPage, openPublicProfilePage, diff --git a/src/pages/home/report/ReportTypingIndicator.js b/src/pages/home/report/ReportTypingIndicator.js index 3a2c611ac358..c2c9a0222542 100755 --- a/src/pages/home/report/ReportTypingIndicator.js +++ b/src/pages/home/report/ReportTypingIndicator.js @@ -2,24 +2,18 @@ import PropTypes from 'prop-types'; import React, {useMemo} from 'react'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; -import networkPropTypes from '@components/networkPropTypes'; -import {withNetwork} from '@components/OnyxProvider'; import Text from '@components/Text'; import TextWithEllipsis from '@components/TextWithEllipsis'; -import withLocalize, {withLocalizePropTypes} from '@components/withLocalize'; -import compose from '@libs/compose'; +import useLocalize from '@hooks/useLocalize'; +import useNetwork from '@hooks/useNetwork'; +import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; +import * as ReportUtils from '@libs/ReportUtils'; import useThemeStyles from '@styles/useThemeStyles'; -import * as PersonalDetails from '@userActions/PersonalDetails'; import ONYXKEYS from '@src/ONYXKEYS'; const propTypes = { /** Key-value pairs of user accountIDs/logins and whether or not they are typing. Keys are accountIDs or logins. */ userTypingStatuses: PropTypes.objectOf(PropTypes.bool), - - /** Information about the network */ - network: networkPropTypes.isRequired, - - ...withLocalizePropTypes, }; const defaultProps = { @@ -27,13 +21,20 @@ const defaultProps = { }; function ReportTypingIndicator(props) { + const {translate} = useLocalize(); + const {isOffline} = useNetwork(); + const styles = useThemeStyles(); const usersTyping = useMemo(() => _.filter(_.keys(props.userTypingStatuses), (loginOrAccountID) => props.userTypingStatuses[loginOrAccountID]), [props.userTypingStatuses]); // If we are offline, the user typing statuses are not up-to-date so do not show them - if (props.network.isOffline) { + if (isOffline) { return null; } + const firstUserTyping = usersTyping[0]; + const firstUserTypingID = Number.isNaN(firstUserTyping) ? PersonalDetailsUtils.getAccountIDsByLogins([firstUserTyping])[0] : firstUserTyping; + const firstUserTypingDisplayName = ReportUtils.getDisplayNameForParticipant(firstUserTypingID, false, false); + const numUsersTyping = _.size(usersTyping); // Decide on the Text element that will hold the display based on the number of users that are typing. @@ -44,8 +45,8 @@ function ReportTypingIndicator(props) { case 1: return ( - {props.translate('reportTypingIndicator.multipleUsers')} - {` ${props.translate('reportTypingIndicator.areTyping')}`} + {translate('reportTypingIndicator.multipleUsers')} + {` ${translate('reportTypingIndicator.areTyping')}`} ); } @@ -69,13 +70,9 @@ ReportTypingIndicator.propTypes = propTypes; ReportTypingIndicator.defaultProps = defaultProps; ReportTypingIndicator.displayName = 'ReportTypingIndicator'; -export default compose( - withLocalize, - withNetwork(), - withOnyx({ - userTypingStatuses: { - key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT_USER_IS_TYPING}${reportID}`, - initialValue: {}, - }, - }), -)(ReportTypingIndicator); +export default withOnyx({ + userTypingStatuses: { + key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT_USER_IS_TYPING}${reportID}`, + initialValue: {}, + }, +})(ReportTypingIndicator); From 1ff3017f95159fefe0c7318cad05b7ad4f1bd440 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Tue, 21 Nov 2023 10:17:04 +0100 Subject: [PATCH 02/13] fix: apply requested changes --- src/pages/home/report/ReportTypingIndicator.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportTypingIndicator.js b/src/pages/home/report/ReportTypingIndicator.js index c2c9a0222542..9b0757668d59 100755 --- a/src/pages/home/report/ReportTypingIndicator.js +++ b/src/pages/home/report/ReportTypingIndicator.js @@ -26,13 +26,14 @@ function ReportTypingIndicator(props) { const styles = useThemeStyles(); const usersTyping = useMemo(() => _.filter(_.keys(props.userTypingStatuses), (loginOrAccountID) => props.userTypingStatuses[loginOrAccountID]), [props.userTypingStatuses]); + const firstUserTyping = usersTyping[0]; + const firstUserTypingID = useMemo(() => firstUserTyping && Number.isNaN(Number(firstUserTyping)) ? PersonalDetailsUtils.getAccountIDsByLogins([firstUserTyping])[0] : firstUserTyping, [firstUserTyping]); + // If we are offline, the user typing statuses are not up-to-date so do not show them if (isOffline) { return null; } - const firstUserTyping = usersTyping[0]; - const firstUserTypingID = Number.isNaN(firstUserTyping) ? PersonalDetailsUtils.getAccountIDsByLogins([firstUserTyping])[0] : firstUserTyping; const firstUserTypingDisplayName = ReportUtils.getDisplayNameForParticipant(firstUserTypingID, false, false); const numUsersTyping = _.size(usersTyping); From b30cb29aa57cf1ede0a2103aa87931fdc46c2138 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Tue, 21 Nov 2023 11:40:10 +0100 Subject: [PATCH 03/13] fix: run prettier --- src/pages/home/report/ReportTypingIndicator.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportTypingIndicator.js b/src/pages/home/report/ReportTypingIndicator.js index 9b0757668d59..9e0149e973e4 100755 --- a/src/pages/home/report/ReportTypingIndicator.js +++ b/src/pages/home/report/ReportTypingIndicator.js @@ -27,7 +27,10 @@ function ReportTypingIndicator(props) { const styles = useThemeStyles(); const usersTyping = useMemo(() => _.filter(_.keys(props.userTypingStatuses), (loginOrAccountID) => props.userTypingStatuses[loginOrAccountID]), [props.userTypingStatuses]); const firstUserTyping = usersTyping[0]; - const firstUserTypingID = useMemo(() => firstUserTyping && Number.isNaN(Number(firstUserTyping)) ? PersonalDetailsUtils.getAccountIDsByLogins([firstUserTyping])[0] : firstUserTyping, [firstUserTyping]); + const firstUserTypingID = useMemo( + () => (firstUserTyping && Number.isNaN(Number(firstUserTyping)) ? PersonalDetailsUtils.getAccountIDsByLogins([firstUserTyping])[0] : firstUserTyping), + [firstUserTyping], + ); // If we are offline, the user typing statuses are not up-to-date so do not show them if (isOffline) { From 2ffcec2417dd634c342460171de57b2bc847f049 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Thu, 30 Nov 2023 08:58:31 +0100 Subject: [PATCH 04/13] fix: destructure props --- src/pages/home/report/ReportTypingIndicator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportTypingIndicator.js b/src/pages/home/report/ReportTypingIndicator.js index 9e0149e973e4..afb18a98b350 100755 --- a/src/pages/home/report/ReportTypingIndicator.js +++ b/src/pages/home/report/ReportTypingIndicator.js @@ -20,12 +20,12 @@ const defaultProps = { userTypingStatuses: {}, }; -function ReportTypingIndicator(props) { +function ReportTypingIndicator({userTypingStatuses}) { const {translate} = useLocalize(); const {isOffline} = useNetwork(); const styles = useThemeStyles(); - 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( () => (firstUserTyping && Number.isNaN(Number(firstUserTyping)) ? PersonalDetailsUtils.getAccountIDsByLogins([firstUserTyping])[0] : firstUserTyping), From fe1e320e2fe8270aa45aac8d83548f933a0a9e50 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Fri, 1 Dec 2023 09:43:54 +0100 Subject: [PATCH 05/13] fix: apply requested changes --- .../home/report/ReportTypingIndicator.js | 51 ++++++++----------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/src/pages/home/report/ReportTypingIndicator.js b/src/pages/home/report/ReportTypingIndicator.js index afb18a98b350..a519afaaa8ba 100755 --- a/src/pages/home/report/ReportTypingIndicator.js +++ b/src/pages/home/report/ReportTypingIndicator.js @@ -27,47 +27,40 @@ function ReportTypingIndicator({userTypingStatuses}) { const styles = useThemeStyles(); const usersTyping = useMemo(() => _.filter(_.keys(userTypingStatuses), (loginOrAccountID) => userTypingStatuses[loginOrAccountID]), [userTypingStatuses]); const firstUserTyping = usersTyping[0]; + + // If the user is typing on OldDot, firstUserTyping will be a string (the user's login) const firstUserTypingID = useMemo( () => (firstUserTyping && Number.isNaN(Number(firstUserTyping)) ? PersonalDetailsUtils.getAccountIDsByLogins([firstUserTyping])[0] : firstUserTyping), [firstUserTyping], ); // If we are offline, the user typing statuses are not up-to-date so do not show them - if (isOffline) { + if (isOffline || !firstUserTyping) { return null; } const firstUserTypingDisplayName = ReportUtils.getDisplayNameForParticipant(firstUserTypingID, false, false); - const numUsersTyping = _.size(usersTyping); - - // Decide on the Text element that will hold the display based on the number of users that are typing. - switch (numUsersTyping) { - case 0: - return null; - - case 1: - return ( - - ); - - default: - return ( - - {translate('reportTypingIndicator.multipleUsers')} - {` ${translate('reportTypingIndicator.areTyping')}`} - - ); + if (usersTyping.length === 1) { + return ( + + ) } + return ( + + {translate('reportTypingIndicator.multipleUsers')} + {` ${translate('reportTypingIndicator.areTyping')}`} + + ); } ReportTypingIndicator.propTypes = propTypes; From e7d667c2edc8300b5fcb649490785a153c98aaeb Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Fri, 1 Dec 2023 09:49:58 +0100 Subject: [PATCH 06/13] fix: run prettier --- src/pages/home/report/ReportTypingIndicator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportTypingIndicator.js b/src/pages/home/report/ReportTypingIndicator.js index a519afaaa8ba..c141a4d141e1 100755 --- a/src/pages/home/report/ReportTypingIndicator.js +++ b/src/pages/home/report/ReportTypingIndicator.js @@ -50,7 +50,7 @@ function ReportTypingIndicator({userTypingStatuses}) { wrapperStyle={[styles.chatItemComposeSecondaryRow, styles.flex1]} leadingTextParentStyle={styles.chatItemComposeSecondaryRowOffset} /> - ) + ); } return ( Date: Fri, 1 Dec 2023 15:38:16 +0100 Subject: [PATCH 07/13] fix: minor fix --- src/pages/home/report/ReportTypingIndicator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportTypingIndicator.js b/src/pages/home/report/ReportTypingIndicator.js index c141a4d141e1..6c6531955115 100755 --- a/src/pages/home/report/ReportTypingIndicator.js +++ b/src/pages/home/report/ReportTypingIndicator.js @@ -28,7 +28,6 @@ function ReportTypingIndicator({userTypingStatuses}) { const usersTyping = useMemo(() => _.filter(_.keys(userTypingStatuses), (loginOrAccountID) => userTypingStatuses[loginOrAccountID]), [userTypingStatuses]); const firstUserTyping = usersTyping[0]; - // If the user is typing on OldDot, firstUserTyping will be a string (the user's login) const firstUserTypingID = useMemo( () => (firstUserTyping && Number.isNaN(Number(firstUserTyping)) ? PersonalDetailsUtils.getAccountIDsByLogins([firstUserTyping])[0] : firstUserTyping), [firstUserTyping], @@ -39,7 +38,8 @@ function ReportTypingIndicator({userTypingStatuses}) { return null; } - const firstUserTypingDisplayName = ReportUtils.getDisplayNameForParticipant(firstUserTypingID, false, false); + // If the user is typing on OldDot, firstUserTyping will be a string (the user's login) + const firstUserTypingDisplayName = ReportUtils.getDisplayNameForParticipant(firstUserTypingID, false, false) || firstUserTyping; if (usersTyping.length === 1) { return ( From c0a9c6a47e613e22ac9df761ab0f8a7c1d062742 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Wed, 6 Dec 2023 09:45:15 +0100 Subject: [PATCH 08/13] fix: minor fix --- src/pages/home/report/ReportTypingIndicator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportTypingIndicator.js b/src/pages/home/report/ReportTypingIndicator.js index 6c6531955115..03d04f947f39 100755 --- a/src/pages/home/report/ReportTypingIndicator.js +++ b/src/pages/home/report/ReportTypingIndicator.js @@ -38,7 +38,7 @@ function ReportTypingIndicator({userTypingStatuses}) { return null; } - // 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) const firstUserTypingDisplayName = ReportUtils.getDisplayNameForParticipant(firstUserTypingID, false, false) || firstUserTyping; if (usersTyping.length === 1) { From e6ed623ea26306a6bc7c76f9ca61822acdaf8fd9 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Wed, 6 Dec 2023 10:31:24 +0100 Subject: [PATCH 09/13] fix: display name that should be hidden as someone --- src/pages/home/report/ReportTypingIndicator.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pages/home/report/ReportTypingIndicator.js b/src/pages/home/report/ReportTypingIndicator.js index 03d04f947f39..dc3bc98e0c78 100755 --- a/src/pages/home/report/ReportTypingIndicator.js +++ b/src/pages/home/report/ReportTypingIndicator.js @@ -27,10 +27,11 @@ function ReportTypingIndicator({userTypingStatuses}) { const styles = useThemeStyles(); const usersTyping = useMemo(() => _.filter(_.keys(userTypingStatuses), (loginOrAccountID) => userTypingStatuses[loginOrAccountID]), [userTypingStatuses]); const firstUserTyping = usersTyping[0]; + const isUserTypingADisplayName = Number.isNaN(Number(firstUserTyping)) const firstUserTypingID = useMemo( - () => (firstUserTyping && Number.isNaN(Number(firstUserTyping)) ? PersonalDetailsUtils.getAccountIDsByLogins([firstUserTyping])[0] : firstUserTyping), - [firstUserTyping], + () => (firstUserTyping && isUserTypingADisplayName ? PersonalDetailsUtils.getAccountIDsByLogins([firstUserTyping])[0] : firstUserTyping), + [firstUserTyping, isUserTypingADisplayName], ); // If we are offline, the user typing statuses are not up-to-date so do not show them @@ -39,7 +40,7 @@ function ReportTypingIndicator({userTypingStatuses}) { } // If the user is typing on OldDot, firstUserTyping will be a string (the user's displayName) - const firstUserTypingDisplayName = ReportUtils.getDisplayNameForParticipant(firstUserTypingID, false, false) || firstUserTyping; + const firstUserTypingDisplayName = isUserTypingADisplayName ? firstUserTyping : ReportUtils.getDisplayNameForParticipant(firstUserTypingID, false, false); if (usersTyping.length === 1) { return ( From e186fd3a15fe08861d5bdfbf7b9dbaf02a046eda Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Wed, 6 Dec 2023 10:36:20 +0100 Subject: [PATCH 10/13] fix: run prettier --- src/pages/home/report/ReportTypingIndicator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportTypingIndicator.js b/src/pages/home/report/ReportTypingIndicator.js index dc3bc98e0c78..b289d87f2fd1 100755 --- a/src/pages/home/report/ReportTypingIndicator.js +++ b/src/pages/home/report/ReportTypingIndicator.js @@ -27,7 +27,7 @@ function ReportTypingIndicator({userTypingStatuses}) { const styles = useThemeStyles(); const usersTyping = useMemo(() => _.filter(_.keys(userTypingStatuses), (loginOrAccountID) => userTypingStatuses[loginOrAccountID]), [userTypingStatuses]); const firstUserTyping = usersTyping[0]; - const isUserTypingADisplayName = Number.isNaN(Number(firstUserTyping)) + const isUserTypingADisplayName = Number.isNaN(Number(firstUserTyping)); const firstUserTypingID = useMemo( () => (firstUserTyping && isUserTypingADisplayName ? PersonalDetailsUtils.getAccountIDsByLogins([firstUserTyping])[0] : firstUserTyping), From 69ba3a09618283cbaf6d50602dc37e5e148e6c99 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Mon, 18 Dec 2023 16:39:34 +0100 Subject: [PATCH 11/13] fix: prettier --- src/pages/home/report/ReportTypingIndicator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportTypingIndicator.js b/src/pages/home/report/ReportTypingIndicator.js index 8bc7887c062c..8b91999d1612 100755 --- a/src/pages/home/report/ReportTypingIndicator.js +++ b/src/pages/home/report/ReportTypingIndicator.js @@ -6,9 +6,9 @@ import Text from '@components/Text'; import TextWithEllipsis from '@components/TextWithEllipsis'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; +import useThemeStyles from '@hooks/useThemeStyles'; import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; import * as ReportUtils from '@libs/ReportUtils'; -import useThemeStyles from '@hooks/useThemeStyles'; import ONYXKEYS from '@src/ONYXKEYS'; const propTypes = { From 10f49fa805974407a928ec72ff35a097d1396615 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Fri, 29 Dec 2023 11:51:59 +0100 Subject: [PATCH 12/13] fix: do not check for login if is present in personalDetails --- src/pages/home/report/ReportTypingIndicator.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/pages/home/report/ReportTypingIndicator.js b/src/pages/home/report/ReportTypingIndicator.js index 8b91999d1612..622a257d0495 100755 --- a/src/pages/home/report/ReportTypingIndicator.js +++ b/src/pages/home/report/ReportTypingIndicator.js @@ -27,12 +27,8 @@ function ReportTypingIndicator({userTypingStatuses}) { const styles = useThemeStyles(); const usersTyping = useMemo(() => _.filter(_.keys(userTypingStatuses), (loginOrAccountID) => userTypingStatuses[loginOrAccountID]), [userTypingStatuses]); const firstUserTyping = usersTyping[0]; - const isUserTypingADisplayName = Number.isNaN(Number(firstUserTyping)); - const firstUserTypingID = useMemo( - () => (firstUserTyping && isUserTypingADisplayName ? PersonalDetailsUtils.getAccountIDsByLogins([firstUserTyping])[0] : firstUserTyping), - [firstUserTyping, isUserTypingADisplayName], - ); + const isUserTypingADisplayName = Number.isNaN(Number(firstUserTyping)); // If we are offline, the user typing statuses are not up-to-date so do not show them if (isOffline || !firstUserTyping) { @@ -40,7 +36,7 @@ function ReportTypingIndicator({userTypingStatuses}) { } // 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); + const firstUserTypingDisplayName = isUserTypingADisplayName ? firstUserTyping : ReportUtils.getDisplayNameForParticipant(Number(firstUserTyping), false, false); if (usersTyping.length === 1) { return ( From 1bab5a99f93432600b5efe06165b48bb6974db70 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Fri, 29 Dec 2023 16:19:34 +0100 Subject: [PATCH 13/13] fix: lint --- src/pages/home/report/ReportTypingIndicator.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/home/report/ReportTypingIndicator.js b/src/pages/home/report/ReportTypingIndicator.js index 622a257d0495..785f1e3f6a1e 100755 --- a/src/pages/home/report/ReportTypingIndicator.js +++ b/src/pages/home/report/ReportTypingIndicator.js @@ -7,7 +7,6 @@ import TextWithEllipsis from '@components/TextWithEllipsis'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import ONYXKEYS from '@src/ONYXKEYS';