Refactor (src/messaging/index.js): resolve complex binary expression in getPublicRooms() #150
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
P1B: Starter Task: Refactoring PR
1. Issue
Link to Issue
Full path to the refactored file:
src/messaging/index.js
What do you think this file does?
This file is the entry point for the messaging module that builds the messaging object with methods that handles the logic for "chats" in nodebb.
What is the scope of your refactoring within that file?
1. Factored out the complex binary expression in getPublicRooms function, using a additional helper function "canUserAccessRoom" that checks user permisssions to see if there are any rooms the current user can access.
Which Qlty‑reported issue did you address?
Complex binary expression: line 139
2. Refactoring
How did the specific issue you chose impact the codebase’s maintainability?
The creation of the helper function "canUserAccessRoom" factors out the boolean logic of checking room access for a user, which enables the code to be more modular. Messaging functions now need to simply call the helper function to do this, which follows the DRY principle.
What changes did you make to resolve the issue?
How do your changes improve maintainability? Did you consider alternatives?
This improves the readability and modularity of the codebase. Alternatives considered were using intermediate variables within the binary expression, but this did not really reduce the complexity of it.
3. Validation
How did you trigger the refactored code path from the UI?
Attach a screenshot of the logs and UI demonstrating the trigger.
Logs:

(you can seee that "Eugene" is printed to the console.)
Relevant UI:

qlty smells output:

(you can see that the "complex binary expression" report is no longer here).