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

Rename lastVisitedTimestamp to lastReadTimestamp #13128

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 7 additions & 7 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,16 @@ function isReportMessageAttachment({text, html}) {
}

/**
* Given a collection of reports returns them sorted by last visited
* Given a collection of reports returns them sorted by last read
*
* @param {Object} reports
* @returns {Array}
*/
function sortReportsByLastVisited(reports) {
function sortReportsByLastRead(reports) {
return _.chain(reports)
.toArray()
.filter(report => report && report.reportID && !isIOUReport(report))
.sortBy('lastVisitedTimestamp')
.sortBy('lastReadTimestamp')
.value();
}

Expand Down Expand Up @@ -240,13 +240,13 @@ function hasExpensifyGuidesEmails(emails) {
/**
* Given a collection of reports returns the most recently accessed one
*
* @param {Record<String, {lastVisitedTimestamp, reportID}>|Array<{lastVisitedTimestamp, reportID}>} reports
* @param {Record<String, {lastReadTimestamp, reportID}>|Array<{lastReadTimestamp, reportID}>} reports
* @param {Boolean} [ignoreDefaultRooms]
* @param {Object} policies
* @returns {Object}
*/
function findLastAccessedReport(reports, ignoreDefaultRooms, policies) {
let sortedReports = sortReportsByLastVisited(reports);
let sortedReports = sortReportsByLastRead(reports);

if (ignoreDefaultRooms) {
sortedReports = _.filter(sortedReports, report => !isDefaultRoom(report)
Expand Down Expand Up @@ -844,7 +844,7 @@ function buildOptimisticChatReport(
lastMessageText: null,
lastReadSequenceNumber: 0,
lastActionCreated: '',
lastVisitedTimestamp: 0,
lastReadTimestamp: 0,
maxSequenceNumber: 0,
notificationPreference,
oldPolicyName,
Expand Down Expand Up @@ -1135,7 +1135,7 @@ export {
findLastAccessedReport,
canEditReportAction,
canDeleteReportAction,
sortReportsByLastVisited,
sortReportsByLastRead,
isDefaultRoom,
isAdminRoom,
isAnnounceRoom,
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function requestMoney(report, amount, currency, recipientEmail, participant, com
key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`,
value: {
...chatReport,
lastVisitedTimestamp: Date.now(),
lastReadTimestamp: Date.now(),
lastReadSequenceNumber: newSequenceNumber,
maxSequenceNumber: newSequenceNumber,
lastMessageText: optimisticReportAction.message[0].text,
Expand Down Expand Up @@ -261,7 +261,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, amount, comment

groupChatReport.maxSequenceNumber = groupChatReportMaxSequenceNumber + 1;
groupChatReport.lastReadSequenceNumber = groupChatReportMaxSequenceNumber + 1;
groupChatReport.lastVisitedTimestamp = Date.now();
groupChatReport.lastReadTimestamp = Date.now();
groupChatReport.lastMessageText = groupIOUReportAction.message[0].text;
groupChatReport.lastMessageHtml = groupIOUReportAction.message[0].html;
groupChatReport.pendingFields = {
Expand Down
10 changes: 5 additions & 5 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function getSimplifiedReportObject(report) {
maxSequenceNumber: lodashGet(report, 'reportActionCount', 0),
participants: getParticipantEmailsFromReport(report),
isPinned: report.isPinned,
lastVisitedTimestamp: lodashGet(report, [
lastReadTimestamp: lodashGet(report, [
'reportNameValuePairs',
`lastRead_${currentUserAccountID}`,
'timestamp',
Expand Down Expand Up @@ -507,7 +507,7 @@ function openReport(reportID, participantList = [], newReportObject = {}) {
value: {
isLoadingReportActions: true,
isLoadingMoreReportActions: false,
lastVisitedTimestamp: Date.now(),
lastReadTimestamp: Date.now(),
lastReadSequenceNumber: getMaxSequenceNumber(reportID),
reportName: lodashGet(allReports, [reportID, 'reportName'], CONST.REPORT.DEFAULT_REPORT_NAME),
},
Expand Down Expand Up @@ -680,7 +680,7 @@ function readNewestAction(reportID) {
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
lastReadSequenceNumber: sequenceNumber,
lastVisitedTimestamp: Date.now(),
lastReadTimestamp: Date.now(),
},
}],
});
Expand All @@ -705,7 +705,7 @@ function markCommentAsUnread(reportID, sequenceNumber) {
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
lastReadSequenceNumber: newLastReadSequenceNumber,
lastVisitedTimestamp: Date.now(),
lastReadTimestamp: Date.now(),
},
}],
});
Expand Down Expand Up @@ -1238,7 +1238,7 @@ function viewNewReportAction(reportID, action) {
// but not necessarily reflected locally so we will update the lastReadSequenceNumber to mark the report as read.
updatedReportObject.maxSequenceNumber = action.sequenceNumber;
if (isFromCurrentUser) {
updatedReportObject.lastVisitedTimestamp = Date.now();
updatedReportObject.lastReadTimestamp = Date.now();
updatedReportObject.lastReadSequenceNumber = action.sequenceNumber;
}

Expand Down
2 changes: 1 addition & 1 deletion src/pages/reportPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default PropTypes.shape({
lastReadSequenceNumber: PropTypes.number,

/** The last time the report was visited */
lastVisitedTimestamp: PropTypes.number,
lastReadTimestamp: PropTypes.number,

/** The largest sequenceNumber on this report */
maxSequenceNumber: PropTypes.number,
Expand Down
26 changes: 13 additions & 13 deletions tests/unit/OptionsListUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('OptionsListUtils', () => {
// Given a set of reports with both single participants and multiple participants some pinned and some not
const REPORTS = {
1: {
lastVisitedTimestamp: 1610666739295,
lastReadTimestamp: 1610666739295,
lastActionCreated: '2022-11-22 03:26:02.015',
isPinned: false,
reportID: 1,
Expand All @@ -22,7 +22,7 @@ describe('OptionsListUtils', () => {
hasDraft: true,
},
2: {
lastVisitedTimestamp: 1610666739296,
lastReadTimestamp: 1610666739296,
lastActionCreated: '2022-11-22 03:26:02.016',
isPinned: false,
reportID: 2,
Expand All @@ -34,7 +34,7 @@ describe('OptionsListUtils', () => {

// This is the only report we are pinning in this test
3: {
lastVisitedTimestamp: 1610666739297,
lastReadTimestamp: 1610666739297,
lastActionCreated: '2022-11-22 03:26:02.170',
isPinned: true,
reportID: 3,
Expand All @@ -44,7 +44,7 @@ describe('OptionsListUtils', () => {
maxSequenceNumber: TEST_MAX_SEQUENCE_NUMBER,
},
4: {
lastVisitedTimestamp: 1610666739298,
lastReadTimestamp: 1610666739298,
lastActionCreated: '2022-11-22 03:26:02.180',
isPinned: false,
reportID: 4,
Expand All @@ -54,7 +54,7 @@ describe('OptionsListUtils', () => {
maxSequenceNumber: TEST_MAX_SEQUENCE_NUMBER,
},
5: {
lastVisitedTimestamp: 1610666739299,
lastReadTimestamp: 1610666739299,
lastActionCreated: '2022-11-22 03:26:02.019',
isPinned: false,
reportID: 5,
Expand All @@ -64,7 +64,7 @@ describe('OptionsListUtils', () => {
maxSequenceNumber: TEST_MAX_SEQUENCE_NUMBER,
},
6: {
lastVisitedTimestamp: 1610666739300,
lastReadTimestamp: 1610666739300,
lastActionCreated: '2022-11-22 03:26:02.020',
isPinned: false,
reportID: 6,
Expand All @@ -76,7 +76,7 @@ describe('OptionsListUtils', () => {

// Note: This report has the largest lastActionCreated
7: {
lastVisitedTimestamp: 1610666739301,
lastReadTimestamp: 1610666739301,
lastActionCreated: '2022-11-22 03:26:03.999',
isPinned: false,
reportID: 7,
Expand All @@ -88,7 +88,7 @@ describe('OptionsListUtils', () => {

// Note: This report has no lastActionCreated
8: {
lastVisitedTimestamp: 1610666739301,
lastReadTimestamp: 1610666739301,
lastActionCreated: '2022-11-22 03:26:02.000',
isPinned: false,
reportID: 8,
Expand All @@ -100,7 +100,7 @@ describe('OptionsListUtils', () => {

// Note: This report has an IOU
9: {
lastVisitedTimestamp: 1610666739302,
lastReadTimestamp: 1610666739302,
lastActionCreated: '2022-11-22 03:26:02.998',
isPinned: false,
reportID: 9,
Expand All @@ -114,7 +114,7 @@ describe('OptionsListUtils', () => {

// This report is an archived room – it does not have a name and instead falls back on oldPolicyName
10: {
lastVisitedTimestamp: 1610666739200,
lastReadTimestamp: 1610666739200,
lastActionCreated: '2022-11-22 03:26:02.001',
reportID: 10,
isPinned: false,
Expand Down Expand Up @@ -179,7 +179,7 @@ describe('OptionsListUtils', () => {
...REPORTS,

11: {
lastVisitedTimestamp: 1610666739302,
lastReadTimestamp: 1610666739302,
lastActionCreated: '2022-11-22 03:26:02.022',
isPinned: false,
reportID: 11,
Expand All @@ -193,7 +193,7 @@ describe('OptionsListUtils', () => {
const REPORTS_WITH_CHRONOS = {
...REPORTS,
12: {
lastVisitedTimestamp: 1610666739302,
lastReadTimestamp: 1610666739302,
lastActionCreated: '2022-11-22 03:26:02.022',
isPinned: false,
reportID: 12,
Expand All @@ -207,7 +207,7 @@ describe('OptionsListUtils', () => {
const REPORTS_WITH_RECEIPTS = {
...REPORTS,
13: {
lastVisitedTimestamp: 1610666739302,
lastReadTimestamp: 1610666739302,
lastActionCreated: '2022-11-22 03:26:02.022',
isPinned: false,
reportID: 13,
Expand Down