Skip to content

refactor(client): split ChatMessage.fromJson into typed helpers#1107

Open
NC1107 wants to merge 1 commit into
mainfrom
refactor/chat-message-from-json-split
Open

refactor(client): split ChatMessage.fromJson into typed helpers#1107
NC1107 wants to merge 1 commit into
mainfrom
refactor/chat-message-from-json-split

Conversation

@NC1107
Copy link
Copy Markdown
Owner

@NC1107 NC1107 commented May 22, 2026

Clears SonarQube S3776 at chat_message.dart:165 (was CC=27) by breaking the system-event sentinel translator into four single-purpose static helpers. Each branch of the orchestrator now reads as a one-line dispatch.

Behind the scenes

  • translateSystemSentinel is now a flat dispatcher over the four known event tags; cognitive complexity drops to 4 (≤ 15 budget).
  • Extracted _parseUuidUsername to parse the <uuid>:<username> payload that every event tag shares.
  • Extracted _formatActiveEvent for "X joined" / "X left" style strings (first-person "You joined").
  • Extracted _formatPassiveEvent for "X was removed" / "X was banned" style strings (first-person "You were removed").
  • Extracted _subjectFor to centralise the self-vs-peer subject phrase rendering used by both active and passive events.
  • Public API unchanged: ChatMessage.fromServerJson, the ChatMessage constructor, and the JSON wire shape are untouched.

Tests: all 86 model + chat_provider_state_test cases pass (test/models/chat_message_test.dart, test/models/chat_message_extended_test.dart, test/providers/chat_provider_state_test.dart). dart format and flutter analyze --fatal-infos clean.

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