-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Refactor Update Last Read #9529
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
Changes from all commits
fa49894
52cb17c
f16573a
148da7b
dda655e
df64eae
bccb6a8
d4d41d3
112c986
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,6 +118,21 @@ function getUnreadActionCount(report) { | |
| return Math.max(0, unreadActionCount); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the number of unread actions for a reportID | ||
| * | ||
| * @param {Number} reportID | ||
| * @param {Number} sequenceNumber | ||
| * @returns {Number} | ||
| */ | ||
| function getUnreadActionCountFromSequenceNumber(reportID, sequenceNumber) { | ||
| const reportMaxSequenceNumber = reportMaxSequenceNumbers[reportID]; | ||
|
|
||
| // Determine the number of unread actions by deducting the last read sequence from the total. If, for some reason, | ||
| // the last read sequence is higher than the actual last sequence, let's just assume all actions are read | ||
| return Math.max(reportMaxSequenceNumber - sequenceNumber - ReportActions.getDeletedCommentsCount(reportID, sequenceNumber), 0); | ||
| } | ||
|
|
||
| /** | ||
| * @param {Object} report | ||
| * @return {String[]} | ||
|
|
@@ -409,15 +424,10 @@ function setLocalIOUReportData(iouReportObject) { | |
| */ | ||
| function setLocalLastRead(reportID, lastReadSequenceNumber) { | ||
| lastReadSequenceNumbers[reportID] = lastReadSequenceNumber; | ||
| const reportMaxSequenceNumber = reportMaxSequenceNumbers[reportID]; | ||
|
|
||
| // Determine the number of unread actions by deducting the last read sequence from the total. If, for some reason, | ||
| // the last read sequence is higher than the actual last sequence, let's just assume all actions are read | ||
| const unreadActionCount = Math.max(reportMaxSequenceNumber - lastReadSequenceNumber - ReportActions.getDeletedCommentsCount(reportID, lastReadSequenceNumber), 0); | ||
|
|
||
| // Update the report optimistically. | ||
| Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, { | ||
| unreadActionCount, | ||
| unreadActionCount: getUnreadActionCountFromSequenceNumber(reportID, lastReadSequenceNumber), | ||
| lastVisitedTimestamp: Date.now(), | ||
| }); | ||
| } | ||
|
|
@@ -1084,6 +1094,81 @@ function updateLastReadActionID(reportID, sequenceNumber, manuallyMarked = false | |
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the latest page of report actions and updates the last read message | ||
| * | ||
| * @param {Number} reportID | ||
| */ | ||
| function openReport(reportID) { | ||
| const sequenceNumber = reportMaxSequenceNumbers[reportID]; | ||
|
marcaaron marked this conversation as resolved.
|
||
| lastReadSequenceNumbers[reportID] = sequenceNumber; | ||
| API.write('OpenReport', | ||
| { | ||
| reportID, | ||
| sequenceNumber, | ||
| }, | ||
| { | ||
| optimisticData: [{ | ||
| onyxMethod: 'merge', | ||
| key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, | ||
| value: { | ||
| lastVisitedTimestamp: Date.now(), | ||
|
madmax330 marked this conversation as resolved.
|
||
| unreadActionCount: getUnreadActionCountFromSequenceNumber(reportID, sequenceNumber), | ||
| }, | ||
| }], | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Marks the new report actions as read | ||
| * | ||
| * @param {Number} reportID | ||
| */ | ||
| function readNewestAction(reportID) { | ||
| const sequenceNumber = reportMaxSequenceNumbers[reportID]; | ||
| lastReadSequenceNumbers[reportID] = sequenceNumber; | ||
| API.write('ReadNewestAction', | ||
| { | ||
| reportID, | ||
| sequenceNumber, | ||
| }, | ||
| { | ||
| optimisticData: [{ | ||
| onyxMethod: 'merge', | ||
| key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, | ||
| value: { | ||
| lastVisitedTimestamp: Date.now(), | ||
| unreadActionCount: getUnreadActionCountFromSequenceNumber(reportID, sequenceNumber), | ||
| }, | ||
| }], | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Sets the last read comment on a report | ||
| * | ||
| * @param {Number} reportID | ||
| * @param {Number} sequenceNumber | ||
| */ | ||
| function markCommentAsUnread(reportID, sequenceNumber) { | ||
| lastReadSequenceNumbers[reportID] = sequenceNumber; | ||
| API.write('MarkCommentAsUnread', | ||
| { | ||
| reportID, | ||
| sequenceNumber, | ||
| }, | ||
| { | ||
| optimisticData: [{ | ||
| onyxMethod: 'merge', | ||
| key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, | ||
| value: { | ||
| lastVisitedTimestamp: Math.round(Date.now() / 1000), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB and sorry, as mentioned in that other comment I was wrong about this and |
||
| unreadActionCount: getUnreadActionCountFromSequenceNumber(reportID, sequenceNumber), | ||
| }, | ||
| }], | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Toggles the pinned state of the report. | ||
| * | ||
|
|
@@ -1535,4 +1620,7 @@ export { | |
| renameReport, | ||
| getLastReadSequenceNumber, | ||
| setIsComposerFullSize, | ||
| markCommentAsUnread, | ||
| readNewestAction, | ||
| openReport, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,7 +125,7 @@ class ReportActionsView extends React.Component { | |
| return; | ||
| } | ||
|
|
||
| Report.updateLastReadActionID(this.props.reportID); | ||
| Report.openReport(this.props.reportID); | ||
| }); | ||
|
|
||
| // If the reportID is not found then we have either not loaded this chat or the user is unable to access it. | ||
|
|
@@ -201,6 +201,7 @@ class ReportActionsView extends React.Component { | |
|
|
||
| componentDidUpdate(prevProps) { | ||
| if (prevProps.network.isOffline && !this.props.network.isOffline) { | ||
| Report.openReport(this.props.reportID); | ||
| this.fetchData(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noting: Once the report actions fetching stuff is refactored this call should not be here anymore. cc @sketchydroide |
||
| } | ||
|
|
||
|
|
@@ -242,14 +243,14 @@ class ReportActionsView extends React.Component { | |
| // When the last action changes, record the max action | ||
| // This will make the NEW marker line go away if you receive comments in the same chat you're looking at | ||
| if (shouldRecordMaxAction) { | ||
| Report.updateLastReadActionID(this.props.reportID); | ||
| Report.readNewestAction(this.props.reportID); | ||
| } | ||
| } | ||
|
|
||
| // Update the new marker position and last read action when we are closing the sidebar or moving from a small to large screen size | ||
| if (shouldRecordMaxAction && reportBecomeVisible) { | ||
| this.updateNewMarkerPosition(this.props.report.unreadActionCount); | ||
| Report.updateLastReadActionID(this.props.reportID); | ||
| Report.openReport(this.props.reportID); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -301,7 +302,6 @@ class ReportActionsView extends React.Component { | |
| */ | ||
| scrollToBottomAndUpdateLastRead() { | ||
| ReportScrollManager.scrollToBottom(); | ||
| Report.updateLastReadActionID(this.props.reportID); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -353,7 +353,7 @@ class ReportActionsView extends React.Component { | |
|
|
||
| // Only mark as read if the report is open | ||
| if (!this.props.isDrawerOpen) { | ||
| Report.updateLastReadActionID(this.props.reportID); | ||
| Report.openReport(this.props.reportID); | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.