Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for viewing full screen Group Chat custom avatars #41586

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

nexarvo
Copy link
Contributor

@nexarvo nexarvo commented May 3, 2024

Details

Fixed Issues

$ #39850
#39760
PROPOSAL: #39850 (comment)

Tests

Group Chat Case:

  1. Go to any group chat
  2. Click on the header
  3. Click on the chat avatar
  4. In the menu click on "View Photo"
  5. Verify that avatar opens in full screen and we can dismiss the modal by clicking "X".

Creating new Group Chat Case:

  1. Click on the '+' button in main tab navigator.
  2. Click on start new chat.
  3. Select participant/s by clicking 'Add to group'.
  4. In the New chat confirm modal, click on the avatar and upload a new avatar.
  5. Now click on the avatar > click on 'View Photo'.
  6. Verify that avatar opens in full screen and we can dismiss the modal by clicking "X".

Group Chat Thread Case:

  1. Go to any group chat
  2. Start a thread
  3. Click on the header of the thread to go to the Details page
  4. Hover over the profile picture. Notice that there is a Pointer Cursor.
  5. Click on the Profile Picture.
  6. Verify that avatar opens in full screen and we can dismiss the modal by clicking "X".
  • Verify that no errors appear in the JS console

Offline tests

Group Chat Case:

  1. Go to any group chat
  2. Click on the header
  3. Click on the chat avatar
  4. In the menu click on "View Photo"
  5. Verify that full screen modal opens with message "You appear to be offline.".

Creating new Group Chat Case:

  1. Click on the '+' button in main tab navigator.
  2. Click on start new chat.
  3. Select participant/s by clicking 'Add to group'.
  4. In the New chat confirm modal, click on the avatar and upload a new avatar.
  5. Now click on the avatar > click on 'View Photo'.
  6. Verify that avatar opens in full screen and we can dismiss the modal by clicking "X".

Group Chat Thread Case:

  1. Go to any group chat
  2. Start a thread
  3. Click on the header of the thread to go to the Details page
  4. Hover over the profile picture. Notice that there is a Pointer Cursor.
  5. Click on the Profile Picture.
  6. Verify that avatar opens in full screen and we can dismiss the modal by clicking "X".

QA Steps

Group Chat Case:

  1. Go to any group chat
  2. Click on the header
  3. Click on the chat avatar
  4. In the menu click on "View Photo"
  5. Verify that avatar opens in full screen and we can dismiss the modal by clicking "X".

Creating new Group Chat Case:

  1. Click on the '+' button in main tab navigator.
  2. Click on start new chat.
  3. Select participant/s by clicking 'Add to group'.
  4. In the New chat confirm modal, click on the avatar and upload a new avatar.
  5. Now click on the avatar > click on 'View Photo'.
  6. Verify that avatar opens in full screen and we can dismiss the modal by clicking "X".

Group Chat Thread Case:

  1. Go to any group chat
  2. Start a thread
  3. Click on the header of the thread to go to the Details page
  4. Hover over the profile picture. Notice that there is a Pointer Cursor.
  5. Click on the Profile Picture.
  6. Verify that avatar opens in full screen and we can dismiss the modal by clicking "X".
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2024-05-25.at.12.09.09.AM.mov
Screen.20Recording.202024-05-25.20at.2012-5.mp4
Screen.20Recording.202024-05-25.20at.2012-6.mp4
Android: mWeb Chrome
Screen.20Recording.202024-05-25.20at.2012-4.mp4
Screen.Recording.2024-05-25.at.12.33.42.AM.mov
Screen.Recording.2024-05-25.at.12.35.51.AM.mov
iOS: Native

Getting build errors.

iOS: mWeb Safari
RPReplay_Final1716579777.MP4
RPReplay_Final1716579821.MP4
RPReplay_Final1716579969.mp4
MacOS: Chrome / Safari
Screen.Recording.2024-05-03.at.8.23.14.PM.mov


Screen.20Recording.202024-05-24.20at.2011-2.mp4
Screen.20Recording.202024-05-24.20at.2011.mp4
MacOS: Desktop
Screen.20Recording.202024-05-25.20at.2012-2.mp4
Screen.20Recording.202024-05-25.20at.2012-3.mp4
Screen.20Recording.202024-05-25.20at.2012.mp4

@nexarvo nexarvo marked this pull request as ready for review May 3, 2024 15:30
@nexarvo nexarvo requested a review from a team as a code owner May 3, 2024 15:30
@melvin-bot melvin-bot bot removed the request for review from a team May 3, 2024 15:30
Copy link

