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-11][$500] DeleteComment not working as expected #39432

Open
6 tasks done
roryabraham opened this issue Apr 2, 2024 · 65 comments
Open
6 tasks done
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Internal Requires API changes or must be handled by Expensify staff Weekly KSv2

Comments

@roryabraham
Copy link
Contributor

roryabraham commented Apr 2, 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!


Issue reported by: @shubham1206agra @rayane-djouah
Slack conversation: https://expensify.slack.com/archives/C01GTK53T8Q/p1711678317008389?thread_ts=1711571474.268739&cid=C01GTK53T8Q

Action Performed:

  1. Add a comment
  2. Create a thread in the same comment
  3. Add another comment inside the thread
  4. Try to delete the comment in the thread
  5. Observe that the DeleteComment API never runs inside the network tab
  6. Try to go to the same thread after navigating away

Expected Result:

The comment deleted in step 4 should be gone.

Actual Result:

The comment deleted in step 4 remains.

Workaround:

n/a

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

https://expensify.slack.com/archives/C01GTK53T8Q/p1712034411209499?thread_ts=1711571474.268739&cid=C01GTK53T8Q

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~014a6349d3b575268d
  • Upwork Job ID: 1775247417597710336
  • Last Price Increase: 2024-04-02
  • Automatic offers:
    • shubham1206agra | Contributor | 0
    • bernhardoj | Contributor | 0
Issue OwnerCurrent Issue Owner: @slafortune
@roryabraham roryabraham added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Apr 2, 2024
@roryabraham roryabraham self-assigned this Apr 2, 2024
Copy link

melvin-bot bot commented Apr 2, 2024

