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

Fix crash on new chat creation due to undefined sequenceNumber #2721

Merged
merged 3 commits into from
May 7, 2021
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
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} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this :D It must have been causing a propType warning? I'm ashamed I didn't notice that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes forgot to mention that I fixed a few random propTypes things in this.

</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