Skip to content

Conversation

@aknickstar
Copy link

P1B: Starter Task: Refactoring PR

1. Issue

Link to the associated GitHub issue:
#60

Full path to the refactored file:
src/messaging/rooms.js

What do you think this file does?
I think this file handles actions regarding messaging someone within a chat room when you click "chat with this user" in NodeBB after you've looked at their profile. Once you click on the chat feature, it opens up a chat room for you two, and this file handles loading all the information in the room.

What is the scope of your refactoring within that file?
Within the Messaging.loadRoom async function, I refactored the binary expression originally on line 470 that I believe handles determining conditions on displaying the room upon load.

Which Qlty‑reported issue did you address?
470 Complex binary expression

2. Refactoring

The issue makes the codebase more maintainable as it splits up the binary expression into distinct parts, which helps us better read and understand the expression but also leaves the ability to edit these parts in the future if we want to change the individual conditions themselves later on.

I split the binary expression into its three main parts and placed them into separate variables. This allowed me to make sure the functionality stayed the same, but the very long binary statements were cut down into smaller chunks.

The changes improves maintainability since it will speed up the process of comprehending and making changes to this conditional in the future. I considered alternatives like splitting into multiple if statements, but I thought that just breaking down the conditional into separate variables would be cleaner and easier to read.

3. Validation

I created a new user in the system, and then as admin I added that user to the Global Moderators group. Then, as the new user, I went to the group and clicked on the admin's user profile, then navigated to "chat with this user" and clicked on that button. That popped up a new chat room and ran the print statements that I had put in my code.

Project 1B - print statements and refactored code chat room

Attach a screenshot of qlty smells --no-snippets <full/path/to/file.js> showing fewer reported issues after the changes.

qlty smells after refactoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant