| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- namespace Application.Abstractions.Chat;
- /// <summary>
- /// 채팅 룸 키 규약 (개미투자 D2) — roomKey = main | stock:{code}.
- /// channel:{sid} 는 기존 채널 채팅(비활성) 호환용 레거시 키 — JoinRoom 공개 계약에는 포함하지 않는다.
- /// </summary>
- public static class ChatRoomKeys
- {
- public const string Main = "main";
- public const string StockPrefix = "stock:";
- public const string ChannelPrefix = "channel:";
- public const int MaxLength = 20;
- public static bool IsStockRoom(string roomKey) => roomKey.StartsWith(StockPrefix, StringComparison.Ordinal);
- public static bool IsChannelRoom(string roomKey) => roomKey.StartsWith(ChannelPrefix, StringComparison.Ordinal);
- /// <summary>공개 계약 유효성 — main 또는 stock:{6자리 숫자} 만 허용</summary>
- public static bool IsValid(string? roomKey)
- {
- if (string.IsNullOrWhiteSpace(roomKey) || roomKey.Length > MaxLength)
- {
- return false;
- }
- if (roomKey == Main)
- {
- return true;
- }
- if (IsStockRoom(roomKey))
- {
- var code = roomKey[StockPrefix.Length..];
- return code is { Length: 6 } && code.All(char.IsAsciiDigit);
- }
- return false;
- }
- public static string ForStock(string code) => $"{StockPrefix}{code}";
- public static string ForChannel(string channelSID) => $"{ChannelPrefix}{channelSID}";
- }
|