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

Make sure that we reduce the unread message count when we delete an unread message #6746

Merged
merged 2 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,12 @@ function setNewMarkerPosition(reportID, sequenceNumber) {
function updateReportActionMessage(reportID, sequenceNumber, message) {
const actionToMerge = {};
actionToMerge[sequenceNumber] = {message: [message]};
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, actionToMerge);
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, actionToMerge).then(() => {
// If the message is deleted, update the last read in case the deleted message is being counted in the unreadActionCount
if (!message.text) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should check html instead of text just to be consistent across app.

setLocalLastRead(reportID, lastReadSequenceNumbers[reportID]);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this what the linter is looking for?

Suggested change
if (!message.text) {
setLocalLastRead(reportID, lastReadSequenceNumbers[reportID]);
}
if (message.text) {
return;
}
setLocalLastRead(reportID, lastReadSequenceNumbers[reportID]);

});

// If this is the most recent message, update the lastMessageText in the report object as well
if (sequenceNumber === reportMaxSequenceNumbers[reportID]) {
Expand Down
6 changes: 3 additions & 3 deletions src/libs/actions/ReportActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ function getDeletedCommentsCount(reportID, sequenceNumber) {
return 0;
}

return _.reduce(reportActions[reportID], (deletedMessages, action) => {
return _.reduce(reportActions[reportID], (numDeletedMessages, action) => {
if (action.actionName !== CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT || action.sequenceNumber <= sequenceNumber) {
return deletedMessages;
return numDeletedMessages;
}

// Empty ADDCOMMENT actions typically mean they have been deleted
const message = _.first(lodashGet(action, 'message', null));
const html = lodashGet(message, 'html', '');
return _.isEmpty(html) ? deletedMessages + 1 : deletedMessages;
return _.isEmpty(html) ? numDeletedMessages + 1 : numDeletedMessages;
}, 0);
}

Expand Down