Skip to content

[HOLD for payment 2024-01-17] [$500] Workspace-Edited&deleted message remains in # when back online when other login delete workspace #32529

Closed

Description

@izarutskaya

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: 1.4.8-0
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: Applause-Internal Team
Slack conversation: @

Action Performed:

  1. Navigate to staging.new.expensify..com
  2. Create workspace
  3. Go to #announce room
  4. Switch to offline mode
  5. Send 3 messages to the room
  6. Delete the first message and edit the second message
  7. From other device delete the workspace
  8. Come back online

Expected Result:

Messages added in offline mode should disappear when other user delete the workspace

Actual Result:

Only edited and deleted message appears in Announce when user come back online, after second login delete the workspace

Workaround:

Unknown

Platforms:

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

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

Screenshots/Videos

Bug6302382_1701809949392.Recording__1485.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0122148165eaf3972f
  • Upwork Job ID: 1732153136367722496
  • Last Price Increase: 2023-12-12
  • Automatic offers:
    • bernhardoj | Contributor | 28062675

Activity

  1. added
    External
    Daily
    Bug
    on Dec 5, 2023
  2. melvin-bot commented on Dec 5, 2023

    @melvin-bot

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

  3. changed the title [-]Workspace-Edited&deleted message remains in # when back online when other login delete workspace[/-] [+][$500] Workspace-Edited&deleted message remains in # when back online when other login delete workspace[/+] on Dec 5, 2023
  4. melvin-bot commented on Dec 5, 2023

    @melvin-bot
  5. melvin-bot commented on Dec 5, 2023

    @melvin-bot

    Bug0 Triage Checklist (Main S/O)

    • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
    • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
      • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
    • This bug is reproducible using the reproduction steps in the OP. S/O
      • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
      • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
    • This issue is filled out as thoroughly and clearly as possible
      • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
    • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync
  6. added
    Help Wanted
    on Dec 5, 2023
  7. melvin-bot commented on Dec 5, 2023

    @melvin-bot

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

  8. bernhardoj commented on Dec 6, 2023

    @bernhardoj
    Contributor

    Proposal

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

    Adding a message in a workspace chat while offline and then deleting the workspace from another device then coming back online will show an error message for each message we added. Pressing the close button of the error message will delete the message, but this doesn't work if we edit/delete the message while offline.

    What is the root cause of that problem?

    It's expected that adding/deleting/editing a message while offline but the chat is archived will throw an error. When we press the close error button, it will delete the message if the pending action is ADD.

    if (reportAction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
    // Delete the optimistic action
    Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`, {
    [reportAction.reportActionID]: null,
    });
    // If there's a linked transaction, delete that too
    const linkedTransactionID = ReportActionUtils.getLinkedTransactionID(originalReportID ?? '', reportAction.reportActionID);
    if (linkedTransactionID) {
    Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${linkedTransactionID}`, null);
    }
    // Delete the failed task report too
    const taskReportID = reportAction.message?.[0]?.taskReportID;
    if (taskReportID && ReportActionUtils.isCreatedTaskReportAction(reportAction)) {
    Report.deleteReport(taskReportID);
    }
    return;
    }

    We want to delete it because it is never added to the server because the chat is already archived. The problem is if we delete/edit the message, the pending action of ADD will be overwritten by UPDATE or DELETE.

    App/src/libs/actions/Report.js

    Lines 1276 to 1277 in 5a0b7fd

    [reportActionID]: {
    pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,

    pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,

    And if one of them fails, we clear the pending action.

    App/src/libs/actions/Report.js

    Lines 1311 to 1318 in 5a0b7fd

    const failureData = [
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`,
    value: {
    [reportActionID]: {
    ...originalReportAction,
    pendingAction: null,

    This is the limitation of having a single pending action.

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

    I think we can start introducing a pending action collection. To minimize changes, we can introduce a new property called pendingActions (with s). pendingActions will contain a list of pending actions (in a form of object) that the user made.

    To achieve that, let's add the pendingActions when adding, editing, and deleting the message/action optimistically.

    pendingActions: {
        [currentTime]: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
    },
    

    We also need to clear it when the request fails/success (for add message, we only clear it on success)

    pendingActions: {
        [currentTime]: null,
    },
    

    (add the above code in addActions, editReportComment, and deleteReportComment)

    We get the currentTime from DateUtils.getDBTime(). The reason I use currentTime is so that the pending action is sorted like a stack. I don't use array because merging an array will replace the previous array.

    After we have the new pendingActions, we can now check if the report action pendingActions contains an ADD action. If true, then we delete the optimistic report action.

    if (reportAction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {

    if (reportAction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD || Object.values(reportAction.pendingActions ?? {}).includes(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD)) {

    Last, to show the correct offline feedback, we should get the last pending action and pass it to OfflineWithFeedback.

    pendingAction={props.draftMessage ? null : props.action.pendingAction}

    pendingAction={props.draftMessage ? null : Object.values(lodashGet(props.action, 'pendingActions', {})).pop() || props.action.pendingAction}

    So, if we add, edit, and then delete a single message (pendingActions = ADD, UPDATE, DELETE) and all of them fails (pendingActions = ADD), we still have the pendingAction of ADD which will reduce the opacity of the message which currently doesn't happen on main.

    What alternative solutions did you explore? (Optional)

    Instead of having a pendingActions, we can introduce a new property called isOptimisticAction. We will set it to true optimistically when adding a new comment and clear it when it is successful.

  9. muttmuure commented on Dec 8, 2023

    @muttmuure
    Contributor

    Still being discussed

  10. 32 remaining items

  11. muttmuure commented on Jan 22, 2024

    @muttmuure
    Contributor

    C+ - @eVoloshchak $500

  12. muttmuure commented on Jan 22, 2024

    @muttmuure
    Contributor

    @bernhardoj paid on Upwork

  13. muttmuure commented on Jan 22, 2024

    @muttmuure
    Contributor

    Let us know if we should add a regression test

  14. eVoloshchak commented on Jan 23, 2024

    @eVoloshchak
    Contributor
    • The PR that introduced the bug has been identified. Link to the PR: there isn't a specific PR that caused this, this is a limitation of the original implementation we've had
    • 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: N/A
    • 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: don't think an additional discussion is needed here, this is an edge case
    • Determine if we should create a regression test for this bug.
      Is it easy to test for this bug? Yes
      Is the bug related to an important user flow? Yes
      Is it an impactful bug? No
      This is an edge case and the bug isn't impactful (users can continue using the app), but it's easy to test and, most importantly, messaging is integral part of the app, so I think we need to add a regression test for this
  15. eVoloshchak commented on Jan 23, 2024

    @eVoloshchak
    Contributor

    Regression Test Proposal

    1. Create a workspace if you don't have one
    2. Go to the #admins or #announce chat of the workspace
    3. Go offline
    4. Send 3 messages
    5. Edit the first message and delete the 2nd message
    6. From another device on the same account, delete that workspace
    7. Back to the main device, go back online
    8. Verify each message has an error message and a reduced opacity
    9. Close the error message one by one
    10. Verify the messages are removed one by one once you're dismissing the errors

    Do we agree 👍 or 👎

  16. JmillsExpensify commented on Jan 25, 2024

    @JmillsExpensify
    Contributor

    $500 approved for @eVoloshchak based on this comment.

  17. muttmuure commented on Jan 29, 2024

    @muttmuure
    Contributor

    I'll ask Applause for feedback on this: #32529 (comment)

  18. melvin-bot commented on Feb 1, 2024

    @melvin-bot

    @eVoloshchak, @marcaaron, @muttmuure, @bernhardoj Whoops! This issue is 2 days overdue. Let's get this updated quick!

  19. melvin-bot commented on Mar 23, 2024

    @melvin-bot

    ⚠️ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentBugDailyExternal

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions