From 7ce22422688c7a8dc0329f2969fa9fc42589cc02 Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Fri, 3 May 2024 19:43:18 +0500 Subject: [PATCH 01/30] enable view photo for group chat --- src/pages/ReportAvatar.tsx | 8 ++++---- src/pages/ReportDetailsPage.tsx | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index 121b238012bf..ec24ac6b4d46 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -22,12 +22,12 @@ type ReportAvatarProps = ReportAvatarOnyxProps & StackScreenProps { @@ -35,7 +35,7 @@ function ReportAvatar({report = {} as Report, policies, isLoadingApp = true}: Re }} isWorkspaceAvatar maybeIcon - originalFileName={policy?.originalFileName ?? policyName} + originalFileName={policy?.originalFileName ?? title} shouldShowNotFoundPage={!report?.reportID && !isLoadingApp} isLoading={(!report?.reportID || !policy?.id) && !!isLoadingApp} /> diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index fa939be4e63d..c88aaa45400c 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -237,7 +237,6 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD isUsingDefaultAvatar={!report.avatarUrl} size={CONST.AVATAR_SIZE.XLARGE} avatarStyle={styles.avatarXLarge} - shouldDisableViewPhoto onImageRemoved={() => { // Calling this without a file will remove the avatar Report.updateGroupChatAvatar(report.reportID ?? ''); @@ -249,6 +248,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD errors={report.errorFields?.avatar ?? null} errorRowStyles={styles.mt6} onErrorClose={() => Report.clearAvatarErrors(report.reportID ?? '')} + onViewPhotoPress={() => Navigation.navigate(ROUTES.REPORT_AVATAR.getRoute(report.reportID))} /> ) : ( Date: Mon, 6 May 2024 19:29:59 +0500 Subject: [PATCH 02/30] create variable for filename --- src/pages/ReportAvatar.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index ec24ac6b4d46..d20396e0a308 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -24,6 +24,7 @@ function ReportAvatar({report = {} as Report, policies, isLoadingApp = true}: Re const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID ?? '0'}`]; const title = policy ? ReportUtils.getPolicyName(report, false, policy) : report?.reportName; const avatarURL = policy ? ReportUtils.getWorkspaceAvatar(report) : report?.avatarUrl; + const fileName = policy?.originalFileName ?? title; return ( From 5b6a7c62126a2ddcd27a6af70a4df6748fc025d9 Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Fri, 17 May 2024 15:39:53 +0500 Subject: [PATCH 03/30] add support for new chat view photo --- .../Attachments/AttachmentView/index.tsx | 9 +++++++++ src/pages/NewChatConfirmPage.tsx | 2 +- src/pages/ReportAvatar.tsx | 15 +++++++++++---- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/components/Attachments/AttachmentView/index.tsx b/src/components/Attachments/AttachmentView/index.tsx index 2685a5cef407..eb15ac5e12e5 100644 --- a/src/components/Attachments/AttachmentView/index.tsx +++ b/src/components/Attachments/AttachmentView/index.tsx @@ -186,6 +186,15 @@ function AttachmentView({ // We also check for numeric source since this is how static images (used for preview) are represented in RN. const isImage = typeof source === 'number' || (typeof source === 'string' && Str.isImage(source)); if (isImage || (file?.name && Str.isImage(file.name))) { + // We are appending .jpg to blob url in NewChatConfirmPage View Photo. + // This was added to surpass the above isImage condition as is it image but it does + // not have image extension hence the condition fails. + // Finally we need to remove that extension to load the image. + if(typeof source === 'string') { + const lastDotIndex = source.lastIndexOf("."); + source = source.slice(0, lastDotIndex); + } + if (imageError) { // AttachmentViewImage can't handle icon fallbacks, so we need to handle it here if (typeof fallbackSource === 'number' || typeof fallbackSource === 'function') { diff --git a/src/pages/NewChatConfirmPage.tsx b/src/pages/NewChatConfirmPage.tsx index f25233f9f568..1cc63cdaf87a 100644 --- a/src/pages/NewChatConfirmPage.tsx +++ b/src/pages/NewChatConfirmPage.tsx @@ -125,9 +125,9 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP }} size={CONST.AVATAR_SIZE.XLARGE} avatarStyle={styles.avatarXLarge} - shouldDisableViewPhoto editIcon={Expensicons.Camera} editIconStyle={styles.smallEditIconAccount} + onViewPhotoPress={() => Navigation.navigate(ROUTES.REPORT_AVATAR.getRoute(optimisticReportID.current))} /> ; isLoadingApp: OnyxEntry; policies: OnyxCollection; + groupChatDraft: OnyxEntry; }; type ReportAvatarProps = ReportAvatarOnyxProps & StackScreenProps; -function ReportAvatar({report = {} as Report, policies, isLoadingApp = true}: ReportAvatarProps) { +function ReportAvatar({report = {} as Report, policies, isLoadingApp = true, groupChatDraft}: ReportAvatarProps) { const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID ?? '0'}`]; const title = policy ? ReportUtils.getPolicyName(report, false, policy) : report?.reportName; - const avatarURL = policy ? ReportUtils.getWorkspaceAvatar(report) : report?.avatarUrl; + let avatarURL = policy ? ReportUtils.getWorkspaceAvatar(report) : report?.avatarUrl; + if(!avatarURL && groupChatDraft?.avatarUri) { + avatarURL = `${groupChatDraft.avatarUri}.jpg`; + } const fileName = policy?.originalFileName ?? title; return ( @@ -37,7 +41,7 @@ function ReportAvatar({report = {} as Report, policies, isLoadingApp = true}: Re isWorkspaceAvatar maybeIcon originalFileName={fileName} - shouldShowNotFoundPage={!report?.reportID && !isLoadingApp} + shouldShowNotFoundPage={!report?.reportID && !groupChatDraft && !isLoadingApp} isLoading={(!report?.reportID || !policy?.id) && !!isLoadingApp} /> ); @@ -55,4 +59,7 @@ export default withOnyx({ policies: { key: ONYXKEYS.COLLECTION.POLICY, }, + groupChatDraft: { + key: ONYXKEYS.NEW_GROUP_CHAT_DRAFT, + }, })(ReportAvatar); From 66d8edcbbfde3f4df259c5d2e87f2b241b2c02fd Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Mon, 20 May 2024 14:55:57 +0500 Subject: [PATCH 04/30] revert removing extension --- src/components/Attachments/AttachmentView/index.tsx | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/components/Attachments/AttachmentView/index.tsx b/src/components/Attachments/AttachmentView/index.tsx index eb15ac5e12e5..2685a5cef407 100644 --- a/src/components/Attachments/AttachmentView/index.tsx +++ b/src/components/Attachments/AttachmentView/index.tsx @@ -186,15 +186,6 @@ function AttachmentView({ // We also check for numeric source since this is how static images (used for preview) are represented in RN. const isImage = typeof source === 'number' || (typeof source === 'string' && Str.isImage(source)); if (isImage || (file?.name && Str.isImage(file.name))) { - // We are appending .jpg to blob url in NewChatConfirmPage View Photo. - // This was added to surpass the above isImage condition as is it image but it does - // not have image extension hence the condition fails. - // Finally we need to remove that extension to load the image. - if(typeof source === 'string') { - const lastDotIndex = source.lastIndexOf("."); - source = source.slice(0, lastDotIndex); - } - if (imageError) { // AttachmentViewImage can't handle icon fallbacks, so we need to handle it here if (typeof fallbackSource === 'number' || typeof fallbackSource === 'function') { From 7d122dac0427f879b38d3f09ac94e465ca00092d Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Mon, 20 May 2024 14:56:58 +0500 Subject: [PATCH 05/30] use file name for new group chat draft --- src/pages/NewChatConfirmPage.tsx | 4 ++-- src/pages/ReportAvatar.tsx | 8 +++++--- src/types/onyx/NewGroupChatDraft.ts | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/pages/NewChatConfirmPage.tsx b/src/pages/NewChatConfirmPage.tsx index 1cc63cdaf87a..f8bdd0dbabc3 100644 --- a/src/pages/NewChatConfirmPage.tsx +++ b/src/pages/NewChatConfirmPage.tsx @@ -117,11 +117,11 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP source={stashedLocalAvatarImage ?? ReportUtils.getDefaultGroupAvatar(optimisticReportID.current)} onImageSelected={(image) => { fileRef.current = image; - Report.setGroupDraft({avatarUri: image?.uri ?? ''}); + Report.setGroupDraft({avatarUri: image?.uri ?? '', originalFileName: image?.name}); }} onImageRemoved={() => { fileRef.current = undefined; - Report.setGroupDraft({avatarUri: null}); + Report.setGroupDraft({avatarUri: null, originalFileName: null}); }} size={CONST.AVATAR_SIZE.XLARGE} avatarStyle={styles.avatarXLarge} diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index 72d04be353d7..9a2902f719ee 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -25,10 +25,12 @@ function ReportAvatar({report = {} as Report, policies, isLoadingApp = true, gro const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID ?? '0'}`]; const title = policy ? ReportUtils.getPolicyName(report, false, policy) : report?.reportName; let avatarURL = policy ? ReportUtils.getWorkspaceAvatar(report) : report?.avatarUrl; - if(!avatarURL && groupChatDraft?.avatarUri) { - avatarURL = `${groupChatDraft.avatarUri}.jpg`; + let fileName = policy?.originalFileName ?? title; + + if (!avatarURL && groupChatDraft?.avatarUri && groupChatDraft?.originalFileName) { + avatarURL = groupChatDraft.avatarUri ?? null; + fileName = groupChatDraft.originalFileName ?? null; } - const fileName = policy?.originalFileName ?? title; return ( Date: Fri, 24 May 2024 00:22:21 +0500 Subject: [PATCH 06/30] add newGroupChat query param for report avatar --- src/ROUTES.ts | 2 +- src/libs/Navigation/types.ts | 1 + src/pages/NewChatConfirmPage.tsx | 2 +- src/pages/ReportAvatar.tsx | 20 +++++++++++++------- src/pages/ReportDetailsPage.tsx | 2 +- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 39a090635655..ee83fe53f2ff 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -213,7 +213,7 @@ const ROUTES = { }, REPORT_AVATAR: { route: 'r/:reportID/avatar', - getRoute: (reportID: string) => `r/${reportID}/avatar` as const, + getRoute: (reportID: string, newGroupChat: boolean) => `r/${reportID}/avatar?newGroupChat=${newGroupChat}` as const, }, EDIT_CURRENCY_REQUEST: { route: 'r/:threadReportID/edit/currency', diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index df707c5a7c7d..36ced140ae37 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -884,6 +884,7 @@ type AuthScreensParamList = SharedScreensParamList & { }; [SCREENS.REPORT_AVATAR]: { reportID: string; + newGroupChat: string }; [SCREENS.NOT_FOUND]: undefined; [NAVIGATORS.LEFT_MODAL_NAVIGATOR]: NavigatorScreenParams; diff --git a/src/pages/NewChatConfirmPage.tsx b/src/pages/NewChatConfirmPage.tsx index f8bdd0dbabc3..f15fb99e430e 100644 --- a/src/pages/NewChatConfirmPage.tsx +++ b/src/pages/NewChatConfirmPage.tsx @@ -127,7 +127,7 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP avatarStyle={styles.avatarXLarge} editIcon={Expensicons.Camera} editIconStyle={styles.smallEditIconAccount} - onViewPhotoPress={() => Navigation.navigate(ROUTES.REPORT_AVATAR.getRoute(optimisticReportID.current))} + onViewPhotoPress={() => Navigation.navigate(ROUTES.REPORT_AVATAR.getRoute(optimisticReportID.current, true))} /> ; -function ReportAvatar({report = {} as Report, policies, isLoadingApp = true, groupChatDraft}: ReportAvatarProps) { +function ReportAvatar({report = {} as Report, policies, isLoadingApp = true, groupChatDraft, route}: ReportAvatarProps) { const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID ?? '0'}`]; const title = policy ? ReportUtils.getPolicyName(report, false, policy) : report?.reportName; - let avatarURL = policy ? ReportUtils.getWorkspaceAvatar(report) : report?.avatarUrl; - let fileName = policy?.originalFileName ?? title; + let avatarURL = undefined; + let fileName = undefined; - if (!avatarURL && groupChatDraft?.avatarUri && groupChatDraft?.originalFileName) { - avatarURL = groupChatDraft.avatarUri ?? null; - fileName = groupChatDraft.originalFileName ?? null; + const shouldUseGroupChatDraft = route.params.newGroupChat === 'true'; + if(shouldUseGroupChatDraft) { + const [groupChatDraft] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT); + avatarURL = groupChatDraft?.avatarUri ?? undefined; + fileName = groupChatDraft?.originalFileName ?? undefined; + } + else { + avatarURL = policy ? ReportUtils.getWorkspaceAvatar(report) : report?.avatarUrl; + fileName = policy?.originalFileName ?? title; } return ( diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index 539f3d3bd228..dd9a6e5aa1a6 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -249,7 +249,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD errors={report.errorFields?.avatar ?? null} errorRowStyles={styles.mt6} onErrorClose={() => Report.clearAvatarErrors(report.reportID ?? '')} - onViewPhotoPress={() => Navigation.navigate(ROUTES.REPORT_AVATAR.getRoute(report.reportID))} + onViewPhotoPress={() => Navigation.navigate(ROUTES.REPORT_AVATAR.getRoute(report.reportID, false))} /> ) : ( Date: Fri, 24 May 2024 00:26:42 +0500 Subject: [PATCH 07/30] clean code --- src/pages/ReportAvatar.tsx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index b5e16094ecd8..121e92b5291e 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -10,26 +10,26 @@ import * as UserUtils from '@libs/UserUtils'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import type {NewGroupChatDraft, Policy, Report} from '@src/types/onyx'; +import type {Policy, Report} from '@src/types/onyx'; type ReportAvatarOnyxProps = { report: OnyxEntry; isLoadingApp: OnyxEntry; policies: OnyxCollection; - groupChatDraft: OnyxEntry; }; type ReportAvatarProps = ReportAvatarOnyxProps & StackScreenProps; -function ReportAvatar({report = {} as Report, policies, isLoadingApp = true, groupChatDraft, route}: ReportAvatarProps) { +function ReportAvatar({report = {} as Report, policies, isLoadingApp = true, route}: ReportAvatarProps) { const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID ?? '0'}`]; const title = policy ? ReportUtils.getPolicyName(report, false, policy) : report?.reportName; let avatarURL = undefined; let fileName = undefined; + let groupChatDraft; const shouldUseGroupChatDraft = route.params.newGroupChat === 'true'; if(shouldUseGroupChatDraft) { - const [groupChatDraft] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT); + [groupChatDraft] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT); avatarURL = groupChatDraft?.avatarUri ?? undefined; fileName = groupChatDraft?.originalFileName ?? undefined; } @@ -67,7 +67,4 @@ export default withOnyx({ policies: { key: ONYXKEYS.COLLECTION.POLICY, }, - groupChatDraft: { - key: ONYXKEYS.NEW_GROUP_CHAT_DRAFT, - }, })(ReportAvatar); From e4ae8b46cc6b10f3bfd76af89bbadec1cadf6833 Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Fri, 24 May 2024 23:05:15 +0500 Subject: [PATCH 08/30] remove shouldDisableViewPhoto param --- src/components/AvatarWithImagePicker.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/components/AvatarWithImagePicker.tsx b/src/components/AvatarWithImagePicker.tsx index 5fa17e726c6f..af575513449d 100644 --- a/src/components/AvatarWithImagePicker.tsx +++ b/src/components/AvatarWithImagePicker.tsx @@ -118,9 +118,6 @@ type AvatarWithImagePickerProps = { /** Allows to open an image without Attachment Picker. */ enablePreview?: boolean; - /** Hard disables the "View photo" option */ - shouldDisableViewPhoto?: boolean; - /** Optionally override the default "Edit" icon */ editIcon?: IconAsset; }; @@ -150,7 +147,6 @@ function AvatarWithImagePicker({ disabled = false, onViewPhotoPress, enablePreview = false, - shouldDisableViewPhoto = false, editIcon = Expensicons.Pencil, }: AvatarWithImagePickerProps) { const theme = useTheme(); @@ -363,7 +359,7 @@ function AvatarWithImagePicker({ const menuItems = createMenuItems(openPicker); // If the current avatar isn't a default avatar and we are not overriding this behavior allow the "View Photo" option - if (!shouldDisableViewPhoto && !isUsingDefaultAvatar) { + if (!isUsingDefaultAvatar) { menuItems.push({ icon: Expensicons.Eye, text: translate('avatarWithImagePicker.viewPhoto'), From b26a1665f3af0706d71cb6b425ccc2a98022dbfc Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Fri, 24 May 2024 23:11:50 +0500 Subject: [PATCH 09/30] add: conditional for route depending on isNewGroupChat --- src/ROUTES.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index fd7f2bbcc002..4d76aea7ae57 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -220,7 +220,13 @@ const ROUTES = { }, REPORT_AVATAR: { route: 'r/:reportID/avatar', - getRoute: (reportID: string, newGroupChat: boolean) => `r/${reportID}/avatar?newGroupChat=${newGroupChat}` as const, + getRoute: (reportID: string, isNewGroupChat?: boolean) => { + if (isNewGroupChat) { + return `r/${reportID}/avatar?isNewGroupChat=${isNewGroupChat}` as const; + } else { + return `r/${reportID}/avatar` as const; + } + }, }, EDIT_CURRENCY_REQUEST: { route: 'r/:threadReportID/edit/currency', From 1e29cab393c0b7e2d811c48cfff039f4359b684d Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Fri, 24 May 2024 23:12:29 +0500 Subject: [PATCH 10/30] add: parser to convert isNewGroupChat to boolean --- src/libs/Navigation/linkingConfig/config.ts | 7 ++++++- src/libs/Navigation/types.ts | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index a093b778360e..60bda7fc218f 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -22,7 +22,12 @@ const config: LinkingOptions['config'] = { [SCREENS.REPORT_ATTACHMENTS]: ROUTES.REPORT_ATTACHMENTS.route, [SCREENS.PROFILE_AVATAR]: ROUTES.PROFILE_AVATAR.route, [SCREENS.WORKSPACE_AVATAR]: ROUTES.WORKSPACE_AVATAR.route, - [SCREENS.REPORT_AVATAR]: ROUTES.REPORT_AVATAR.route, + [SCREENS.REPORT_AVATAR]: { + path: ROUTES.REPORT_AVATAR.route, + parse: { + isNewGroupChat: (isNewGroupChat: string) => isNewGroupChat === "true", + }, + }, [SCREENS.TRANSACTION_RECEIPT]: ROUTES.TRANSACTION_RECEIPT.route, [SCREENS.WORKSPACE_JOIN_USER]: ROUTES.WORKSPACE_JOIN_USER.route, diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index c62cb3fe7b10..284641aa9800 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -881,7 +881,7 @@ type AuthScreensParamList = SharedScreensParamList & { }; [SCREENS.REPORT_AVATAR]: { reportID: string; - newGroupChat: string + isNewGroupChat: boolean }; [SCREENS.NOT_FOUND]: undefined; [NAVIGATORS.LEFT_MODAL_NAVIGATOR]: NavigatorScreenParams; From 0b0da6c66845b585f82fa9f12a0a6e2034bd0a57 Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Fri, 24 May 2024 23:13:27 +0500 Subject: [PATCH 11/30] update: made isNewGroupChat query param optional --- src/pages/ReportDetailsPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index fcee63d5442a..d401cc09e60f 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -249,7 +249,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD errors={report.errorFields?.avatar ?? null} errorRowStyles={styles.mt6} onErrorClose={() => Report.clearAvatarErrors(report.reportID ?? '')} - onViewPhotoPress={() => Navigation.navigate(ROUTES.REPORT_AVATAR.getRoute(report.reportID, false))} + onViewPhotoPress={() => Navigation.navigate(ROUTES.REPORT_AVATAR.getRoute(report.reportID))} /> ) : ( Date: Fri, 24 May 2024 23:19:06 +0500 Subject: [PATCH 12/30] refactor: clean code --- src/pages/ReportAvatar.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index 46fe9618d904..ab4bf42a9af6 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -23,19 +23,19 @@ type ReportAvatarProps = ReportAvatarOnyxProps & StackScreenProps ); From 232e787657726a34b44f4923fa2103a53c464628 Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Fri, 24 May 2024 23:49:23 +0500 Subject: [PATCH 13/30] fix: lint issues --- src/ROUTES.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 4d76aea7ae57..721c19389d27 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -223,9 +223,8 @@ const ROUTES = { getRoute: (reportID: string, isNewGroupChat?: boolean) => { if (isNewGroupChat) { return `r/${reportID}/avatar?isNewGroupChat=${isNewGroupChat}` as const; - } else { - return `r/${reportID}/avatar` as const; } + return `r/${reportID}/avatar` as const; }, }, EDIT_CURRENCY_REQUEST: { From 8ff95bef27148b7aad90a58f997c29aa8c758fe5 Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Sat, 25 May 2024 01:18:13 +0500 Subject: [PATCH 14/30] fix: lint issues --- src/libs/Navigation/linkingConfig/config.ts | 4 ++-- src/libs/Navigation/types.ts | 2 +- src/pages/ReportAvatar.tsx | 7 +++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index 60bda7fc218f..392eac2369f6 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -25,8 +25,8 @@ const config: LinkingOptions['config'] = { [SCREENS.REPORT_AVATAR]: { path: ROUTES.REPORT_AVATAR.route, parse: { - isNewGroupChat: (isNewGroupChat: string) => isNewGroupChat === "true", - }, + isNewGroupChat: (isNewGroupChat: string) => isNewGroupChat === 'true', + }, }, [SCREENS.TRANSACTION_RECEIPT]: ROUTES.TRANSACTION_RECEIPT.route, [SCREENS.WORKSPACE_JOIN_USER]: ROUTES.WORKSPACE_JOIN_USER.route, diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 284641aa9800..061249da3658 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -881,7 +881,7 @@ type AuthScreensParamList = SharedScreensParamList & { }; [SCREENS.REPORT_AVATAR]: { reportID: string; - isNewGroupChat: boolean + isNewGroupChat: boolean; }; [SCREENS.NOT_FOUND]: undefined; [NAVIGATORS.LEFT_MODAL_NAVIGATOR]: NavigatorScreenParams; diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index ab4bf42a9af6..2f206fb0977d 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -25,14 +25,13 @@ function ReportAvatar({report = {} as Report, policies, isLoadingApp = true, rou const title = policy ? ReportUtils.getPolicyName(report, false, policy) : report?.reportName; let avatarURL; let fileName; - const [groupChatDraft] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT);; + const [groupChatDraft] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT); const shouldUseGroupChatDraft = route.params.isNewGroupChat; - if(shouldUseGroupChatDraft) { + if (shouldUseGroupChatDraft) { avatarURL = groupChatDraft?.avatarUri ?? undefined; fileName = groupChatDraft?.originalFileName ?? undefined; - } - else { + } else { avatarURL = policy ? ReportUtils.getWorkspaceAvatar(report) : report?.avatarUrl; // In the case of default workspace avatar, originalFileName prop takes policyID as value to get the color of the avatar fileName = policy ? policy?.originalFileName ?? policy?.id : title; From 284d1f08fc6675ff13f1c5c635b5f2132002ae12 Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Mon, 27 May 2024 15:08:54 +0500 Subject: [PATCH 15/30] fix: minor logic issues --- src/libs/Navigation/types.ts | 2 +- src/pages/ReportAvatar.tsx | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 061249da3658..2791d6d4e2b5 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -881,7 +881,7 @@ type AuthScreensParamList = SharedScreensParamList & { }; [SCREENS.REPORT_AVATAR]: { reportID: string; - isNewGroupChat: boolean; + isNewGroupChat?: boolean; }; [SCREENS.NOT_FOUND]: undefined; [NAVIGATORS.LEFT_MODAL_NAVIGATOR]: NavigatorScreenParams; diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index 2f206fb0977d..c490a81444ba 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -22,19 +22,23 @@ type ReportAvatarProps = ReportAvatarOnyxProps & StackScreenProps Date: Wed, 29 May 2024 18:55:08 +0500 Subject: [PATCH 16/30] fix: shouldShowNotFoundPage condition --- src/pages/ReportAvatar.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index c490a81444ba..4193a6af62bf 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -41,6 +41,7 @@ function ReportAvatar({report = {} as Report, policies, isLoadingApp = true, rou title = policy ? ReportUtils.getPolicyName(report, false, policy) : report?.reportName; } + const shouldShowNotFoundPage = !isLoadingApp && (shouldUseGroupChatDraft ? !groupChatDraft : !policy && !report?.reportID); return ( ); From f6f582c06fa9942fd3f5bce5be778ee82be638d7 Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Tue, 4 Jun 2024 15:37:19 +0500 Subject: [PATCH 17/30] fix: handle edge cases for group chat name --- src/pages/ReportAvatar.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index 4193a6af62bf..807713f114af 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -33,7 +33,9 @@ function ReportAvatar({report = {} as Report, policies, isLoadingApp = true, rou if (shouldUseGroupChatDraft) { avatarURL = groupChatDraft?.avatarUri ?? undefined; fileName = groupChatDraft?.originalFileName ?? undefined; - title = groupChatDraft?.reportName ?? ''; + // When user enters custom group name, it typically stored in groupChatDraft.reportName + // If that is null then we will use ReportUtils.getGroupChatName to get the name + title = groupChatDraft?.reportName ? groupChatDraft?.reportName : ReportUtils.getGroupChatName(groupChatDraft?.participants.map(x => x.accountID) ?? []); } else { avatarURL = policy ? ReportUtils.getWorkspaceAvatar(report) : report?.avatarUrl; // In the case of default workspace avatar, originalFileName prop takes policyID as value to get the color of the avatar From cf3f9428c2b2dabe3248e577d4ca684c6e9c7634 Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Thu, 6 Jun 2024 15:51:06 +0500 Subject: [PATCH 18/30] fix: report title edge cases --- src/pages/ReportAvatar.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index 807713f114af..93d42ca0188c 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -25,6 +25,8 @@ function ReportAvatar({report = {} as Report, policies, isLoadingApp = true, rou let title; let avatarURL; let fileName; + // eslint-disable-next-line rulesdir/no-negated-variables + let shouldShowNotFoundPage; const shouldUseGroupChatDraft = !!route.params.isNewGroupChat; @@ -35,15 +37,20 @@ function ReportAvatar({report = {} as Report, policies, isLoadingApp = true, rou fileName = groupChatDraft?.originalFileName ?? undefined; // When user enters custom group name, it typically stored in groupChatDraft.reportName // If that is null then we will use ReportUtils.getGroupChatName to get the name - title = groupChatDraft?.reportName ? groupChatDraft?.reportName : ReportUtils.getGroupChatName(groupChatDraft?.participants.map(x => x.accountID) ?? []); + title = groupChatDraft?.reportName ? groupChatDraft?.reportName : ReportUtils.getGroupChatName(groupChatDraft?.participants.map((x) => x.accountID) ?? []); + shouldShowNotFoundPage = !isLoadingApp && !groupChatDraft; } else { avatarURL = policy ? ReportUtils.getWorkspaceAvatar(report) : report?.avatarUrl; // In the case of default workspace avatar, originalFileName prop takes policyID as value to get the color of the avatar fileName = policy ? policy?.originalFileName ?? policy?.id : title; - title = policy ? ReportUtils.getPolicyName(report, false, policy) : report?.reportName; + if (policy) { + title = ReportUtils.getPolicyName(report, false, policy); + } else { + title = report?.reportName ? report.reportName : ReportUtils.getGroupChatName(undefined, false, report?.reportID); + } + shouldShowNotFoundPage = !isLoadingApp && !policy && !report?.reportID; } - const shouldShowNotFoundPage = !isLoadingApp && (shouldUseGroupChatDraft ? !groupChatDraft : !policy && !report?.reportID); return ( Date: Fri, 7 Jun 2024 04:18:37 +0500 Subject: [PATCH 19/30] fix: changes WIP --- src/pages/ReportAvatar.tsx | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index 93d42ca0188c..a40c8bdbebda 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -37,17 +37,13 @@ function ReportAvatar({report = {} as Report, policies, isLoadingApp = true, rou fileName = groupChatDraft?.originalFileName ?? undefined; // When user enters custom group name, it typically stored in groupChatDraft.reportName // If that is null then we will use ReportUtils.getGroupChatName to get the name - title = groupChatDraft?.reportName ? groupChatDraft?.reportName : ReportUtils.getGroupChatName(groupChatDraft?.participants.map((x) => x.accountID) ?? []); + title = groupChatDraft?.reportName || ReportUtils.getGroupChatName(groupChatDraft?.participants.map((participant) => participant.accountID) ?? []); shouldShowNotFoundPage = !isLoadingApp && !groupChatDraft; } else { avatarURL = policy ? ReportUtils.getWorkspaceAvatar(report) : report?.avatarUrl; // In the case of default workspace avatar, originalFileName prop takes policyID as value to get the color of the avatar - fileName = policy ? policy?.originalFileName ?? policy?.id : title; - if (policy) { - title = ReportUtils.getPolicyName(report, false, policy); - } else { - title = report?.reportName ? report.reportName : ReportUtils.getGroupChatName(undefined, false, report?.reportID); - } + fileName = policy?.originalFileName ?? policy?.id; + title = policy ? ReportUtils.getPolicyName(report, false, policy) : ReportUtils.getReportName(report); shouldShowNotFoundPage = !isLoadingApp && !policy && !report?.reportID; } From c0db9ef0d282f41acbd84221a0ef851c6180c256 Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Mon, 10 Jun 2024 17:45:00 +0500 Subject: [PATCH 20/30] fix: remove policy from not found --- src/pages/ReportAvatar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index cf7ef1c40028..e45d2930ba91 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -44,7 +44,7 @@ function ReportAvatar({report = {} as Report, policies, isLoadingApp = true, rou // In the case of default workspace avatar, originalFileName prop takes policyID as value to get the color of the avatar fileName = policy?.originalFileName ?? policy?.id ?? report?.policyID; title = policy ? ReportUtils.getPolicyName(report, false, policy) : ReportUtils.getReportName(report); - shouldShowNotFoundPage = !isLoadingApp && !policy && !report?.reportID; + shouldShowNotFoundPage = !isLoadingApp && !report?.reportID; } return ( From 6d6953f6b6287006d62c838b445daf301453b788 Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Mon, 10 Jun 2024 17:59:22 +0500 Subject: [PATCH 21/30] fix: lint issues --- src/pages/ReportAvatar.tsx | 2 +- src/types/onyx/NewGroupChatDraft.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index e45d2930ba91..9870a7b3acdd 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -37,7 +37,7 @@ function ReportAvatar({report = {} as Report, policies, isLoadingApp = true, rou fileName = groupChatDraft?.originalFileName ?? undefined; // When user enters custom group name, it typically stored in groupChatDraft.reportName // If that is null then we will use ReportUtils.getGroupChatName to get the name - title = groupChatDraft?.reportName || ReportUtils.getGroupChatName(groupChatDraft?.participants.map((participant) => participant.accountID) ?? []); + title = groupChatDraft?.reportName ?? ReportUtils.getGroupChatName(groupChatDraft?.participants.map((participant) => participant.accountID) ?? []); shouldShowNotFoundPage = !isLoadingApp && !groupChatDraft; } else { avatarURL = policy ? ReportUtils.getWorkspaceAvatar(report) : report?.avatarUrl; diff --git a/src/types/onyx/NewGroupChatDraft.ts b/src/types/onyx/NewGroupChatDraft.ts index fba6b6866efe..f56d3567a3d7 100644 --- a/src/types/onyx/NewGroupChatDraft.ts +++ b/src/types/onyx/NewGroupChatDraft.ts @@ -17,6 +17,8 @@ type NewGroupChatDraft = { /** New group chat avatar URI */ avatarUri: string | null; + + /** New group chat file name */ originalFileName: string | null; }; export type {SelectedParticipant}; From 9d4a66fded40bb383851fe44b1ff002d1ce745c1 Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Wed, 12 Jun 2024 19:06:53 +0500 Subject: [PATCH 22/30] add: originalFileName to report onyx --- src/libs/actions/Report.ts | 2 ++ src/pages/ReportAvatar.tsx | 2 +- src/types/onyx/Report.ts | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index ab8ca2a1a4b6..93d8c640f7e6 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -673,6 +673,7 @@ function updateGroupChatAvatar(reportID: string, file?: File | CustomRNImageMani key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: { avatarUrl: file?.uri ?? '', + originalFileName: file?.name ?? '', pendingFields: { avatar: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, }, @@ -689,6 +690,7 @@ function updateGroupChatAvatar(reportID: string, file?: File | CustomRNImageMani key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: { avatarUrl: currentReportData?.[reportID]?.avatarUrl ?? null, + originalFileName: currentReportData?.[reportID]?.originalFileName ?? null, pendingFields: { avatar: null, }, diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index 9870a7b3acdd..444d27d38caf 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -42,7 +42,7 @@ function ReportAvatar({report = {} as Report, policies, isLoadingApp = true, rou } else { avatarURL = policy ? ReportUtils.getWorkspaceAvatar(report) : report?.avatarUrl; // In the case of default workspace avatar, originalFileName prop takes policyID as value to get the color of the avatar - fileName = policy?.originalFileName ?? policy?.id ?? report?.policyID; + fileName = policy ? policy?.originalFileName ?? policy?.id ?? report?.policyID : report?.originalFileName; title = policy ? ReportUtils.getPolicyName(report, false, policy) : ReportUtils.getReportName(report); shouldShowNotFoundPage = !isLoadingApp && !report?.reportID; } diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index 77409c036696..56c2ad262313 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -71,6 +71,9 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback< /** The URL of the Group Chat report custom avatar */ avatarUrl?: string; + /** The file name of the Group Chat report custom avatar */ + originalFileName?: string; + /** The specific type of chat */ chatType?: ValueOf; From 38d7f5b3807e61684aa3a0e2e3c606926c47cac5 Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Wed, 12 Jun 2024 19:08:52 +0500 Subject: [PATCH 23/30] fix: null checks for title --- src/pages/ReportAvatar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index 444d27d38caf..7d9321b95281 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -37,7 +37,7 @@ function ReportAvatar({report = {} as Report, policies, isLoadingApp = true, rou fileName = groupChatDraft?.originalFileName ?? undefined; // When user enters custom group name, it typically stored in groupChatDraft.reportName // If that is null then we will use ReportUtils.getGroupChatName to get the name - title = groupChatDraft?.reportName ?? ReportUtils.getGroupChatName(groupChatDraft?.participants.map((participant) => participant.accountID) ?? []); + title = groupChatDraft?.reportName || ReportUtils.getGroupChatName(groupChatDraft?.participants.map((participant) => participant.accountID) ?? [], true); shouldShowNotFoundPage = !isLoadingApp && !groupChatDraft; } else { avatarURL = policy ? ReportUtils.getWorkspaceAvatar(report) : report?.avatarUrl; From 530df19f6e025806c8888848b3cc0e8d23b65ee1 Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Wed, 12 Jun 2024 19:15:57 +0500 Subject: [PATCH 24/30] fix: lint issues --- src/pages/ReportAvatar.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index 7d9321b95281..8f8bb2229af1 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -37,6 +37,7 @@ function ReportAvatar({report = {} as Report, policies, isLoadingApp = true, rou fileName = groupChatDraft?.originalFileName ?? undefined; // When user enters custom group name, it typically stored in groupChatDraft.reportName // If that is null then we will use ReportUtils.getGroupChatName to get the name + /* eslint-disable @typescript-eslint/prefer-nullish-coalescing */ title = groupChatDraft?.reportName || ReportUtils.getGroupChatName(groupChatDraft?.participants.map((participant) => participant.accountID) ?? [], true); shouldShowNotFoundPage = !isLoadingApp && !groupChatDraft; } else { From bc18cf6e76bcc5302a9d5aca5a99a04840aa4007 Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Thu, 4 Jul 2024 12:43:12 +0500 Subject: [PATCH 25/30] add: handle offline behaviour for view photo --- src/libs/actions/Report.ts | 4 ++-- src/pages/ReportAvatar.tsx | 2 +- src/types/onyx/Report.ts | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 93d8c640f7e6..2ea07c961dee 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -673,7 +673,7 @@ function updateGroupChatAvatar(reportID: string, file?: File | CustomRNImageMani key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: { avatarUrl: file?.uri ?? '', - originalFileName: file?.name ?? '', + avatarFileName: file?.name ?? '', pendingFields: { avatar: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, }, @@ -690,7 +690,7 @@ function updateGroupChatAvatar(reportID: string, file?: File | CustomRNImageMani key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: { avatarUrl: currentReportData?.[reportID]?.avatarUrl ?? null, - originalFileName: currentReportData?.[reportID]?.originalFileName ?? null, + avatarFileName: currentReportData?.[reportID]?.avatarFileName ?? null, pendingFields: { avatar: null, }, diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index 8f8bb2229af1..69146acd0993 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -43,7 +43,7 @@ function ReportAvatar({report = {} as Report, policies, isLoadingApp = true, rou } else { avatarURL = policy ? ReportUtils.getWorkspaceAvatar(report) : report?.avatarUrl; // In the case of default workspace avatar, originalFileName prop takes policyID as value to get the color of the avatar - fileName = policy ? policy?.originalFileName ?? policy?.id ?? report?.policyID : report?.originalFileName; + fileName = policy ? policy?.originalFileName ?? policy?.id ?? report?.policyID : report?.avatarFileName; title = policy ? ReportUtils.getPolicyName(report, false, policy) : ReportUtils.getReportName(report); shouldShowNotFoundPage = !isLoadingApp && !report?.reportID; } diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index 56c2ad262313..8cfbc13554d0 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -71,8 +71,10 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback< /** The URL of the Group Chat report custom avatar */ avatarUrl?: string; - /** The file name of the Group Chat report custom avatar */ - originalFileName?: string; + /** The file name of the Group Chat report custom avatar + * This field is not coming from backend, so it's for client side only + */ + avatarFileName?: string; /** The specific type of chat */ chatType?: ValueOf; From db65135df2a4d2bf080af51eafa9cee3c0275bf5 Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Thu, 4 Jul 2024 12:58:56 +0500 Subject: [PATCH 26/30] add: isNewGroupChat to types after merge main --- src/libs/Navigation/types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index ac9710b65d19..ca4307434a9e 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -1019,6 +1019,7 @@ type AuthScreensParamList = CentralPaneScreensParamList & }; [SCREENS.REPORT_AVATAR]: { reportID: string; + isNewGroupChat: boolean; }; [SCREENS.NOT_FOUND]: undefined; [NAVIGATORS.LEFT_MODAL_NAVIGATOR]: NavigatorScreenParams; From 86fb5e7784994212ef19e5c5cffc0a41e2a8848d Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Sun, 7 Jul 2024 19:57:48 +0500 Subject: [PATCH 27/30] fix: view photo when chat created offline(optimistic) --- src/libs/ReportUtils.ts | 6 ++++++ src/libs/actions/Report.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index e16c5c7abe56..b2de7918813f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -269,6 +269,7 @@ type OptimisticChatReport = Pick< | 'description' | 'writeCapability' | 'avatarUrl' + | 'avatarFileName' | 'invoiceReceiver' | 'isHidden' > & { @@ -4637,6 +4638,7 @@ function buildOptimisticChatReport( parentReportID = '', description = '', avatarUrl = '', + avatarFileName = '', optimisticReportID = '', shouldShowParticipants = true, ): OptimisticChatReport { @@ -4678,6 +4680,7 @@ function buildOptimisticChatReport( description, writeCapability, avatarUrl, + avatarFileName }; if (chatType === CONST.REPORT.CHAT_TYPE.INVOICE) { @@ -4695,6 +4698,7 @@ function buildOptimisticGroupChatReport( participantAccountIDs: number[], reportName: string, avatarUri: string, + avatarFileName: string, optimisticReportID?: string, notificationPreference?: NotificationPreference, ) { @@ -4713,6 +4717,7 @@ function buildOptimisticGroupChatReport( undefined, undefined, avatarUri, + avatarFileName, optimisticReportID, ); } @@ -5205,6 +5210,7 @@ function buildTransactionThread( '', '', '', + '', false, ); } diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 1667d8e2ebcb..c8c147c2ce17 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -982,7 +982,7 @@ function navigateToAndOpenReport( if (isEmptyObject(chat)) { if (isGroupChat) { // If we are creating a group chat then participantAccountIDs is expected to contain currentUserAccountID - newChat = ReportUtils.buildOptimisticGroupChatReport(participantAccountIDs, reportName ?? '', avatarUri ?? '', optimisticReportID, CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); + newChat = ReportUtils.buildOptimisticGroupChatReport(participantAccountIDs, reportName ?? '', avatarUri ?? '', avatarFile?.name ?? '', optimisticReportID, CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); } else { newChat = ReportUtils.buildOptimisticChatReport( [...participantAccountIDs, currentUserAccountID], From 12d1da788505fdd943675099208b25a72869a81d Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Sun, 7 Jul 2024 20:15:02 +0500 Subject: [PATCH 28/30] fix: lint issues --- src/libs/ReportUtils.ts | 2 +- src/libs/actions/Report.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index b2de7918813f..8e6238b1b337 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4680,7 +4680,7 @@ function buildOptimisticChatReport( description, writeCapability, avatarUrl, - avatarFileName + avatarFileName, }; if (chatType === CONST.REPORT.CHAT_TYPE.INVOICE) { diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index c8c147c2ce17..6f5596e386bd 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -982,7 +982,14 @@ function navigateToAndOpenReport( if (isEmptyObject(chat)) { if (isGroupChat) { // If we are creating a group chat then participantAccountIDs is expected to contain currentUserAccountID - newChat = ReportUtils.buildOptimisticGroupChatReport(participantAccountIDs, reportName ?? '', avatarUri ?? '', avatarFile?.name ?? '', optimisticReportID, CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); + newChat = ReportUtils.buildOptimisticGroupChatReport( + participantAccountIDs, + reportName ?? '', + avatarUri ?? '', + avatarFile?.name ?? '', + optimisticReportID, + CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, + ); } else { newChat = ReportUtils.buildOptimisticChatReport( [...participantAccountIDs, currentUserAccountID], From f2e6e7b28a6da6f569ebaef6925f131bc0b52fe5 Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Thu, 18 Jul 2024 02:13:08 +0500 Subject: [PATCH 29/30] making a single getAllReports call and merging main --- src/libs/actions/Report.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 838e0368bd68..0dec5d4a91e6 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -687,13 +687,15 @@ function updateGroupChatAvatar(reportID: string, file?: File | CustomRNImageMani }, ]; + const fetchedReport = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; + const failureData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: { - avatarFileName: ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.avatarFileName ?? null, - avatarUrl: ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.avatarUrl ?? null, + avatarFileName: fetchedReport?.avatarFileName ?? null, + avatarUrl: fetchedReport?.avatarUrl ?? null, pendingFields: { avatar: null, }, From 1c3e7db84ff296c9a62fd48530de4c2306027994 Mon Sep 17 00:00:00 2001 From: usman-ghani564 Date: Fri, 19 Jul 2024 01:14:36 +0500 Subject: [PATCH 30/30] verify parameters of buildOptimisticChatReport --- src/libs/ReportUtils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 797e5fc5c4fb..62197840378b 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5069,6 +5069,7 @@ function buildOptimisticWorkspaceChats(policyID: string, policyName: string, exp undefined, undefined, undefined, + undefined, expenseReportId, ); const expenseChatReportID = expenseChatData.reportID;