Skip to content

[HOLD for payment 2021-12-13] [HOLD for payment 2021-12-06] After deleting the last message, editing the next last message doesn't update the message displayed in LHN #3743

@dklymenk

Description

@dklymenk

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


Action Performed:

  1. Send 2 messages (message 1 and message 2) in a chat
  2. Delete the last message (message 2)
  3. Edit the next last message (message 1)

Expected Result:

The LHN should be updated after editing last message regardless of your previous actions

Actual Result:

The LHN is not updated

Workaround:

Sending a new message and editing it updates LHN properly

Platform:

Where is this issue occurring?

Web ✔️
iOS ✔️
Android ✔️
Desktop App ✔️
Mobile Web ✔️

Proposal:

The issue is caused by unreliable values in reportMaxSequenceNumbers in src/libs/actions/Report.js. This array is not updated when you delete a message.

Here is how I would rewrite updateReportActionMessage to update the reportMaxSequenceNumbers.

function updateReportActionMessage(reportID, sequenceNumber, message) {
   const actionToMerge = {};
   actionToMerge[sequenceNumber] = {message: [message]};
   Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, actionToMerge);

   // If this is the most recent message
   if (sequenceNumber === reportMaxSequenceNumbers[reportID]) {
       // If message is deleted we need to update maxSequenceNumber
       if (message.html === '') {
           const connectionID = Onyx.connect({
               key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
               callback: (reportActionList) => {
                   // To make sure the callback is only called once
                   Onyx.disconnect(connectionID);

                   // Find last non-empty message
                   const lastReportAction = !_.isEmpty(reportActionList)
                       ? _.find(Object.values(reportActionList).reverse(),
                           reportAction => _.last(reportAction.message).html !== ''
                           && reportAction.created !== 'CREATED')
                       : null;

                   Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {
                       maxSequenceNumber: lastReportAction.sequenceNumber,
                   });
               },
           });
       } else {
           // Update the lastMessageText in the report object
           Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {
               lastMessageText: message.html,
           });
       }
   }
}

I would also need to check how other functions across the app interact with maxSequenceNumber to make sure reducing it doesn't break anything.

Version Number: 1.0.68-4
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation
Expensify/Expensify Issue URL:

View all open jobs on Upwork

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionExternalAdded to denote the issue can be worked on by a contributorPlanningChanges still in the thought processReviewingHas a PR in reviewWeeklyKSv2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions