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 room creation error #8725

Merged
merged 3 commits into from
Apr 26, 2022
Merged
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,8 @@ function createPolicyRoom(policyID, reportName, visibility) {
}
return fetchChatReportsByIDs([response.reportID]);
})
.then(([{reportID}]) => {
.then((response) => {
thesahindia marked this conversation as resolved.
Show resolved Hide resolved
const {reportID} = _.values(response)[0];
Copy link
Member

@rushatgabhane rushatgabhane Apr 21, 2022

Choose a reason for hiding this comment

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

  1. Question: Is a response always guaranteed?

  2. Avoid object destructuring for a single variable that you only use once. see style.md#destructuring

  3. Use _.firstfor accessing the first element of the array.

  4. Use lodashGet for accessing reportID, or we might crash the app.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this will meet all the conditions. It will set reportID as false if there's no response resulting in early return.
const reportID = lodashGet(_.first(_.values(chatReports)), 'reportID', false);

Copy link
Member

@rushatgabhane rushatgabhane Apr 21, 2022

Choose a reason for hiding this comment

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

Sound good. Just make sure that the default value is an empty string instead of false.

Thanks

Copy link
Member Author

Choose a reason for hiding this comment

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

@rushatgabhane, done ✔️

if (!reportID) {
Log.error('Unable to grab policy room after creation', reportID);
return;
Expand Down