Skip to content

Conversation

@mollup
Copy link

@mollup mollup commented Sep 5, 2025

…mplexity in Messaging.addMessage

P1B: Starter Task: Refactoring src/messaging/create.js: cleaning up error detection/handling in addMessage

1. Issue

Please provide a link to the associated GitHub issue:
#162

Link to the associated GitHub issue:
#162

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

What do you think this file does?
(Your answer does not have to be 100% correct; give a reasonable, evidence‑based guess.)
This file handles the private messaging/group chat creation feature of NodeBB, adding you to communicate between individual users.

What is the scope of your refactoring within that file?
(Name specific functions/blocks/regions touched.)
Cleaned up the Messaging.addMessage function by moving the error detection at the start of the function into a helper function.

Which Qlty‑reported issue did you address?
(Name the rule/metric and include the BEFORE value; e.g., “Cognitive Complexity 18 in render()”.)
Function complexity of 14 in addMessage

2. Refactoring

How did the specific issue you chose impact the codebase’s adaptability?
Error checking/handling in addMessage has one dedicated section; any situations where an error should occur will happen in the same location.

What changes did you make to resolve the issue?
Converted error handling into a helper function.

How do your changes improve adaptability? Did you consider alternatives?
Error checking/handling in addMessage has one dedicated section; any situations where an error should occur will happen in the same location. I did not really consider any alternatives.

3. Validation

How did you trigger the refactored code path from the UI?
Each time I send a message, it checks if the message flagged an error.

Attach a screenshot of the logs and UI demonstrating the trigger.
(Run ./nodebb log; include the relevant UI view. Temporary logs should be removed before final commit.)
console_log

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

@coveralls
Copy link

Pull Request Test Coverage Report for Build 17483643249

Details

  • 7 of 7 (100.0%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.003%) to 78.532%

Files with Coverage Reduction New Missed Lines %
src/messaging/create.js 1 86.32%
Totals Coverage Status
Change from base Build 17435863312: 0.003%
Covered Lines: 24697
Relevant Lines: 29611

💛 - Coveralls

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.

2 participants