Triggered auto assignment to @slafortune (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@roryabraham roryabraham added the External Added to denote the issue can be worked on by a contributor label Apr 2, 2024
@melvin-bot melvin-bot bot changed the title DeleteComment not working as expected [$500] DeleteComment not working as expected Apr 2, 2024
Copy link

melvin-bot bot commented Apr 2, 2024

Job added to Upwork: https://www.upwork.com/jobs/~014a6349d3b575268d

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Apr 2, 2024
Copy link

melvin-bot bot commented Apr 2, 2024

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

@bernhardoj
Copy link
Contributor

Proposal

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

Delete comment request is never processed.

What is the root cause of that problem?

We include delete comment as part of the conflicting request and shouldIncludeCurrentRequest is also true (except thread parent)

App/src/libs/actions/Report.ts

Lines 1258 to 1267 in 879378f

getConflictingRequests: (persistedRequests) => {
const conflictingCommands = (
isDeletedParentAction
? [WRITE_COMMANDS.UPDATE_COMMENT]
: [WRITE_COMMANDS.ADD_COMMENT, WRITE_COMMANDS.ADD_ATTACHMENT, WRITE_COMMANDS.UPDATE_COMMENT, WRITE_COMMANDS.DELETE_COMMENT]
) as string[];
return persistedRequests.filter((request) => conflictingCommands.includes(request.command) && request.data?.reportActionID === reportActionID);
},
handleConflictingRequest: () => Onyx.update(successData),
shouldIncludeCurrentRequest: !isDeletedParentAction,

so when we do a delete comment, it conflicts with itself and is removed from the request list.

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

From my understanding, the purpose of getConflictingRequests is:

  1. Remove duplicate requests, such as reconnect app (which is achieved previously with idem key)
  2. Remove both add (optionally edit) and delete request of a same action as they cancel out each other

The 1st point works fine, but not with the 2nd. There are 2 issues with the 2nd point:

  1. The delete comment is always removed from the request list, but it should only be removed when there is an add request.
  2. If we add a comment while online, then edit and delete it while offline, both edit and delete command is removed from the request list and we optimistically remove the message.

So, here is what I propose:

  1. Replace shouldIncludeCurrentRequest with shouldExcludeCurrentRequestWhenConflict, the value stays the same
  2. Remove DELETE from the conflicting request list and conditionally add UPDATE if the action.isOptimisticAction is true
    : [WRITE_COMMANDS.ADD_COMMENT, WRITE_COMMANDS.ADD_ATTACHMENT, WRITE_COMMANDS.UPDATE_COMMENT, WRITE_COMMANDS.DELETE_COMMENT]
  3. In PersistedRequest.save, don't include the current request (requestToPersist) to the array yet, this means we don't need potentiallyConflictingRequests anymore. We will pass requests to getConflictingRequests
    function save(requestToPersist: Request) {
    const requests = [...persistedRequests, requestToPersist];
  4. Create a new variable called hasConflict with an initial value of false.
  5. Set it to true if conflictingRequests is not empty
  6. If shouldExcludeCurrentRequestWhenConflict is false or there is no conflict, add the current request to the request list
diff
diff --git a/src/libs/actions/PersistedRequests.ts b/src/libs/actions/PersistedRequests.ts
index 8adb598246..7e671e8cce 100644
--- a/src/libs/actions/PersistedRequests.ts
+++ b/src/libs/actions/PersistedRequests.ts
@@ -18,16 +18,15 @@ function clear() {
 }
 
 function save(requestToPersist: Request) {
-    const requests = [...persistedRequests, requestToPersist];
+    const requests = [...persistedRequests];
+    let hasConflict = false;
 
     // identify and handle any existing requests that conflict with the new one
-    const {getConflictingRequests, handleConflictingRequest, shouldIncludeCurrentRequest} = requestToPersist;
+    const {getConflictingRequests, handleConflictingRequest, shouldExcludeCurrentRequestWhenConflict} = requestToPersist;
     if (getConflictingRequests) {
-        // Get all the requests, potentially including the one we're adding, which will always be at the end of the array
-        const potentiallyConflictingRequests = shouldIncludeCurrentRequest ? requests : requests.slice(0, requests.length - 1);
-
         // Identify conflicting requests according to logic bound to the new request
-        const conflictingRequests = getConflictingRequests(potentiallyConflictingRequests);
+        const conflictingRequests = getConflictingRequests(requests);
+        hasConflict = conflictingRequests.length > 0;
 
         conflictingRequests.forEach((conflictingRequest) => {
             // delete the conflicting request
@@ -41,11 +40,15 @@ function save(requestToPersist: Request) {
         });
     }
 
+    if (!shouldExcludeCurrentRequestWhenConflict || !hasConflict) {
+        requests.push(requestToPersist)
+    }
+
     // Don't try to serialize conflict resolution functions
     persistedRequests = requests.map((request) => {
         delete request.getConflictingRequests;
         delete request.handleConflictingRequest;
-        delete request.shouldIncludeCurrentRequest;
+        delete request.shouldExcludeCurrentRequestWhenConflict;
         return request;
     });
 
diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts
index 775d2459b0..0ab400d523 100644
--- a/src/libs/actions/Report.ts
+++ b/src/libs/actions/Report.ts
@@ -1314,12 +1314,12 @@ function deleteReportComment(reportID: string, reportAction: ReportAction) {
                 const conflictingCommands = (
                     isDeletedParentAction
                         ? [WRITE_COMMANDS.UPDATE_COMMENT]
-                        : [WRITE_COMMANDS.ADD_COMMENT, WRITE_COMMANDS.ADD_ATTACHMENT, WRITE_COMMANDS.UPDATE_COMMENT, WRITE_COMMANDS.DELETE_COMMENT]
+                        : [WRITE_COMMANDS.ADD_COMMENT, WRITE_COMMANDS.ADD_ATTACHMENT, reportAction.isOptimisticAction ? WRITE_COMMANDS.UPDATE_COMMENT : '']
                 ) as string[];
                 return persistedRequests.filter((request) => conflictingCommands.includes(request.command) && request.data?.reportActionID === reportActionID);
             },
             handleConflictingRequest: () => Onyx.update(successData),
-            shouldIncludeCurrentRequest: !isDeletedParentAction,
+            shouldExcludeCurrentRequestWhenConflict: !isDeletedParentAction,
         },
     );
 }

@shubham1206agra
Copy link
Contributor

@bernhardoj Can you confirm that your proposal fixes #39218?

@ntdiary
Copy link
Contributor

ntdiary commented Apr 3, 2024

Hi, @shubham1206agra, are you also interested in taking over this issue? I'll be offline for the next 4 days, and won't be able to handle new issues. :)

