mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-06 15:46:03 +02:00
deploy: 40aea9a04b
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
# HubConstants
|
||||
|
||||
> **File:** `src/EchoHub.Core/Constants/HubConstants.cs`
|
||||
> **Kind:** class
|
||||
|
||||
```csharp
|
||||
public static class HubConstants
|
||||
```
|
||||
|
||||
|
||||
HubConstants is a static container for global constants used by the chat hub to configure limits, paths, and feature boundaries. It provides values such as the hub path, default channel, and various size and constraint limits, ensuring consistent behavior across components and avoiding scattered magic numbers.
|
||||
|
||||
## Remarks
|
||||
HubConstants centralizes cross-cutting, tunable values so changes propagate consistently across messaging validation, content embedding, and endpoint configuration. Because these are compile-time constants, they are not sourced from runtime configuration; if you need different behavior per deployment, introduce a separate configuration mechanism rather than altering these constants at runtime.
|
||||
|
||||
## Notes
|
||||
- The distinction between MaxMessageNewlines (30) and MaxConsecutiveNewlines (1) matters: the first limits overall newline usage, the second limits consecutive newline runs.
|
||||
- Size limits are per-file (e.g., MaxImageSizeBytes, MaxAudioFileSizeBytes, MaxFileSizeBytes) and guide validation and storage decisions; never assume a single cap covers all attachment types.
|
||||
- IrcConnectionIdPrefix is used by the presence tracker to distinguish IRC gateway connections from native SignalR clients; ensure prefix checks rather than simple contains checks to avoid misclassification.
|
||||
@@ -0,0 +1,30 @@
|
||||
# MessageConventions
|
||||
|
||||
> **File:** `src/EchoHub.Core/Constants/MessageConventions.cs`
|
||||
> **Kind:** class
|
||||
|
||||
```csharp
|
||||
public static class MessageConventions
|
||||
```
|
||||
|
||||
|
||||
Cross-protocol message conventions are centralized in this static helper. It provides formatting and parsing for IRC CTCP ACTION-style messages, so /me-like actions render consistently across clients. Action messages are stored as the CTCP framing: 0x01 + "ACTION " + text + 0x01; MessageConventions.FormatAction(text) wraps a plain text string in that payload, and TryParseAction(content, out actionText) extracts the inner text when the content matches the framing. In end-to-end encrypted rooms the action marker travels with the text, preserving semantics.
|
||||
|
||||
## Remarks
|
||||
- This abstraction prevents scattering the CTCP ACTION framing constants across the codebase and offers a single source of truth for how action messages are stored and read.
|
||||
- It isolates the low-level framing from higher-level message handling, making testing and future changes safer and easier.
|
||||
- The parsing path uses ordinal string comparisons and explicitly requires both the proper prefix and suffix, plus non-empty inner text, to succeed.
|
||||
|
||||
## Example
|
||||
```csharp
|
||||
var action = MessageConventions.FormatAction("waves");
|
||||
if (MessageConventions.TryParseAction(action, out var text))
|
||||
{
|
||||
// text == "waves"
|
||||
}
|
||||
```
|
||||
|
||||
## Notes
|
||||
- TryParseAction(content, out actionText) returns true only if the content starts with ActionPrefix, ends with ActionSuffix, and the extracted inner text has length > 0; otherwise actionText is null and the method returns false.
|
||||
- The behavior relies on ordinal comparisons to avoid culture-related differences in prefix/suffix checks.
|
||||
- The inner action text can contain arbitrary characters; the method only enforces the framing and non-emptiness of the payload.
|
||||
@@ -0,0 +1,20 @@
|
||||
# ValidationConstants
|
||||
|
||||
> **File:** `src/EchoHub.Core/Constants/ValidationConstants.cs`
|
||||
> **Kind:** class
|
||||
|
||||
```csharp
|
||||
public static partial class ValidationConstants
|
||||
```
|
||||
|
||||
|
||||
ValidationConstants is a centralized, static container for validation constraints used throughout the EchoHub.Core domain. It defines reusable patterns for usernames, channel names, and hex color codes, as well as a set of length limits governing passwords, display names, bios, statuses, channel topics, and chat history. The included GeneratedRegex methods expose precompiled Regex instances derived from those patterns, enabling fast, consistent validation without incurring per-call regex compilation.
|
||||
|
||||
## Remarks
|
||||
ValidationConstants provides a single source of truth for input validation. By offloading regex compilation to source generation, it avoids runtime overhead while keeping the validation rules easily discoverable and consistent across the codebase.
|
||||
|
||||
The class is static and partial, so callers simply reference ValidationConstants.UsernameRegex(), ValidationConstants.ChannelNameRegex(), and ValidationConstants.HexColorRegex() to obtain ready-to-use Regex instances.
|
||||
|
||||
## Notes
|
||||
- GeneratedRegex provides compile-time-compiled Regex instances, which improves performance by avoiding repeated regex compilation at runtime.
|
||||
- Updating any constraint here propagates the change to all validation sites, ensuring consistency; do not duplicate rules elsewhere.
|
||||
Reference in New Issue
Block a user