Skip to content

Commit

Permalink
add created param to markCommentAsUnread
Browse files Browse the repository at this point in the history
  • Loading branch information
luacmartins committed Dec 7, 2022
1 parent 699d469 commit 368e48d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -690,13 +690,15 @@ function readNewestAction(reportID) {
* Sets the last read comment on a report
*
* @param {String} reportID
* @param {String} created
* @param {Number} sequenceNumber
*/
function markCommentAsUnread(reportID, sequenceNumber) {
function markCommentAsUnread(reportID, created, sequenceNumber) {
const newLastReadSequenceNumber = sequenceNumber - 1;
API.write('MarkAsUnread',
{
reportID,
created,
sequenceNumber,
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default [
successIcon: Expensicons.Checkmark,
shouldShow: type => type === CONTEXT_MENU_TYPES.REPORT_ACTION,
onPress: (closePopover, {reportAction, reportID}) => {
Report.markCommentAsUnread(reportID, reportAction.sequenceNumber);
Report.markCommentAsUnread(reportID, reportAction.created, reportAction.sequenceNumber);
if (closePopover) {
hideContextMenu(true, ReportActionComposeFocusManager.focus);
}
Expand Down
10 changes: 7 additions & 3 deletions tests/actions/ReportTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ describe('actions/Report', () => {
it('should be updated correctly when new comments are added, deleted or marked as unread', () => {
const REPORT_ID = 1;
let report;
const reportActionCreated = DateUtils.getDBTime();
Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`,
callback: val => report = val,
Expand Down Expand Up @@ -260,7 +261,7 @@ describe('actions/Report', () => {
person: [{type: 'TEXT', style: 'strong', text: 'Test User'}],
sequenceNumber: 1,
shouldShow: true,
created: DateUtils.getDBTime(),
created: reportActionCreated,
},
},
},
Expand All @@ -280,7 +281,7 @@ describe('actions/Report', () => {
expect(ReportUtils.isUnread(report)).toBe(false);

// When the user manually marks a message as "unread"
Report.markCommentAsUnread(REPORT_ID, 1);
Report.markCommentAsUnread(REPORT_ID, reportActionCreated, 1);
return waitForPromisesToResolve();
})
.then(() => {
Expand Down Expand Up @@ -354,16 +355,19 @@ describe('actions/Report', () => {
2: {
...USER_1_BASE_ACTION,
message: [{type: 'COMMENT', html: 'Current User Comment 1', text: 'Current User Comment 1'}],
created: DateUtils.getDBTime(),
sequenceNumber: 2,
},
3: {
...USER_1_BASE_ACTION,
message: [{type: 'COMMENT', html: 'Current User Comment 2', text: 'Current User Comment 2'}],
created: DateUtils.getDBTime(),
sequenceNumber: 3,
},
4: {
...USER_1_BASE_ACTION,
message: [{type: 'COMMENT', html: 'Current User Comment 3', text: 'Current User Comment 3'}],
created: DateUtils.getDBTime(),
sequenceNumber: 4,
},
},
Expand All @@ -383,7 +387,7 @@ describe('actions/Report', () => {
expect(ReportUtils.isUnread(report)).toBe(false);

// When the user manually marks a message as "unread"
Report.markCommentAsUnread(REPORT_ID, 3);
Report.markCommentAsUnread(REPORT_ID, USER_1_BASE_ACTION.created, 3);
return waitForPromisesToResolve();
})
.then(() => {
Expand Down

0 comments on commit 368e48d

Please sign in to comment.