From 32df987d9da1d0e91950ccde652e4f339b9bec6f Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Tue, 26 Sep 2023 07:07:48 +0800 Subject: [PATCH 01/15] update the design for group chats --- src/pages/ProfilePage.js | 14 ++ src/pages/ReportParticipantsPage.js | 149 +++++++++--------- .../Report/NotificationPreferencePage.js | 2 +- .../settings/Report/ReportSettingsPage.js | 2 +- 4 files changed, 93 insertions(+), 74 deletions(-) diff --git a/src/pages/ProfilePage.js b/src/pages/ProfilePage.js index 60037e4755c0..5e59384fea32 100755 --- a/src/pages/ProfilePage.js +++ b/src/pages/ProfilePage.js @@ -37,6 +37,7 @@ import variables from '../styles/variables'; import * as ValidationUtils from '../libs/ValidationUtils'; import Permissions from '../libs/Permissions'; import ROUTES from '../ROUTES'; +import MenuItemWithTopDescription from '../components/MenuItemWithTopDescription'; const matchType = PropTypes.shape({ params: PropTypes.shape({ @@ -136,6 +137,11 @@ function ProfilePage(props) { const chatReportWithCurrentUser = !isCurrentUser && !Session.isAnonymousUser() ? ReportUtils.getChatByParticipants([accountID]) : 0; + const notificationPreference = + chatReportWithCurrentUser.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN + ? props.translate(`notificationPreferencesPage.notificationPreferences.${chatReportWithCurrentUser.notificationPreference}`) + : ''; + // eslint-disable-next-line rulesdir/prefer-early-return useEffect(() => { if (ValidationUtils.isValidAccountRoute(accountID) && !hasMinimumDetails) { @@ -227,6 +233,14 @@ function ProfilePage(props) { ) : null} {shouldShowLocalTime && } + {chatReportWithCurrentUser.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN && ( + Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(chatReportWithCurrentUser.reportID))} + /> + )} {!isCurrentUser && !Session.isAnonymousUser() && ( { - let participantAccountIDs = report.participantAccountIDs; +function ReportParticipantsPage(props) { + const participants = useMemo(() => lodashGet(props.report, 'participantAccountIDs', []), [props.report]); + const isArchivedRoom = useMemo(() => ReportUtils.isArchivedRoom(props.report), [props.report]); + const participantAvatars = OptionsListUtils.getAvatarsForAccountIDs(participants, props.personalDetails); + const displayNamesWithTooltips = useMemo(() => { + const hasMultipleParticipants = participants.length > 1; + return ReportUtils.getDisplayNamesWithTooltips(OptionsListUtils.getPersonalDetailsForAccountIDs(participants, props.personalDetails), hasMultipleParticipants); + }, [participants, props.personalDetails]); + const menuItems = useMemo(() => { + const items = []; - // Build participants list for IOU report - there is a possibility that participantAccountIDs may be undefined/empty - if (ReportUtils.isIOUReport(report)) { - const managerID = report.managerID || ''; - const ownerAccountID = report.ownerAccountID || ''; - participantAccountIDs = [managerID, ownerAccountID]; - } + if (isArchivedRoom) { + return items; + } - return _.chain(participantAccountIDs) - .map((accountID, index) => { - const userPersonalDetail = lodashGet(personalDetails, accountID, {displayName: personalDetails.displayName || translate('common.hidden'), avatar: ''}); - const userLogin = LocalePhoneNumber.formatPhoneNumber(userPersonalDetail.login || '') || translate('common.hidden'); + if (participants.length) { + items.push({ + key: CONST.REPORT_DETAILS_MENU_ITEM.MEMBERS, + translationKey: 'common.members', + icon: Expensicons.Users, + subtitle: participants.length, + isAnonymousAction: false, + action: () => { + Navigation.navigate(ROUTES.REPORT_PARTICIPANTS.getRoute(props.report.reportID)); + }, + }); + } - return { - alternateText: userLogin, - displayName: userPersonalDetail.displayName, - accountID: userPersonalDetail.accountID, - icons: [ - { - id: accountID, - source: UserUtils.getAvatar(userPersonalDetail.avatar, accountID), - name: userLogin, - type: CONST.ICON_TYPE_AVATAR, - }, - ], - keyForList: `${index}-${userLogin}`, - login: userLogin, - text: userPersonalDetail.displayName, - tooltipText: userLogin, - participantsList: [{accountID, displayName: userPersonalDetail.displayName}], - }; - }) - .sortBy((participant) => participant.displayName.toLowerCase()) - .value(); -}; + items.push({ + key: CONST.REPORT_DETAILS_MENU_ITEM.SETTINGS, + translationKey: 'common.settings', + icon: Expensicons.Gear, + isAnonymousAction: false, + action: () => { + Navigation.navigate(ROUTES.REPORT_SETTINGS.getRoute(props.report.reportID)); + }, + }); -function ReportParticipantsPage(props) { - const participants = _.map(getAllParticipants(props.report, props.personalDetails, props.translate), (participant) => ({ - ...participant, - isDisabled: ReportUtils.isOptimisticPersonalDetail(participant.accountID), - })); + return items; + }, [props.report, participants, isArchivedRoom]); return ( - {({safeAreaPaddingBottomStyle}) => ( + {() => ( {Boolean(participants.length) && ( - { - Navigation.navigate(ROUTES.PROFILE.getRoute(option.accountID)); - }} - hideSectionHeaders - showTitleTooltip - showScrollIndicator - disableFocusOptions - boldStyle - optionHoveredStyle={styles.hoveredComponentBG} - contentContainerStyles={[safeAreaPaddingBottomStyle]} - /> + + + + + + )} + {_.map(menuItems, (item) => { + const brickRoadIndicator = + ReportUtils.hasReportNameError(props.report) && item.key === CONST.REPORT_DETAILS_MENU_ITEM.SETTINGS ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''; + return ( + + ); + })} )} diff --git a/src/pages/settings/Report/NotificationPreferencePage.js b/src/pages/settings/Report/NotificationPreferencePage.js index b6dbf5f42c83..0bc518c71942 100644 --- a/src/pages/settings/Report/NotificationPreferencePage.js +++ b/src/pages/settings/Report/NotificationPreferencePage.js @@ -26,7 +26,7 @@ const propTypes = { const greenCheckmark = {src: Expensicons.Checkmark, color: themeColors.success}; function NotificationPreferencePage(props) { - const shouldDisableNotificationPreferences = ReportUtils.shouldDisableSettings(props.report) || ReportUtils.isArchivedRoom(props.report); + const shouldDisableNotificationPreferences = ReportUtils.isArchivedRoom(props.report); const notificationPreferenceOptions = _.map( _.filter(_.values(CONST.REPORT.NOTIFICATION_PREFERENCE), (pref) => pref !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN), (preference) => ({ diff --git a/src/pages/settings/Report/ReportSettingsPage.js b/src/pages/settings/Report/ReportSettingsPage.js index 3db6bef16e30..2bfdec828668 100644 --- a/src/pages/settings/Report/ReportSettingsPage.js +++ b/src/pages/settings/Report/ReportSettingsPage.js @@ -63,7 +63,7 @@ function ReportSettingsPage(props) { const shouldDisableWelcomeMessage = ReportUtils.isArchivedRoom(report) || !ReportUtils.isChatRoom(report) || _.isEmpty(linkedWorkspace) || linkedWorkspace.role !== CONST.POLICY.ROLE.ADMIN; - const shouldDisableSettings = _.isEmpty(report) || ReportUtils.shouldDisableSettings(report) || ReportUtils.isArchivedRoom(report); + const shouldDisableSettings = _.isEmpty(report) || ReportUtils.isArchivedRoom(report); const shouldShowRoomName = !ReportUtils.isPolicyExpenseChat(report) && !ReportUtils.isChatThread(report); const notificationPreference = report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN From d122a0d47c8e4d37a4b53afb744431a61bca79ad Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Wed, 27 Sep 2023 08:16:34 +0800 Subject: [PATCH 02/15] fix profile page --- src/pages/ProfilePage.js | 7 ++++--- src/styles/utilities/spacing.ts | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/pages/ProfilePage.js b/src/pages/ProfilePage.js index 20f834cf8aae..1f2cca42dd88 100755 --- a/src/pages/ProfilePage.js +++ b/src/pages/ProfilePage.js @@ -236,15 +236,16 @@ function ProfilePage(props) { ) : null} {shouldShowLocalTime && } - {chatReportWithCurrentUser.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN && ( + + {chatReportWithCurrentUser.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN && ( Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(chatReportWithCurrentUser.reportID))} + wrapperStyle={[styles.mtn6, styles.mb5]} /> - )} - + )} {!isCurrentUser && !Session.isAnonymousUser() && ( Date: Wed, 27 Sep 2023 08:31:04 +0800 Subject: [PATCH 03/15] updated details page to also count for group chats --- src/libs/ReportUtils.js | 17 +--- src/pages/ReportDetailsPage.js | 19 ++-- src/pages/ReportParticipantsPage.js | 151 ++++++++++++++-------------- 3 files changed, 85 insertions(+), 102 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 475c1a8bcb8a..953354ece3e4 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1846,15 +1846,11 @@ function getParentNavigationSubtitle(report) { function navigateToDetailsPage(report) { const participantAccountIDs = lodashGet(report, 'participantAccountIDs', []); - if (isChatRoom(report) || isPolicyExpenseChat(report) || isChatThread(report) || isTaskReport(report)) { - Navigation.navigate(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report.reportID)); - return; - } - if (participantAccountIDs.length === 1) { + if (isDM(report) && participantAccountIDs.length === 1) { Navigation.navigate(ROUTES.PROFILE.getRoute(participantAccountIDs[0])); return; } - Navigation.navigate(ROUTES.REPORT_PARTICIPANTS.getRoute(report.reportID)); + Navigation.navigate(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report.reportID)); } /** @@ -3458,14 +3454,6 @@ function getPolicyExpenseChatReportIDByOwner(policyOwner) { return expenseChat.reportID; } -/* - * @param {Object|null} report - * @returns {Boolean} - */ -function shouldDisableSettings(report) { - return !isPolicyExpenseChat(report) && !isChatRoom(report) && !isChatThread(report); -} - /** * @param {Object|null} report * @param {Object|null} policy - the workspace the report is on, null if the user isn't a member of the workspace @@ -3791,7 +3779,6 @@ export { isDM, getPolicy, getPolicyExpenseChatReportIDByOwner, - shouldDisableSettings, shouldDisableRename, hasSingleParticipant, getReportRecipientAccountIDs, diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index 98dae2e94780..e70ab52c3d63 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -60,8 +60,7 @@ const defaultProps = { function ReportDetailsPage(props) { const policy = useMemo(() => props.policies[`${ONYXKEYS.COLLECTION.POLICY}${props.report.policyID}`], [props.policies, props.report.policyID]); const isPolicyAdmin = useMemo(() => PolicyUtils.isPolicyAdmin(policy), [policy]); - const shouldDisableSettings = useMemo(() => ReportUtils.shouldDisableSettings(props.report), [props.report]); - const shouldUseFullTitle = !shouldDisableSettings || ReportUtils.isTaskReport(props.report); + const shouldUseFullTitle = ReportUtils.isTaskReport(props.report); const isChatRoom = useMemo(() => ReportUtils.isChatRoom(props.report), [props.report]); const isThread = useMemo(() => ReportUtils.isChatThread(props.report), [props.report]); const isUserCreatedPolicyRoom = useMemo(() => ReportUtils.isUserCreatedPolicyRoom(props.report), [props.report]); @@ -72,16 +71,20 @@ function ReportDetailsPage(props) { const canLeaveRoom = useMemo(() => ReportUtils.canLeaveRoom(props.report, !_.isEmpty(policy)), [policy, props.report]); const participants = useMemo(() => lodashGet(props.report, 'participantAccountIDs', []), [props.report]); + const isGroupDMChat = useMemo(() => ReportUtils.isDM(props.report) && participants.length > 1, [props.report, participants.length]); + const menuItems = useMemo(() => { - const items = [ - { + const items = []; + + if (!isGroupDMChat) { + items.push({ key: CONST.REPORT_DETAILS_MENU_ITEM.SHARE_CODE, translationKey: 'common.shareCode', icon: Expensicons.QrCode, isAnonymousAction: true, action: () => Navigation.navigate(ROUTES.REPORT_WITH_ID_DETAILS_SHARE_CODE.getRoute(props.report.reportID)), - }, - ]; + }); + } if (isArchivedRoom) { return items; @@ -100,7 +103,6 @@ function ReportDetailsPage(props) { }); } - if (!shouldDisableSettings) { items.push({ key: CONST.REPORT_DETAILS_MENU_ITEM.SETTINGS, translationKey: 'common.settings', @@ -110,7 +112,6 @@ function ReportDetailsPage(props) { Navigation.navigate(ROUTES.REPORT_SETTINGS.getRoute(props.report.reportID)); }, }); - } // Prevent displaying private notes option for threads and task reports if (!isThread && !ReportUtils.isTaskReport(props.report)) { @@ -135,7 +136,7 @@ function ReportDetailsPage(props) { } return items; - }, [props.report, participants, isArchivedRoom, shouldDisableSettings, isThread, isUserCreatedPolicyRoom, canLeaveRoom]); + }, [props.report, participants, isArchivedRoom, isThread, isUserCreatedPolicyRoom, canLeaveRoom, isGroupDMChat]); const displayNamesWithTooltips = useMemo(() => { const hasMultipleParticipants = participants.length > 1; diff --git a/src/pages/ReportParticipantsPage.js b/src/pages/ReportParticipantsPage.js index 1606615270f9..7465916e95bd 100755 --- a/src/pages/ReportParticipantsPage.js +++ b/src/pages/ReportParticipantsPage.js @@ -1,4 +1,4 @@ -import React, {useMemo} from 'react'; +import React from 'react'; import _ from 'underscore'; import {View} from 'react-native'; import PropTypes from 'prop-types'; @@ -9,6 +9,7 @@ import ONYXKEYS from '../ONYXKEYS'; import HeaderWithBackButton from '../components/HeaderWithBackButton'; import Navigation from '../libs/Navigation/Navigation'; import ScreenWrapper from '../components/ScreenWrapper'; +import OptionsList from '../components/OptionsList'; import ROUTES from '../ROUTES'; import personalDetailsPropType from './personalDetailsPropType'; import withLocalize, {withLocalizePropTypes} from '../components/withLocalize'; @@ -18,11 +19,8 @@ import reportPropTypes from './reportPropTypes'; import withReportOrNotFound from './home/report/withReportOrNotFound'; import FullPageNotFoundView from '../components/BlockingViews/FullPageNotFoundView'; import CONST from '../CONST'; -import * as OptionsListUtils from '../libs/OptionsListUtils'; -import * as Expensicons from '../components/Icon/Expensicons'; -import MultipleAvatars from '../components/MultipleAvatars'; -import DisplayNames from '../components/DisplayNames'; -import MenuItem from '../components/MenuItem'; +import * as UserUtils from '../libs/UserUtils'; +import * as LocalePhoneNumber from '../libs/LocalePhoneNumber'; const propTypes = { /* Onyx Props */ @@ -48,53 +46,64 @@ const defaultProps = { personalDetails: {}, }; -function ReportParticipantsPage(props) { - const participants = useMemo(() => lodashGet(props.report, 'participantAccountIDs', []), [props.report]); - const isArchivedRoom = useMemo(() => ReportUtils.isArchivedRoom(props.report), [props.report]); - const participantAvatars = OptionsListUtils.getAvatarsForAccountIDs(participants, props.personalDetails); - const displayNamesWithTooltips = useMemo(() => { - const hasMultipleParticipants = participants.length > 1; - return ReportUtils.getDisplayNamesWithTooltips(OptionsListUtils.getPersonalDetailsForAccountIDs(participants, props.personalDetails), hasMultipleParticipants); - }, [participants, props.personalDetails]); - const menuItems = useMemo(() => { - const items = []; +/** + * Returns all the participants in the active report + * + * @param {Object} report The active report object + * @param {Object} personalDetails The personal details of the users + * @param {Object} translate The localize + * @return {Array} + */ +const getAllParticipants = (report, personalDetails, translate) => { + let participantAccountIDs = report.participantAccountIDs; - if (isArchivedRoom) { - return items; - } + // Build participants list for IOU report - there is a possibility that participantAccountIDs may be undefined/empty + if (ReportUtils.isIOUReport(report)) { + const managerID = report.managerID || ''; + const ownerAccountID = report.ownerAccountID || ''; + participantAccountIDs = [managerID, ownerAccountID]; + } - if (participants.length) { - items.push({ - key: CONST.REPORT_DETAILS_MENU_ITEM.MEMBERS, - translationKey: 'common.members', - icon: Expensicons.Users, - subtitle: participants.length, - isAnonymousAction: false, - action: () => { - Navigation.navigate(ROUTES.REPORT_PARTICIPANTS.getRoute(props.report.reportID)); - }, - }); - } + return _.chain(participantAccountIDs) + .map((accountID, index) => { + const userPersonalDetail = lodashGet(personalDetails, accountID, {displayName: personalDetails.displayName || translate('common.hidden'), avatar: ''}); + const userLogin = LocalePhoneNumber.formatPhoneNumber(userPersonalDetail.login || '') || translate('common.hidden'); - items.push({ - key: CONST.REPORT_DETAILS_MENU_ITEM.SETTINGS, - translationKey: 'common.settings', - icon: Expensicons.Gear, - isAnonymousAction: false, - action: () => { - Navigation.navigate(ROUTES.REPORT_SETTINGS.getRoute(props.report.reportID)); - }, - }); + return { + alternateText: userLogin, + displayName: userPersonalDetail.displayName, + accountID: userPersonalDetail.accountID, + icons: [ + { + id: accountID, + source: UserUtils.getAvatar(userPersonalDetail.avatar, accountID), + name: userLogin, + type: CONST.ICON_TYPE_AVATAR, + }, + ], + keyForList: `${index}-${userLogin}`, + login: userLogin, + text: userPersonalDetail.displayName, + tooltipText: userLogin, + participantsList: [{accountID, displayName: userPersonalDetail.displayName}], + }; + }) + .sortBy((participant) => participant.displayName.toLowerCase()) + .value(); +}; - return items; - }, [props.report, participants, isArchivedRoom]); +function ReportParticipantsPage(props) { + const participants = _.map(getAllParticipants(props.report, props.personalDetails, props.translate), (participant) => ({ + ...participant, + isDisabled: ReportUtils.isOptimisticPersonalDetail(participant.accountID), + })); return ( - {() => ( + {({safeAreaPaddingBottomStyle}) => ( {Boolean(participants.length) && ( - - - - - - + { + Navigation.navigate(ROUTES.PROFILE.getRoute(option.accountID)); + }} + hideSectionHeaders + showTitleTooltip + showScrollIndicator + disableFocusOptions + boldStyle + optionHoveredStyle={styles.hoveredComponentBG} + contentContainerStyles={[safeAreaPaddingBottomStyle]} + /> )} - {_.map(menuItems, (item) => { - const brickRoadIndicator = - ReportUtils.hasReportNameError(props.report) && item.key === CONST.REPORT_DETAILS_MENU_ITEM.SETTINGS ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''; - return ( - - ); - })} )} @@ -165,4 +160,4 @@ export default compose( key: ONYXKEYS.PERSONAL_DETAILS_LIST, }, }), -)(ReportParticipantsPage); +)(ReportParticipantsPage); \ No newline at end of file From cf820414984a2a81da1fbd2a257ca89bc488131b Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Wed, 27 Sep 2023 08:53:54 +0800 Subject: [PATCH 04/15] fix the spacing --- src/pages/ReportParticipantsPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ReportParticipantsPage.js b/src/pages/ReportParticipantsPage.js index 7465916e95bd..7f453d16817b 100755 --- a/src/pages/ReportParticipantsPage.js +++ b/src/pages/ReportParticipantsPage.js @@ -160,4 +160,4 @@ export default compose( key: ONYXKEYS.PERSONAL_DETAILS_LIST, }, }), -)(ReportParticipantsPage); \ No newline at end of file +)(ReportParticipantsPage); From 083c924eb8d8fc2322d2b65d71d8b1ccaf896453 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Wed, 27 Sep 2023 09:06:28 +0800 Subject: [PATCH 05/15] use prettier --- src/pages/ProfilePage.js | 14 +++++++------- src/pages/ReportDetailsPage.js | 18 +++++++++--------- src/styles/utilities/spacing.ts | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/pages/ProfilePage.js b/src/pages/ProfilePage.js index 1f2cca42dd88..c21c3b74305a 100755 --- a/src/pages/ProfilePage.js +++ b/src/pages/ProfilePage.js @@ -238,13 +238,13 @@ function ProfilePage(props) { {shouldShowLocalTime && } {chatReportWithCurrentUser.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN && ( - Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(chatReportWithCurrentUser.reportID))} - wrapperStyle={[styles.mtn6, styles.mb5]} - /> + Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(chatReportWithCurrentUser.reportID))} + wrapperStyle={[styles.mtn6, styles.mb5]} + /> )} {!isCurrentUser && !Session.isAnonymousUser() && ( { - Navigation.navigate(ROUTES.REPORT_SETTINGS.getRoute(props.report.reportID)); - }, - }); + items.push({ + key: CONST.REPORT_DETAILS_MENU_ITEM.SETTINGS, + translationKey: 'common.settings', + icon: Expensicons.Gear, + isAnonymousAction: false, + action: () => { + Navigation.navigate(ROUTES.REPORT_SETTINGS.getRoute(props.report.reportID)); + }, + }); // Prevent displaying private notes option for threads and task reports if (!isThread && !ReportUtils.isTaskReport(props.report)) { diff --git a/src/styles/utilities/spacing.ts b/src/styles/utilities/spacing.ts index dba4274784cd..5190af8dbd9c 100644 --- a/src/styles/utilities/spacing.ts +++ b/src/styles/utilities/spacing.ts @@ -203,7 +203,7 @@ export default { marginTop: 'auto', }, - mtn6 : { + mtn6: { marginTop: -24, }, From 994140dc100a33ca0e3fbfd5385203849436d500 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Wed, 27 Sep 2023 15:38:03 +0800 Subject: [PATCH 06/15] get chat report for profile page --- src/pages/ProfilePage.js | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/pages/ProfilePage.js b/src/pages/ProfilePage.js index c21c3b74305a..221f5cb76b69 100755 --- a/src/pages/ProfilePage.js +++ b/src/pages/ProfilePage.js @@ -136,12 +136,7 @@ function ProfilePage(props) { const navigateBackTo = lodashGet(props.route, 'params.backTo', ROUTES.HOME); - const chatReportWithCurrentUser = !isCurrentUser && !Session.isAnonymousUser() ? ReportUtils.getChatByParticipants([accountID]) : 0; - - const notificationPreference = - chatReportWithCurrentUser.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN - ? props.translate(`notificationPreferencesPage.notificationPreferences.${chatReportWithCurrentUser.notificationPreference}`) - : ''; + const notificationPreference = !_.isEmpty(props.report) ? props.translate(`notificationPreferencesPage.notificationPreferences.${props.report.notificationPreference}`) : ''; // eslint-disable-next-line rulesdir/prefer-early-return useEffect(() => { @@ -237,12 +232,12 @@ function ProfilePage(props) { ) : null} {shouldShowLocalTime && } - {chatReportWithCurrentUser.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN && ( + {notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN && !isCurrentUser && ( Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(chatReportWithCurrentUser.reportID))} + onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(props.report.reportID))} wrapperStyle={[styles.mtn6, styles.mb5]} /> )} @@ -256,15 +251,15 @@ function ProfilePage(props) { shouldShowRightIcon /> )} - {!_.isEmpty(chatReportWithCurrentUser) && ( + {!_.isEmpty(props.report) && ( Navigation.navigate(ROUTES.PRIVATE_NOTES_LIST.getRoute(chatReportWithCurrentUser.reportID))} + onPress={() => Navigation.navigate(ROUTES.PRIVATE_NOTES_LIST.getRoute(props.report.reportID))} wrapperStyle={styles.breakAll} shouldShowRightIcon - brickRoadIndicator={Report.hasErrorInPrivateNotes(chatReportWithCurrentUser) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''} + brickRoadIndicator={Report.hasErrorInPrivateNotes(props.report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''} /> )} @@ -304,5 +299,20 @@ export default compose( betas: { key: ONYXKEYS.BETAS, }, + session: { + key: ONYXKEYS.SESSION, + }, + }), + // eslint-disable-next-line rulesdir/no-multiple-onyx-in-file + withOnyx({ + report: { + key: ({route, session}) => { + const accountID = Number(lodashGet(route.params, 'accountID', 0)); + if (Number(session.accountID) === accountID || Session.isAnonymousUser()) { + return null; + } + return `${ONYXKEYS.COLLECTION.REPORT}${lodashGet(ReportUtils.getChatByParticipants([accountID]), 'reportID', '')}`; + }, + }, }), )(ProfilePage); From 89fc4ae1b44100d39a24670653efd03580e92af4 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Wed, 4 Oct 2023 20:49:59 +0530 Subject: [PATCH 07/15] revert the double withonyx change --- src/pages/ProfilePage.js | 24 +++++------------------- src/pages/ReportDetailsPage.js | 2 +- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/pages/ProfilePage.js b/src/pages/ProfilePage.js index 221f5cb76b69..7213cdcb3a3c 100755 --- a/src/pages/ProfilePage.js +++ b/src/pages/ProfilePage.js @@ -136,7 +136,8 @@ function ProfilePage(props) { const navigateBackTo = lodashGet(props.route, 'params.backTo', ROUTES.HOME); - const notificationPreference = !_.isEmpty(props.report) ? props.translate(`notificationPreferencesPage.notificationPreferences.${props.report.notificationPreference}`) : ''; + const chatReportWithCurrentUser = !isCurrentUser && !Session.isAnonymousUser() ? ReportUtils.getChatByParticipants([accountID]) : {}; + const notificationPreference = lodashGet(chatReportWithCurrentUser, 'notificationPreference', ''); // eslint-disable-next-line rulesdir/prefer-early-return useEffect(() => { @@ -251,15 +252,15 @@ function ProfilePage(props) { shouldShowRightIcon /> )} - {!_.isEmpty(props.report) && ( + {!_.isEmpty(chatReportWithCurrentUser) && ( Navigation.navigate(ROUTES.PRIVATE_NOTES_LIST.getRoute(props.report.reportID))} + onPress={() => Navigation.navigate(ROUTES.PRIVATE_NOTES_LIST.getRoute(chatReportWithCurrentUser.reportID))} wrapperStyle={styles.breakAll} shouldShowRightIcon - brickRoadIndicator={Report.hasErrorInPrivateNotes(props.report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''} + brickRoadIndicator={Report.hasErrorInPrivateNotes(chatReportWithCurrentUser) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''} /> )} @@ -299,20 +300,5 @@ export default compose( betas: { key: ONYXKEYS.BETAS, }, - session: { - key: ONYXKEYS.SESSION, - }, - }), - // eslint-disable-next-line rulesdir/no-multiple-onyx-in-file - withOnyx({ - report: { - key: ({route, session}) => { - const accountID = Number(lodashGet(route.params, 'accountID', 0)); - if (Number(session.accountID) === accountID || Session.isAnonymousUser()) { - return null; - } - return `${ONYXKEYS.COLLECTION.REPORT}${lodashGet(ReportUtils.getChatByParticipants([accountID]), 'reportID', '')}`; - }, - }, }), )(ProfilePage); diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index c65aff1fc1c8..42a535844c72 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -139,7 +139,7 @@ function ReportDetailsPage(props) { } return items; - }, [isArchivedRoom, participants.length, shouldDisableSettings, isThread, isMoneyRequestReport, props.report, isUserCreatedPolicyRoom, canLeaveRoom, isGroupDMChat]); + }, [isArchivedRoom, participants.length, isThread, isMoneyRequestReport, props.report, isUserCreatedPolicyRoom, canLeaveRoom, isGroupDMChat]); const displayNamesWithTooltips = useMemo(() => { const hasMultipleParticipants = participants.length > 1; From 491e044fa2c0a97bf7d8713205d3acbebbd6ec95 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Wed, 4 Oct 2023 21:05:16 +0530 Subject: [PATCH 08/15] fix the report --- src/pages/ProfilePage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ProfilePage.js b/src/pages/ProfilePage.js index 7213cdcb3a3c..adf9b35f16f9 100755 --- a/src/pages/ProfilePage.js +++ b/src/pages/ProfilePage.js @@ -238,7 +238,7 @@ function ProfilePage(props) { shouldShowRightIcon title={notificationPreference} description={props.translate('notificationPreferencesPage.label')} - onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(props.report.reportID))} + onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(chatReportWithCurrentUser.reportID))} wrapperStyle={[styles.mtn6, styles.mb5]} /> )} From f050e20fe30dd12a3137dadab0e1ce8a43741a88 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Wed, 4 Oct 2023 21:45:13 +0530 Subject: [PATCH 09/15] use the display name property --- .../Notification/LocalNotification/BrowserNotifications.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/Notification/LocalNotification/BrowserNotifications.js b/src/libs/Notification/LocalNotification/BrowserNotifications.js index ca2cfc73866d..69c13e3e6b82 100644 --- a/src/libs/Notification/LocalNotification/BrowserNotifications.js +++ b/src/libs/Notification/LocalNotification/BrowserNotifications.js @@ -111,7 +111,7 @@ export default { const plainTextMessage = (_.find(message, (f) => f.type === 'COMMENT') || {}).text; if (isChatRoom) { - const roomName = _.get(report, 'displayName', ''); + const roomName = _.get(report, 'roomName', ''); title = roomName; body = `${plainTextPerson}: ${plainTextMessage}`; } else { @@ -120,7 +120,7 @@ export default { } push({ - title, + title: 'Title 1', body, delay: 0, onClick, From d21f21c9bddce0d7ee3768fd5492f753a2640f41 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Wed, 4 Oct 2023 21:54:45 +0530 Subject: [PATCH 10/15] get rid of default value --- src/libs/Notification/LocalNotification/BrowserNotifications.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Notification/LocalNotification/BrowserNotifications.js b/src/libs/Notification/LocalNotification/BrowserNotifications.js index 69c13e3e6b82..fb73d2f60b77 100644 --- a/src/libs/Notification/LocalNotification/BrowserNotifications.js +++ b/src/libs/Notification/LocalNotification/BrowserNotifications.js @@ -120,7 +120,7 @@ export default { } push({ - title: 'Title 1', + title, body, delay: 0, onClick, From 3c880c6e6ecd6ce1dc1782481bc6a57e08966730 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Wed, 4 Oct 2023 21:59:08 +0530 Subject: [PATCH 11/15] don't show notification option if not chatted before --- src/pages/ProfilePage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ProfilePage.js b/src/pages/ProfilePage.js index adf9b35f16f9..f538f500086a 100755 --- a/src/pages/ProfilePage.js +++ b/src/pages/ProfilePage.js @@ -233,7 +233,7 @@ function ProfilePage(props) { ) : null} {shouldShowLocalTime && } - {notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN && !isCurrentUser && ( + {chatReportWithCurrentUser && notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN && !isCurrentUser && ( Date: Wed, 4 Oct 2023 22:37:32 +0530 Subject: [PATCH 12/15] use getReportName method --- src/libs/Notification/LocalNotification/BrowserNotifications.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Notification/LocalNotification/BrowserNotifications.js b/src/libs/Notification/LocalNotification/BrowserNotifications.js index fb73d2f60b77..3199e4c6388d 100644 --- a/src/libs/Notification/LocalNotification/BrowserNotifications.js +++ b/src/libs/Notification/LocalNotification/BrowserNotifications.js @@ -111,7 +111,7 @@ export default { const plainTextMessage = (_.find(message, (f) => f.type === 'COMMENT') || {}).text; if (isChatRoom) { - const roomName = _.get(report, 'roomName', ''); + const roomName = ReportUtils.getReportName(report); title = roomName; body = `${plainTextPerson}: ${plainTextMessage}`; } else { From 626ec91ffe335fda59fdc1be29a7343122280d05 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Thu, 5 Oct 2023 22:33:14 +0530 Subject: [PATCH 13/15] Revert "revert the double withonyx change" This reverts commit 89fc4ae1b44100d39a24670653efd03580e92af4. --- src/pages/ProfilePage.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/pages/ProfilePage.js b/src/pages/ProfilePage.js index f538f500086a..8f97387d60b6 100755 --- a/src/pages/ProfilePage.js +++ b/src/pages/ProfilePage.js @@ -136,8 +136,7 @@ function ProfilePage(props) { const navigateBackTo = lodashGet(props.route, 'params.backTo', ROUTES.HOME); - const chatReportWithCurrentUser = !isCurrentUser && !Session.isAnonymousUser() ? ReportUtils.getChatByParticipants([accountID]) : {}; - const notificationPreference = lodashGet(chatReportWithCurrentUser, 'notificationPreference', ''); + const notificationPreference = !_.isEmpty(props.report) ? props.translate(`notificationPreferencesPage.notificationPreferences.${props.report.notificationPreference}`) : ''; // eslint-disable-next-line rulesdir/prefer-early-return useEffect(() => { @@ -252,15 +251,15 @@ function ProfilePage(props) { shouldShowRightIcon /> )} - {!_.isEmpty(chatReportWithCurrentUser) && ( + {!_.isEmpty(props.report) && ( Navigation.navigate(ROUTES.PRIVATE_NOTES_LIST.getRoute(chatReportWithCurrentUser.reportID))} + onPress={() => Navigation.navigate(ROUTES.PRIVATE_NOTES_LIST.getRoute(props.report.reportID))} wrapperStyle={styles.breakAll} shouldShowRightIcon - brickRoadIndicator={Report.hasErrorInPrivateNotes(chatReportWithCurrentUser) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''} + brickRoadIndicator={Report.hasErrorInPrivateNotes(props.report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''} /> )} @@ -300,5 +299,20 @@ export default compose( betas: { key: ONYXKEYS.BETAS, }, + session: { + key: ONYXKEYS.SESSION, + }, + }), + // eslint-disable-next-line rulesdir/no-multiple-onyx-in-file + withOnyx({ + report: { + key: ({route, session}) => { + const accountID = Number(lodashGet(route.params, 'accountID', 0)); + if (Number(session.accountID) === accountID || Session.isAnonymousUser()) { + return null; + } + return `${ONYXKEYS.COLLECTION.REPORT}${lodashGet(ReportUtils.getChatByParticipants([accountID]), 'reportID', '')}`; + }, + }, }), )(ProfilePage); From 4417b5cbf38936538c6508c29c1fb899fb484720 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Thu, 5 Oct 2023 22:44:18 +0530 Subject: [PATCH 14/15] fix showing notification preference --- src/pages/ProfilePage.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/ProfilePage.js b/src/pages/ProfilePage.js index 8f97387d60b6..ff99cf190739 100755 --- a/src/pages/ProfilePage.js +++ b/src/pages/ProfilePage.js @@ -232,12 +232,12 @@ function ProfilePage(props) { ) : null} {shouldShowLocalTime && } - {chatReportWithCurrentUser && notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN && !isCurrentUser && ( + {!_.isEmpty(props.reportID) && notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN && ( Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(chatReportWithCurrentUser.reportID))} + onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(props.reportID))} wrapperStyle={[styles.mtn6, styles.mb5]} /> )} From b8a66ed763728a9e1b5c782fc9d5e6dbaab44177 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Thu, 5 Oct 2023 23:12:55 +0530 Subject: [PATCH 15/15] use correct property name --- src/pages/ProfilePage.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/ProfilePage.js b/src/pages/ProfilePage.js index ff99cf190739..b51671341e40 100755 --- a/src/pages/ProfilePage.js +++ b/src/pages/ProfilePage.js @@ -232,12 +232,12 @@ function ProfilePage(props) { ) : null} {shouldShowLocalTime && } - {!_.isEmpty(props.reportID) && notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN && ( + {!_.isEmpty(props.report) && notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN && ( Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(props.reportID))} + onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(props.report.reportID))} wrapperStyle={[styles.mtn6, styles.mb5]} /> )}