[Core] Split PushLogic's message processing methods#74
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the PushLogic class by extracting its large switch-case message handling logic into separate handler classes, improving code maintainability and readability. Additionally, it makes the MessageBody property nullable to handle cases where it may not be present.
Key Changes:
- Refactored message processing from a monolithic switch-case into individual handler classes
- Implemented a handler registration system using reflection and frozen dictionaries for efficient lookup
- Made
MessageBodynullable inCommonMessageto handle missing message bodies gracefully
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Lagrange.Core/Message/MessagePacker.cs | Added null checks for MessageBody and null-forgiving operator usage |
| Lagrange.Core/Internal/Packets/Message/NTMessageCommon.cs | Changed MessageBody property to nullable type |
| Lagrange.Core/Internal/Logic/PushLogic.cs | Refactored from switch-case to handler-based architecture with reflection-based handler discovery |
| Lagrange.Core/Internal/Logic/MsgPushHandlers/RichTextMsgHandler.cs | Extracted rich text message handling logic into dedicated handler |
| Lagrange.Core/Internal/Logic/MsgPushHandlers/GroupReactionHandler.cs | Extracted group reaction handling logic into dedicated handler |
| Lagrange.Core/Internal/Logic/MsgPushHandlers/GroupNudgeHandler.cs | Extracted group nudge handling logic into dedicated handler |
| Lagrange.Core/Internal/Logic/MsgPushHandlers/GroupMemberIncreaseHandler.cs | Extracted group member increase handling logic into dedicated handler |
| Lagrange.Core/Internal/Logic/MsgPushHandlers/GroupMemberDecreaseHandler.cs | Extracted group member decrease handling logic into dedicated handler |
| Lagrange.Core/Internal/Logic/MsgPushHandlers/GroupJoinHandler.cs | Extracted group join handling logic into dedicated handler |
| Lagrange.Core/Internal/Logic/MsgPushHandlers/GroupInviteHandler.cs | Extracted group invite handling logic into dedicated handler |
| Lagrange.Core/Internal/Logic/MsgPushHandlers/FriendRequestHandler.cs | Extracted friend request handling logic into dedicated handler |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Motivation
Split the big switch-case in
PushLogic's Incomingmethod, to get better readability.More
Make
MessageBodynullable, it could be null in some cases