melvin-bot bot commented May 3, 2024

@s77rt Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot bot requested a review from s77rt May 3, 2024 15:30
defaultOpen
source={UserUtils.getFullSizeAvatar(avatarURL, 0)}
onModalClose={() => {
Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report?.reportID ?? ''));
}}
isWorkspaceAvatar
maybeIcon
originalFileName={policy?.originalFileName ?? policyName}
originalFileName={policy?.originalFileName ?? title}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB. Can you move this to a separate variable like the rest

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Please check

@s77rt
Copy link
Contributor

s77rt commented May 4, 2024

Also complete the checklist

@nexarvo
Copy link
Contributor Author

nexarvo commented May 6, 2024

@s77rt Need to confirm one thing, do we need to add "View Photo" functionality for starting a new group chat modal?
Screenshot 2024-05-06 at 7 07 30 PM

@s77rt
Copy link
Contributor

s77rt commented May 6, 2024

Yes, let's add support for that one too

@s77rt
Copy link
Contributor

s77rt commented May 11, 2024

@nexarvo Any update on this? Let me know if there is something blocking this

@nexarvo
Copy link
Contributor Author

nexarvo commented May 13, 2024

sorry for the delay. I will update and push the code for this by today EOD.

@nexarvo
Copy link
Contributor Author

nexarvo commented May 17, 2024

@s77rt can you please review this commit for this feature. Once approved I will test all the edge cases related to this.

