Skip to content

Commit

Permalink
Merge pull request #2721 from Expensify/marcaaron-updateLastRead
Browse files Browse the repository at this point in the history
Fix crash on new chat creation due to undefined sequenceNumber
  • Loading branch information
marcaaron authored May 7, 2021
2 parents 13d9a2a + 651801a commit 4253f79
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/libs/Navigation/AppNavigator/MainDrawerNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const getInitialReportScreenParams = _.once((reports) => {

// Fallback to empty if for some reason reportID cannot be derived - prevents the app from crashing
const reportID = lodashGet(last, 'reportID', '');
return {reportID};
return {reportID: String(reportID)};
});

const MainDrawerNavigator = (props) => {
Expand Down
7 changes: 7 additions & 0 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,13 @@ function addAction(reportID, text, file) {
* is last read (meaning that the entire report history has been read)
*/
function updateLastReadActionID(reportID, sequenceNumber) {
// If we aren't specifying a sequenceNumber and have no maxSequenceNumber for this report then we should not update
// the last read. Most likely, we have just created the report and it has no comments. But we should err on the side
// of caution and do nothing in this case.
if (_.isUndefined(sequenceNumber) && _.isUndefined(reportMaxSequenceNumbers[reportID])) {
return;
}

// Need to subtract 1 from sequenceNumber so that the "New" marker appears in the right spot (the last read
// action). If 1 isn't subtracted then the "New" marker appears one row below the action (the first unread action)
const lastReadSequenceNumber = (sequenceNumber - 1) || reportMaxSequenceNumbers[reportID];
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/sidebar/OptionRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ const OptionRow = ({
<View style={[styles.flexRow, styles.alignItemsCenter]}>
{option.hasDraftComment && (
<View style={styles.ml2}>
<Icon src={Pencil} height="16" width="16" />
<Icon src={Pencil} height={16} width={16} />
</View>
)}
{option.hasOutstandingIOU && (
<IOUBadge iouReportID={option.iouReportID} />
)}
{option.isPinned && (
<View style={styles.ml2}>
<Icon src={Pin} height="16" width="16" />
<Icon src={Pin} height={16} width={16} />
</View>
)}
</View>
Expand Down

0 comments on commit 4253f79

Please sign in to comment.