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

[HOLD for payment 2024-10-14] [$250] mWeb - Attachment - Opened offline attachment directed to conversation page on online #48173

Closed
1 of 6 tasks
lanitochka17 opened this issue Aug 28, 2024 · 87 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor

Comments

@lanitochka17
Copy link

lanitochka17 commented Aug 28, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.0.25
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail: N/A
Issue reported by: Applause - Internal Team

Action Performed:

  1. Go to https://staging.new.expensify.com/home
  2. Open a chat
  3. Go offline
  4. Upload a image
  5. Open the image
  6. Go online
  7. Note User directed to conversation page

Expected Result:

Upload and open attachment in offline, then going online user must stay in same attachment page

Actual Result:

Upload and open attachment in offline, then going online user directed to conversation page

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Bug6584997_1724833122321.Screenrecorder-2024-08-27-17-12-45-779_compress_1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01e366edd029d4e402
  • Upwork Job ID: 1829648417535865218
  • Last Price Increase: 2024-09-20
  • Automatic offers:
    • wildan-m | Contributor | 104146531
Issue OwnerCurrent Issue Owner: @mallenexpensify
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Aug 28, 2024
Copy link

melvin-bot bot commented Aug 28, 2024

Triggered auto assignment to @kevinksullivan (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@NJ-2020
Copy link
Contributor

NJ-2020 commented Aug 28, 2024

Proposal

Please restate the problem we are trying to solve with this issue.

mWeb - Attachment - Opened offline attachment directed to conversation page on online.

What is the root cause of this problem?

When we are offline, we upload an attachment and click on it to view the details by clicking the attachment. When we return online, we invoke submitAndClose function because an attachment has been sent. Inside this function, we close the modal with setIsModalOpen(false) after sending the attachment.

/**
* Execute the onConfirm callback and close the modal.
*/
const submitAndClose = useCallback(() => {
// If the modal has already been closed or the confirm button is disabled
// do not submit.
if (!isModalOpen || isConfirmButtonDisabled) {
return;
}
if (onConfirm) {
onConfirm(Object.assign(file ?? {}, {source: sourceState} as FileObject));
}
setIsModalOpen(false);
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [isModalOpen, isConfirmButtonDisabled, onConfirm, file, sourceState]);

What changes do you think we should make in order to solve the problem?

We can add a new parameter to the URL or a parameter inside the function to indicate how the AttachmentModal was opened. For example, we can use ?openType=openDetail when the user opens the attachment by clicking on it, and ?openType=submit when the user submits the attachment. We can then conditionally close the modal based on the value of openType.

What alternative solutions did you explore? (Optional)

We can check if there is existing Onyx data for the attachment. If there is, it means the attachment has been submitted but not yet added to the backend. In this case, we can avoid invoking setIsModalOpen(false) and keep the modal open.

@NJ-2020
Copy link
Contributor

NJ-2020 commented Aug 28, 2024

Proposal

Updated

@tsa321
Copy link
Contributor

tsa321 commented Aug 28, 2024

Edited by proposal-police: This proposal was edited at 2024-08-28 14:38:24 UTC.

Proposal

Please re-state the problem that we are trying to solve in this issue.

When opening a sent attachment while offline, after going online, the app navigates to a report.

What is the root cause of that problem?

When viewing an attachment image, the AttachmentCarousel is displayed. It uses logic to determine if the viewed image has been deleted then dismiss the modal. This is done by comparing the source (a URL parameter) with the available attachment properties in reportActions:

// Dismiss the modal when deleting an attachment during its display in preview.
if (initialPage === -1 && attachments.find(compareImage)) {
Navigation.dismissModal();
} else {

The lines detects if the viewed image is deleted by comparing the current source with the updated attachment properties retrieved from reportActions.

When the user is offline, the current source is a blob URL string. When the user goes online, this source is updated to a new path.

The current detection logic mistakenly identifies the image as deleted because the blob URL is no longer available, resulting in the dismissal of the modal.

What changes do you think we should make in order to solve the problem?

We could add a check in the if clause to determine whether the current source is an image that will be uploaded, by verifying if the source starts with blob and if the new attachment has the same file name as the uploaded image.

The revised code could look like this, assuming a report action can have multiple images (i.e., an array):

if (initialPage === -1 && attachments.find(compareImage)) {
    let isUploadedImage = false;
   // maybe cheching for wheter the file is blob uri object is enough, but for more code completeness I am adding additional checks.
   // If we want to checks whether the blob uri object exist we can use `FileUtils.readFileAsync`
    if (source.startsWith('blob')) {
        const uploadedAttachment = attachments.find(compareImage);
        const possibleTargetUploads = targetAttachments.filter(attachment => {
            return attachment.reportActionID === uploadedAttachment.reportActionID;
        });

        isUploadedImage = possibleTargetUploads.some(attachment => {
            return attachment.file.name === uploadedAttachment.file.name;
        });
    }

    if (!isUploadedImage) {
        Navigation.dismissModal();
    }
}

Alternatively, we could check for pending actions such as deletion or addition, if this approach is more accurate, or simply verify whether the reportAction is a deleted message.

What alternative solutions did you explore? (1)

We can determine whether the report action has been deleted by checking the availability of currently viewed report attahcment's reportActionID in targetAttachment. Then set the search result to initialPage.

The code could be:

const currentAttachmentReportActionID = attachments.find(compareImage)?.reportActionID;
let initialPage;
if (currentAttachmentReportActionID) {
    initialPage = targetAttachments.findIndex(attachment => attachment.reportActionID === currentAttachmentReportActionID);
} else {
    initialPage = targetAttachments.findIndex(compareImage);
}

Or :

let initialPage = targetAttachments.findIndex(compareImage);
const currentAttachmentReportActionID = attachments.find(compareImage)?.reportActionID;
const isReportActionExist = currentAttachmentReportActionID ? targetAttachments.find(attachment => attachment.reportActionID === currentAttachmentReportActionID) : initialPage !== -1;

// Dismiss the modal when deleting an attachment during its display in preview.
if (initialPage === -1 && attachments.find(compareImage)) {
    if (!isReportActionExist) {
        Navigation.dismissModal();
    }
}

What alternative solutions did you explore? (2)

Expanding my first solution which I mention to use pendingAction data:
We could add pendingAction data to the attachment. If the report action for the currently viewed attachment is pendingAction add, we should not dismiss the modal.

In this line:

const html = ReportActionsUtils.getReportActionHtml(action).replace('/>', `data-flagged="${hasBeenFlagged}" data-id="${action.reportActionID}"/>`);

We need to modify it to:
(Additionally, some modifications to the replace function are based on the bug I mentioned at the bottom of my proposal):

const html = ReportActionsUtils.getReportActionHtml(action).replace(/(<(?:(?=video )|(?=img )).+?)(\/*)>/gm, `$1 data-flagged="${hasBeenFlagged}" data-id="${action.reportActionID}" data-pending-action="${action?.pendingAction}"$2>`);

Then, in this line and this line, we should add:

pendingAction: attribs['data-pending-action']

In the AttachmentCarousel, we modify the lines near the dismiss modal to:

const currentlyViewedAttachment = attachments.find(compareImage);
if (initialPage === -1 && !!currentlyViewedAttachment) {
    if (currentlyViewedAttachment?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
        Navigation.dismissModal();
    }
}

What alternative solutions did you explore? (3)

This is a simplified version of my initial solution to determine whether a file is stored temporarily by the browser or app. We can check if the source starts with "blob" or "file," or similar characters that indicate it is a file stored in user storage. The code could be:

if (initialPage === -1 && !!currentlyViewedAttachment) {
    if (source.startsWith('blob') || source.startsWith('file')) {
       return;    
    }
    Navigation.dismissModal();
}


Also there is a bug in when user send a text with image attachment, the reportActionID data will be undefined. This in because:

const html = ReportActionsUtils.getReportActionHtml(action).replace('/>', `data-flagged="${hasBeenFlagged}" data-id="${action.reportActionID}"/>`);

If user send a text comment and an image, there is <br /> tag and the end tag of br that will be replaced. the more correct code could be:

const html = ReportActionsUtils.getReportActionHtml(action).replace(/(<img .+?)\/>/gm, `$1 data-flagged="${hasBeenFlagged}" data-id="${action.reportActionID}"/>`);

To also fix for video:

const html = ReportActionsUtils.getReportActionHtml(action).replace(/(<(?:(?=video )|(?=img )).+?)(\/*)>/gm, `$1 data-flagged="${hasBeenFlagged}" data-id="${action.reportActionID}"$2>`);

@daledah
Copy link
Contributor

daledah commented Aug 29, 2024

Edited by proposal-police: This proposal was edited at 2024-08-29 02:10:22 UTC.

Proposal

Please re-state the problem that we are trying to solve in this issue.

Upload and open attachment in offline, then going online user directed to conversation page

What is the root cause of that problem?

  • We have logic to close the attachment modal if User A is viewing an attachment and it gets deleted by User B:

    // Dismiss the modal when deleting an attachment during its display in preview.
    if (initialPage === -1 && attachments.find(compareImage)) {
    Navigation.dismissModal();

  • In this logic, we check if the currently open attachment (identified by the source prop) was present in the previous list of attachments (identified by the attachments state) but no longer appears in the updated list (identified by the targetAttachments variable). If this condition is met, we call Navigation.dismissModal() to close the modal.

  • When we upload an image while offline and then reconnect online, the attachment source data switches from a blob value to the value returned by the backend, triggering the condition mentioned above to be true.

What changes do you think we should make in order to solve the problem?

            if(isLocalFile(source)){
                return
            }
            Navigation.dismissModal();

What alternative solutions did you explore? (Optional)

@daledah
Copy link
Contributor

daledah commented Aug 29, 2024

Proposal updated

@melvin-bot melvin-bot bot added the Overdue label Aug 30, 2024
@kevinksullivan kevinksullivan added the External Added to denote the issue can be worked on by a contributor label Aug 30, 2024
Copy link

melvin-bot bot commented Aug 30, 2024

Job added to Upwork: https://www.upwork.com/jobs/~01e366edd029d4e402

@melvin-bot melvin-bot bot changed the title mWeb - Attachment - Opened offline attachment directed to conversation page on online [$250] mWeb - Attachment - Opened offline attachment directed to conversation page on online Aug 30, 2024
@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Aug 30, 2024
Copy link

melvin-bot bot commented Aug 30, 2024

Triggered auto assignment to Contributor-plus team member for initial proposal review - @s77rt (External)

@melvin-bot melvin-bot bot removed the Overdue label Aug 30, 2024
@s77rt
Copy link
Contributor

s77rt commented Aug 31, 2024

@NJ-2020

When we return online, we invoke submitAndClose function

This is not the case. The function is invoked as soon as you click the submit button (while offline)

@s77rt
Copy link
Contributor

s77rt commented Aug 31, 2024

@tsa321 Your RCA is correct. However the suggested solution is a workaround. The correct approach would be to make the comparison function correctly identify that we are viewing an image that does exist.

@s77rt
Copy link
Contributor

s77rt commented Aug 31, 2024

@daledah Your RCA is correct but same note as above regarding the solution. The attachment carousel should be able to tell that we are still viewing the same image even though the source did change. IOW initialPage should not be -1 because the image we are viewing does exist.

@s77rt
Copy link
Contributor

s77rt commented Aug 31, 2024

It's worth mentioning that the targetAttachments values has a reportAction key which remains unchanged. We can make use of that.

@daledah
Copy link
Contributor

daledah commented Aug 31, 2024

Proposal updated

@s77rt
Copy link
Contributor

s77rt commented Aug 31, 2024

@daledah A file name is not a unique identifier and thus we cannot use it for lookup.

@tsa321
Copy link
Contributor

tsa321 commented Sep 1, 2024

Proposal

updated

@s77rt I have updated my proposal with an alternative solution.

@daledah
Copy link
Contributor

daledah commented Sep 1, 2024

@s77rt

A file name is not a unique identifier and thus we cannot use it for lookup.

  • Thanks for your information, that makes sense.

It's worth mentioning that the targetAttachments values has a reportAction key which remains unchanged. We can make use of that.

  • I don't think we should use the reportAction key as suggested. Here's the issue with that approach:

Imagine user A sends a reportAction containing 3 images to user B, all linked to a single reportAction key.

User B opens the carousel to view the 2nd image.

Then, user A edits the reportAction and removes the 2nd image.

As a result, for user B, the carousel does not close.

@s77rt
Copy link
Contributor

s77rt commented Sep 1, 2024

@tsa321 Thanks, looks good overall

Edit: see #48173 (comment)

@s77rt
Copy link
Contributor

s77rt commented Sep 1, 2024

@daledah I'm not sure if multiple images in one report action is supported. So far I keep getting empty images, let me double check

@s77rt
Copy link
Contributor

s77rt commented Sep 1, 2024

@daledah It turns out we can send multiple images in one report action (although it seems a bit broken; the report action id for the second image is undefined)

![image1.jpeg](https://img.freepik.com/free-photo/autumn-tree-forest-leaves-bright-yellow-generative-ai_188544-12668.jpg)

![image2.jpeg](https://img.freepik.com/free-photo/photorealistic-view-tree-nature-with-branches-trunk_23-2151478039.jpg)

Thus we can't use the report action id for image identification either cc @tsa321

@tsa321
Copy link
Contributor

tsa321 commented Sep 1, 2024

Proposal

updated

on alternative solution 2 and 3.
Additionally, I have proposed a fix on the issue with incorrect reportActionID values (undefined) when a user sends an attachment with text or when an attachment is sent using markdown at the bottom of my proposal.

@daledah
Copy link
Contributor

daledah commented Sep 1, 2024

Updated proposal

  • Added more details about main solution, the idea is not changed.
  • Removed the alternative solution since it does not work.

@s77rt
Copy link
Contributor

s77rt commented Sep 26, 2024

@wildan-m The new behaviour seems to work well and does fix the issue. Let's go with alternative solution (3) without the isAttachmentSimilar and without prevInitialPageRef (it's same as attachments.findIndex(compareImage))

🎀 👀 🎀 C+ reviewed
Link to proposal

Copy link

melvin-bot bot commented Sep 26, 2024

Triggered auto assignment to @rlinoz, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Sep 26, 2024
Copy link

melvin-bot bot commented Sep 26, 2024

📣 @wildan-m 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@wildan-m
Copy link
Contributor

@s77rt The PR is ready #49832 Thanks!

@mallenexpensify
Copy link
Contributor

Note to self... PR hit staging on Oct 4th (posting as a reminder in case production deploy automation fails, it should be fixed now though)

Copy link

melvin-bot bot commented Oct 7, 2024

⚠️ Looks like this issue was linked to a Deploy Blocker here

If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

If a regression has occurred and you are the assigned CM follow the instructions here.

If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Oct 7, 2024
@melvin-bot melvin-bot bot changed the title [$250] mWeb - Attachment - Opened offline attachment directed to conversation page on online [HOLD for payment 2024-10-14] [$250] mWeb - Attachment - Opened offline attachment directed to conversation page on online Oct 7, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Oct 7, 2024
Copy link

melvin-bot bot commented Oct 7, 2024

Reviewing label has been removed, please complete the "BugZero Checklist".

Copy link

melvin-bot bot commented Oct 7, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.45-4 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2024-10-14. 🎊

For reference, here are some details about the assignees on this issue:

Copy link

melvin-bot bot commented Oct 7, 2024

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@s77rt] The PR that introduced the bug has been identified. Link to the PR:
  • [@s77rt] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
  • [@s77rt] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
  • [@s77rt] Determine if we should create a regression test for this bug.
  • [@s77rt] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@mallenexpensify] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@s77rt
Copy link
Contributor

s77rt commented Oct 11, 2024

@mallenexpensify
Copy link
Contributor

Contributor: @wildan-m paid $250 via Upwork
Contributor+: @s77rt due $250 via NewDot

I posted in the other issue to state we need a regression test there
#50296 (comment)

Thx!

@JmillsExpensify
Copy link

$250 approved for @s77rt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor
Projects
No open projects
Status: No status
Development

No branches or pull requests