Comment on lines 28 to 30
if(!avatarURL && groupChatDraft?.avatarUri) {
avatarURL = `${groupChatDraft.avatarUri}.jpg`;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a hacky solution. What we can do instead is get the file name and pass it as prop originalFileName. This will pass the condition your referenced in AttachmentView

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added originalFileName in this commit.

src/pages/NewChatConfirmPage.tsx Show resolved Hide resolved
let avatarURL = policy ? ReportUtils.getWorkspaceAvatar(report) : report?.avatarUrl;
let fileName = policy?.originalFileName ?? title;

if (!avatarURL && groupChatDraft?.avatarUri && groupChatDraft?.originalFileName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fallback logic will not work correctly in cases where we'd expect to see a not found page i.e. we will always fallback to the draft avatar. Can you instead add a query params that determines if we want to use the group chat draft?

Comment on lines 64 to 66
groupChatDraft: {
key: ONYXKEYS.NEW_GROUP_CHAT_DRAFT,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this use the useOnyx hook instead. It should help avoid loading the data from onyx if we are not going to use it. Related to the point above ^

@nexarvo
Copy link
Contributor Author

nexarvo commented May 23, 2024

@s77rt updated the code to address this and this

Copy link
Contributor

@s77rt s77rt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix the conflicts please

}}
size={CONST.AVATAR_SIZE.XLARGE}
avatarStyle={styles.avatarXLarge}
shouldDisableViewPhoto
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prop is not removed yet from AvatarWithImagePicker

Comment on lines 31 to 35
if(shouldUseGroupChatDraft) {
[groupChatDraft] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT);
avatarURL = groupChatDraft?.avatarUri ?? undefined;
fileName = groupChatDraft?.originalFileName ?? undefined;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hooks cannot be conditioned.

originalFileName={policy?.originalFileName ?? policyName}
shouldShowNotFoundPage={!report?.reportID && !isLoadingApp}
originalFileName={fileName}
shouldShowNotFoundPage={!report?.reportID && !groupChatDraft && !isLoadingApp}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to the above ^. Since groupChatDraft will pretty much always be set we will not see the not found page in any case. Please update the logic accordingly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove ! groupChatDraft from above condition then for groupChatDraft it always return not found page.

src/ROUTES.ts Outdated
@@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not pass the query param if the newGroupChat param is not true

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB. Change the param name to isNewGroupChat

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Added conditional to return route based on isNewGroupChat here.

@@ -884,6 +884,7 @@ type AuthScreensParamList = SharedScreensParamList & {
};
[SCREENS.REPORT_AVATAR]: {
reportID: string;
newGroupChat: string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be boolean. Then in src/libs/Navigation/linkingConfig/config.ts add

parse: {
    newGroupChat: (newGroupChat: string) => newGroupChat === "true",
},

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done.

@@ -881,7 +881,7 @@ type AuthScreensParamList = SharedScreensParamList & {
};
[SCREENS.REPORT_AVATAR]: {
reportID: string;
newGroupChat: string
isNewGroupChat: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
isNewGroupChat: boolean;
isNewGroupChat?: boolean;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let groupChatDraft;
let avatarURL;
let fileName;
const [groupChatDraft] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const [groupChatDraft] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT);
const shouldUseGroupChatDraft = !!route.params.isNewGroupChat;
const [groupChatDraft] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT, {initWithStoredValues: shouldUseGroupChatDraft});

A little optimization, we don't need to get onyx values if we are not going to use it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@s77rt
Copy link
Contributor

s77rt commented May 25, 2024

Bug: The report name (title) is not displayed

Screenshot 2024-05-25 at 7 33 06 PM

@s77rt
Copy link
Contributor

s77rt commented May 25, 2024

Bug: If you try to access the avatar of a non-existing report you will not see the not found view (because groupChatDraft is present)
Solution: Write a conditioned shouldShowNotFoundPage variable

@nexarvo
Copy link
Contributor Author

nexarvo commented May 27, 2024

Bug: The report name (title) is not displayed

Screenshot 2024-05-25 at 7 33 06 PM

I think is from new group chat. Actually we are showing policyName or report.title in the title of the modal. For new group chat, if the user does not enters custom name foe group chat the default name is not added to the GroupChatDraft. We can update the logic to add default chat name to GroupChatDraft as well here, so that it does not show as empty.
thoughts @s77rt ?

@nexarvo
Copy link
Contributor Author

nexarvo commented May 27, 2024

Bug: If you try to access the avatar of a non-existing report you will not see the not found view (because groupChatDraft is present) Solution: Write a conditioned shouldShowNotFoundPage variable

Will fix this today

if (shouldUseGroupChatDraft) {
avatarURL = groupChatDraft?.avatarUri ?? undefined;
fileName = groupChatDraft?.originalFileName ?? undefined;
title = groupChatDraft?.reportName ?? '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ReportUtils.getReportName

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReportUtils.getReportName takes report as input but in this case we have groupChatDraft which is of type: OnyxEntry<NewGroupChatDraft>.

function getReportName(report: OnyxEntry<Report>, policy: OnyxEntry<Policy> = null): string {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use ReportUtils.getGroupChatName then

@nexarvo
Copy link
Contributor Author

nexarvo commented May 29, 2024

Bug: If you try to access the avatar of a non-existing report you will not see the not found view (because groupChatDraft is present) Solution: Write a conditioned shouldShowNotFoundPage variable

Updated the condition in this commit.

if (shouldUseGroupChatDraft) {
avatarURL = groupChatDraft?.avatarUri ?? undefined;
fileName = groupChatDraft?.originalFileName ?? undefined;
title = groupChatDraft?.reportName ?? '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use ReportUtils.getGroupChatName then

title = policy ? ReportUtils.getPolicyName(report, false, policy) : report?.reportName;
}

const shouldShowNotFoundPage = !isLoadingApp && (shouldUseGroupChatDraft ? !groupChatDraft : !policy && !report?.reportID);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to the if condition above and add eslint ignore comment (false positive)

@s77rt
Copy link
Contributor

s77rt commented Jun 5, 2024

@nexarvo Any updates here?

@nexarvo
Copy link
Contributor Author

nexarvo commented Jun 6, 2024

@s77rt the code is updated now and ready for review :)

Copy link
Contributor

@s77rt s77rt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unable to test this, all attachments are stuck in loading state, can you try merge main see if that fixes it

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) ?? []);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
title = groupChatDraft?.reportName ? groupChatDraft?.reportName : ReportUtils.getGroupChatName(groupChatDraft?.participants.map((x) => x.accountID) ?? []);
title = groupChatDraft?.reportName || ReportUtils.getGroupChatName(groupChatDraft?.participants.map((participant) => participant.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
fileName = policy ? policy?.originalFileName ?? policy?.id : title;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you adding title as fallback? Also it's undefined at this point

Comment on lines +46 to +50
if (policy) {
title = ReportUtils.getPolicyName(report, false, policy);
} else {
title = report?.reportName ? report.reportName : ReportUtils.getGroupChatName(undefined, false, report?.reportID);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (policy) {
title = ReportUtils.getPolicyName(report, false, policy);
} else {
title = report?.reportName ? report.reportName : ReportUtils.getGroupChatName(undefined, false, report?.reportID);
}
title = policy ? ReportUtils.getPolicyName(report, false, policy) : ReportUtils.getReportName(report);

} else {
title = report?.reportName ? report.reportName : ReportUtils.getGroupChatName(undefined, false, report?.reportID);
}
shouldShowNotFoundPage = !isLoadingApp && !policy && !report?.reportID;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why we are adding the policy check?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants