Skip to content

[HOLD for payment 2021-12-13] [HOLD for payment 2021-12-06] Delete comment - Deleted comment is still visible on LHN #3293

Closed

Description

@isagoico

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


Expected Result:

LHN should show the message that was before the deleted message.

Actual Result:

LHN still shows the deleted comment. After refreshing the page, the email address of the sender is displayed.

Action Performed:

  1. Log in to e.cash
  2. Navigate to a conversation
  3. Send a message
  4. Delete the message
  5. Check the LHN
  6. Refresh the page

Workaround:

No need, visual issue.

Platform:

Where is this issue occurring?

Web ✔️
iOS✔️
Android ✔️
Desktop App (Don't have a mac to check)
Mobile Web ✔️

Version Number: 1.0.59-0

Logs: https://stackoverflow.com/c/expensify/questions/4856

Notes/Photos/Videos:

image

Grabando.187.mp4

Expensify/Expensify Issue URL:

view this job on upwork

View all open jobs on Upwork


From @rafecolton https://expensify.slack.com/archives/C01GTK53T8Q/p1622591805431300

Deleted comment shows as the recipient's email in the LHN. At first, the deleted comment still showed there, and then after a hard refresh, it just shows the email. Expected behavior is it would show the previous comment as though the deleted comment had never occurred.

Activity

  1. MelvinBot commented on Jun 2, 2021

    @MelvinBot
    Contributor

    Triggered auto assignment to @cead22 (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

  2. removed their assignment
    on Jun 2, 2021
  3. added
    External
    on Jun 2, 2021
  4. MelvinBot commented on Jun 2, 2021

    @MelvinBot
    Contributor

    Triggered auto assignment to @jboniface (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

  5. MelvinBot commented on Jun 2, 2021

    @MelvinBot
    Contributor

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

  6. added
    Weekly
    and removed
    Daily
    on Jun 2, 2021
  7. dklymenk commented on Jun 3, 2021

    @dklymenk
    Contributor

    There are 2 issues here (last message shown is not updated after deleting it and after reload it displays sender email) that need to be addressed separately, but I think a solution can be refactored into one new function partially.

    Addressing the refresh issue

    It is caused by the fact that function getSimplifiedReportObject, that is responsible for converting API data into object that is stored locally, gets last message by simply getting the last object value. This is not correct anymore because apparently a delete comment action just changes it's text to an empty string and it is still served by BE as an actual message.

    The reason it displays an email is as simple as it being a fallback in case message is empty.

    So my proposal here is to update the way lastReportAction is found here:

    https://github.com/Expensify/Expensify.cash/blob/8b979de2cf00deafbba85c5c139f6d78cd1fd3f2/src/libs/actions/Report.js#L148-L153

    with something like this:

        const reportActionKey = _.find(
            Object.keys(reportActionList).reverse(),
            key => reportActionList[key].message.html !== '',
        );
        const lastReportAction = reportActionList[reportActionKey];

    This will make sure last message has text (is not deleted).

    Addressing the on delete issue

    The root cause of this is the fact that data like lastMessageText, lastMessageTimestamp and lastActorEmail for a specific report are not updated on delete action. It is the way things work for updateReportActionMessage:

    https://github.com/Expensify/Expensify.cash/blob/8b979de2cf00deafbba85c5c139f6d78cd1fd3f2/src/libs/actions/Report.js#L488-L493

    and updateReportWithNewAction:

    https://github.com/Expensify/Expensify.cash/blob/8b979de2cf00deafbba85c5c139f6d78cd1fd3f2/src/libs/actions/Report.js#L528-L534

    but deleteReportComment function is missing that code, so I would need to implement something similar there:

        ...
        
        Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, reportActionsToMerge);
    
        // If this is the most recent message, update the lastMessage
        if (reportAction.sequenceNumber === reportMaxSequenceNumbers[reportID]) {
            #TODO figure out how to get reportActionList here
            const reportActionList = []; 
            const reportActionKey = _.find(
                Object.keys(reportActionList).reverse(),
                key => _.last(reportActionList[key].message).text !== '',
            );
            const lastReportAction = reportActionList[reportActionKey];
            const createTimestamp = lastReportAction ? lastReportAction.created : 0;
            const lastMessageTimestamp = moment.utc(createTimestamp).unix();
            const lastMessageText = lodashGet(lastReportAction, ['message', 'html'], '')
                .replace(/((<br[^>]*>)+)/gi, ' ')
                .replace(/(<([^>]+)>)/gi, '');
            const lastActorEmail = lodashGet(lastReportAction, 'accountEmail', '');
            Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {
                lastMessageText,
                lastMessageTimestamp,
                lastActorEmail,
            });
        }
            
         ...

    Refactoring

    I'm not exactly sure it would be worth it, but the code where I get last non-empty message text, timestamp and email can be refactored into a separate function getLastReportActionDetails(reportActionList) that would return an object with lastMessageText, lastMessageTimestamp and lastActorEmail. This function could be then used in both getSimplifiedReportObject and deleteReportComment.

    Summary

    I am yet to figure out how to get reportActionList in deleteReportComment function and I would also need to test if using sequence numbers to determine last message is good enough now that deleted messages can still have them, but otherwise that's it.

    P.S. What does LHN stand for? It is referenced in the issue, but I couldn't find a relevant meaning online. Judging by the context I would assume it's synonymous with Last Chat Message, but I better be sure. Thanks.

    EDIT: Fix grammar

  8. jboniface commented on Jun 3, 2021

    @jboniface

    @dklymenk LHN = left hand navigation

  9. 48 remaining items

  10. dklymenk commented on Nov 23, 2021

    @dklymenk
    Contributor

    Ok, so to fix the issue where it says "Comment deleted" when you create a new chat, I propose replacing

    // We are removing any html tags from the message html since we cannot access the text version of any comments as
    // the report only has the raw reportActionList and not the processed version returned by Report_GetHistory
    // We convert the line-breaks in html to space ' ' before striping the tags
    const lastMessageText = lastActionMessage
    .replace(/((<br[^>]*>)+)/gi, ' ')
    .replace(/(<([^>]+)>)/gi, '') || `[${translateLocal('common.deletedCommentMessage')}]`;

    with

        let lastMessageText;
        if (report.reportActionCount > 0) {
            // We are removing any html tags from the message html since we cannot access the text version of any comments as
            // the report only has the raw reportActionList and not the processed version returned by Report_GetHistory
            // We convert the line-breaks in html to space ' ' before striping the tags
            lastMessageText = lastActionMessage
                .replace(/((<br[^>]*>)+)/gi, ' ')
                .replace(/(<([^>]+)>)/gi, '') || `[${translateLocal('common.deletedCommentMessage')}]`;
        } else {
            lastMessageText = null;
        }

    This way if there are no report actions we default the LHN display to it's original behavior (showing email or phone).

    Now when it comes to showing user's email if all the messages are deleted it gets more complicated. Since we don't have access to all reports in that function it would mean somehow fetching all the reports in an async manner, which as far as I am aware is something we are trying to avoid. This is especially the case for something that would run for each of your chats. I don't think this is feasible unless we get this info from BE, so I suggest just apply the fix above to remedy the obvious bug I have overseen in my original PR.

    Thanks.

  11. NikkiWines commented on Nov 23, 2021

    @NikkiWines
    Contributor

    That looks good to me @dklymenk, I think it's fine to account for only the new chat scenario - if someone deletes all the chats in an existing message we can continue to show [Comment deleted]

  12. dklymenk commented on Nov 24, 2021

    @dklymenk
    Contributor

    I have submitted the fix #6458.

  13. added
    Weekly
    Awaiting Payment
    and removed on Nov 29, 2021
  14. botify commented on Nov 29, 2021

    @botify

    The solution for this issue has been 🚀 deployed to production 🚀 in version 1.1.16-10 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 2021-12-06. 🎊

  15. changed the title [-]Delete comment - Deleted comment is still visible on LHN[/-] [+][HOLD for payment 2021-12-06] Delete comment - Deleted comment is still visible on LHN[/+] on Nov 29, 2021
  16. removed their assignment
    on Nov 29, 2021
  17. added
    Weekly
    and removed
    Weekly
    on Dec 6, 2021
  18. changed the title [-][HOLD for payment 2021-12-06] Delete comment - Deleted comment is still visible on LHN[/-] [+][HOLD for payment 2021-12-13] [HOLD for payment 2021-12-06] Delete comment - Deleted comment is still visible on LHN[/+] on Dec 6, 2021
  19. botify commented on Dec 6, 2021

    @botify

    The solution for this issue has been 🚀 deployed to production 🚀 in version 1.1.17-7 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 2021-12-13. 🎊

  20. jboniface commented on Dec 13, 2021

    @jboniface

    paid with bonus

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

Metadata

Metadata

Labels

Awaiting PaymentEngineeringExternalReviewingWeekly

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions