-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
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:
- Send 2 messages (message 1 and message 2) in a chat
- Delete the last message (message 2)
- 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: