Skip to content

Commit

Permalink
Style and format improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
puneetlath committed Dec 21, 2022
1 parent 2f60f15 commit d647d1e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
4 changes: 1 addition & 3 deletions src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,9 @@ function getLastVisibleMessageText(reportID, actionsToMerge = {}) {
}

/**
* Get the reportActionTimestamp of the last visible (non-deleted) comment on a report
*
* @param {String} reportID
* @param {Object} [actionsToMerge]
* @returns {String}
* @returns {Number}
*/
function getLastVisibleMessageTimestamp(reportID, actionsToMerge = {}) {
const actions = _.toArray(lodashMerge({}, allReportActions[reportID], actionsToMerge));
Expand Down
6 changes: 3 additions & 3 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,13 +685,13 @@ function readNewestAction(reportID, createdDate) {
* Sets the last read timestamp on a report
*
* @param {String} reportID
* @param {String} created
* @param {Number} reportActionTimestamp
*/
function markCommentAsUnread(reportID, created) {
function markCommentAsUnread(reportID, reportActionTimestamp) {
// We subtract 1 millisecond so that the lastReadTimestamp is updated to just before a given reportAction's created date
// For example, if we want to mark a report action with timestamp 1000 unread, we set the lastReadTimestamp to 999
// Since the report action with timestamp 1000 will be the first with a timestamp above 999, it's the first one that will be shown as unread
const lastReadTimestamp = moment.utc(created).valueOf() - 1;
const lastReadTimestamp = reportActionTimestamp - 1;
API.write('MarkAsUnread',
{
reportID,
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.created);
Report.markCommentAsUnread(reportID, reportAction.reportActionTimestamp);
if (closePopover) {
hideContextMenu(true, ReportActionComposeFocusManager.focus);
}
Expand Down
6 changes: 3 additions & 3 deletions src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ class ReportActionsView extends React.Component {
const didReportBecomeVisible = isReportFullyVisible && (didSidebarClose || didScreenSizeIncrease);
if (didReportBecomeVisible) {
this.setState({
newMarkerReportActionID: !ReportUtils.isUnread(this.props.report)
? null
: ReportUtils.getNewMarkerReportActionID(this.props.report, this.sortedAndFilteredReportActions),
newMarkerReportActionID: ReportUtils.isUnread(this.props.report)
? ReportUtils.getNewMarkerReportActionID(this.props.report, this.sortedAndFilteredReportActions)
: null,
});
this.openReportIfNecessary();
}
Expand Down
23 changes: 12 additions & 11 deletions tests/actions/ReportTest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import _ from 'underscore';
import Onyx from 'react-native-onyx';
import lodashGet from 'lodash/get';
import moment from 'moment';
import {
beforeEach, beforeAll, afterEach, jest, describe, it, expect,
} from '@jest/globals';
Expand Down Expand Up @@ -247,8 +248,8 @@ describe('actions/Report', () => {
lastMessageText: 'Comment 1',
lastActorEmail: USER_2_LOGIN,
lastReadSequenceNumber: 0,
lastMessageTimestamp: Date.parse(`${reportActionCreatedDate} UTC`),
lastReadTimestamp: Date.parse(`${reportActionCreatedDate} UTC`) - 1,
lastMessageTimestamp: moment.utc(reportActionCreatedDate).valueOf(),
lastReadTimestamp: moment.utc(reportActionCreatedDate).valueOf() - 1,
},
},
{
Expand All @@ -267,7 +268,7 @@ describe('actions/Report', () => {
shouldShow: true,
created: reportActionCreatedDate,
reportActionID: '1',
reportActionTimestamp: Date.parse(`${reportActionCreatedDate} UTC`),
reportActionTimestamp: moment.utc(reportActionCreatedDate).valueOf(),
},
},
},
Expand All @@ -289,13 +290,13 @@ describe('actions/Report', () => {
expect(report.lastReadTimestamp).toBeGreaterThanOrEqual(currentTimestamp);

// When the user manually marks a message as "unread"
Report.markCommentAsUnread(REPORT_ID, reportActionCreatedDate);
Report.markCommentAsUnread(REPORT_ID, moment.utc(reportActionCreatedDate).valueOf());
return waitForPromisesToResolve();
})
.then(() => {
// Then the report will be unread
expect(ReportUtils.isUnread(report)).toBe(true);
expect(report.lastReadTimestamp).toBe(Date.parse(`${reportActionCreatedDate} UTC`) - 1);
expect(report.lastReadTimestamp).toBe(moment.utc(reportActionCreatedDate).valueOf() - 1);

// When a new comment is added by the current user
currentTimestamp = Date.now();
Expand Down Expand Up @@ -378,7 +379,7 @@ describe('actions/Report', () => {
};
reportActionCreatedDate = DateUtils.getDBTime();
optimisticReportActions.value[4].created = reportActionCreatedDate;
optimisticReportActions.value[4].reportActionTimestamp = Date.parse(`${reportActionCreatedDate} UTC`);
optimisticReportActions.value[4].reportActionTimestamp = moment.utc(reportActionCreatedDate).valueOf();

// When we emit the events for these pending created actions to update them to not pending
channel.emit(Pusher.TYPE.ONYX_API_UPDATE, [
Expand All @@ -393,8 +394,8 @@ describe('actions/Report', () => {
lastMessageText: 'Current User Comment 3',
lastActorEmail: 'test@test.com',
lastReadSequenceNumber: 4,
lastMessageTimestamp: Date.parse(`${reportActionCreatedDate} UTC`),
lastReadTimestamp: Date.parse(`${reportActionCreatedDate} UTC`),
lastMessageTimestamp: moment.utc(reportActionCreatedDate).valueOf(),
lastReadTimestamp: moment.utc(reportActionCreatedDate).valueOf(),
},
},
optimisticReportActions,
Expand All @@ -409,17 +410,17 @@ describe('actions/Report', () => {
})
.then(() => {
// Then no change will occur
expect(report.lastReadTimestamp).toBe(Date.parse(`${reportActionCreatedDate} UTC`));
expect(report.lastReadTimestamp).toBe(moment.utc(reportActionCreatedDate).valueOf());
expect(ReportUtils.isUnread(report)).toBe(false);

// When the user manually marks a message as "unread"
Report.markCommentAsUnread(REPORT_ID, reportActionCreatedDate);
Report.markCommentAsUnread(REPORT_ID, moment.utc(reportActionCreatedDate).valueOf());
return waitForPromisesToResolve();
})
.then(() => {
// Then we should expect the report to be to be unread
expect(ReportUtils.isUnread(report)).toBe(true);
expect(report.lastReadTimestamp).toBe(Date.parse(`${reportActionCreatedDate} UTC`) - 1);
expect(report.lastReadTimestamp).toBe(moment.utc(reportActionCreatedDate).valueOf() - 1);

// If the user deletes the last comment after the lastReadTimestamp the lastMessageText will reflect the new last comment
Report.deleteReportComment(REPORT_ID, {...reportActions[4], sequenceNumber: 4, clientID: null});
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/UnreadIndicatorsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ describe('Unread Indicators', () => {
.then(() => {
// It's difficult to trigger marking a report comment as unread since we would have to mock the long press event and then
// another press on the context menu item so we will do it via the action directly and then test if the UI has updated properly
Report.markCommentAsUnread(REPORT_ID, reportAction3CreatedDate);
Report.markCommentAsUnread(REPORT_ID, moment.utc(reportAction3CreatedDate).valueOf());
return waitForPromisesToResolve();
})
.then(() => {
Expand Down Expand Up @@ -480,7 +480,7 @@ describe('Unread Indicators', () => {
expect(unreadIndicator).toHaveLength(0);

// Mark a previous comment as unread and verify the unread action indicator returns
Report.markCommentAsUnread(REPORT_ID, reportAction9CreatedDate);
Report.markCommentAsUnread(REPORT_ID, moment.utc(reportAction9CreatedDate).valueOf());
return waitForPromisesToResolve();
})
.then(() => {
Expand Down

0 comments on commit d647d1e

Please sign in to comment.