@shubham1206agra
Copy link
Contributor

Ok no problem

@slafortune slafortune assigned shubham1206agra and unassigned ntdiary Apr 3, 2024
@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Apr 3, 2024
Copy link

melvin-bot bot commented Apr 3, 2024

📣 @shubham1206agra 🎉 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 📖

@slafortune
Copy link
Contributor

Thanks all! I've update the assignments 👍

@roryabraham roryabraham added the Help Wanted Apply this label when an issue is open to proposals by contributors label Apr 3, 2024
@roryabraham
Copy link
Contributor Author

roryabraham commented Apr 3, 2024

next step - waiting for an approved proposal. @bernhardoj's proposal LGTM, just want to answer @shubham1206agra's question first 👍🏼

I'd also love to see us add tests to cover the DeleteComment conflict resolution flow specifically 🙇🏼

@bernhardoj
Copy link
Contributor

I have checked and it's a different issue unrelated to the conflict resolution logic. I have posted a proposal there explaining the issue.

@shubham1206agra
Copy link
Contributor

@bernhardoj Sorry, but one last request. Can you check if any one of the proposal fixes #39307?

@bernhardoj
Copy link
Contributor

Yes, it will fix #39307

Screen.Recording.2024-04-05.at.14.22.18.mov

@shubham1206agra
Copy link
Contributor

@bernhardoj's proposal looks good.

🎀 👀 🎀 C+ Reviewed

@melvin-bot melvin-bot bot added the Overdue label Jul 22, 2024
@melvin-bot melvin-bot bot added Monthly KSv2 and removed Weekly KSv2 labels Aug 5, 2024
Copy link

melvin-bot bot commented Aug 5, 2024

This issue has not been updated in over 15 days. @slafortune, @roryabraham, @bernhardoj, @shubham1206agra eroding to Monthly issue.

P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

@melvin-bot melvin-bot bot removed the Overdue label Aug 5, 2024
@slafortune
Copy link
Contributor

This is waiting on Rory, so I don't feel the need to add another BZ person to this.
I'll be out until 8/21 and will check in on this then.

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Monthly KSv2 labels Aug 23, 2024
@slafortune
Copy link
Contributor

@roryabraham I am not able to recreate this any longer - following the steps above I was able to successfully delete the comment on the thread - still gone after navigating away and back.
image

@shubham1206agra
Copy link
Contributor

@slafortune Can I get paid for #39432 (comment)?

@slafortune
Copy link
Contributor

Whoops, I didn't mean to close, I meant to clarify that this isn't reproducible and that we are still waiting on the linked PR to finalize payments as noted here - #39432 (comment)

@slafortune slafortune reopened this Aug 23, 2024
@melvin-bot melvin-bot bot removed the Weekly KSv2 label Sep 16, 2024
Copy link

melvin-bot bot commented Sep 16, 2024

This issue has not been updated in over 15 days. @slafortune, @roryabraham, @bernhardoj, @shubham1206agra eroding to Monthly issue.

P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

@melvin-bot melvin-bot bot added the Monthly KSv2 label Sep 16, 2024
@roryabraham roryabraham added Weekly KSv2 Monthly KSv2 and removed Monthly KSv2 Reviewing Has a PR in review Weekly KSv2 labels Sep 16, 2024
@roryabraham
Copy link
Contributor Author

We've been actively developing/reviewing in #47913, seems we are close

@roryabraham roryabraham added Weekly KSv2 Reviewing Has a PR in review and removed Monthly KSv2 labels Oct 1, 2024
@roryabraham
Copy link
Contributor Author

#47913 was deployed to prod today. Not sure why this didn't get marked as awaiting payment, doing that manually

@roryabraham roryabraham added Awaiting Payment Auto-added when associated PR is deployed to production and removed Reviewing Has a PR in review labels Oct 4, 2024
@roryabraham roryabraham changed the title [$500] DeleteComment not working as expected [HOLD for payment 2024-10-11][$500] DeleteComment not working as expected Oct 4, 2024
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. Internal Requires API changes or must be handled by Expensify staff Weekly KSv2
Projects
No open projects
Status: No status
Development

No branches or pull requests

10 participants