diff --git a/docs/changelog/v0.2.8.md b/docs/changelog/v0.2.8.md index 8cf62c3..7882ec8 100644 --- a/docs/changelog/v0.2.8.md +++ b/docs/changelog/v0.2.8.md @@ -15,6 +15,7 @@ - Fix thread safety — `_channelUsers` presence cache now protected by `Lock` to prevent races between SignalR events and background fetches - Fix `@mention` regex matching email addresses and `#channel` regex matching hex colors / issue numbers — both now use lookbehind and letter-requirement guards - Fix `ParseThemeColor` accepting non-hex characters — now validates `[0-9a-fA-F]` digits +- Fix ghost channel when trying to join a channel that doesn't exist ## New Features @@ -38,6 +39,7 @@ - Extract `IUserService`/`UserService` — consolidate user registration, authentication, and profile management into a dedicated service, eliminating duplicated logic between `AuthController` and `ChatService` - IRC gateway now checks ban status during authentication (previously skipped) - EchoHubSpace directory updates — server now only sends user count when it actually changes instead of every 30 seconds +- `ChatHub.JoinChannel` now returns `JoinChannelResult` instead of `List` to allow for better error handling ## Distribution diff --git a/src/EchoHub.Client/Services/EchoHubConnection.cs b/src/EchoHub.Client/Services/EchoHubConnection.cs index d59ec6b..c79fccd 100644 --- a/src/EchoHub.Client/Services/EchoHubConnection.cs +++ b/src/EchoHub.Client/Services/EchoHubConnection.cs @@ -136,8 +136,10 @@ public sealed class EchoHubConnection : IAsyncDisposable public async Task> JoinChannelAsync(string channelName) { - var messages = await _connection.InvokeAsync>("JoinChannel", channelName); - return DecryptMessages(messages); + var result = await _connection.InvokeAsync("JoinChannel", channelName); + if (!result.Success) + throw new InvalidOperationException(result.Error ?? "Failed to join channel."); + return DecryptMessages(result.History); } public async Task LeaveChannelAsync(string channelName) diff --git a/src/EchoHub.Core/DTOs/ChatDtos.cs b/src/EchoHub.Core/DTOs/ChatDtos.cs index 32cd71f..3a7e624 100644 --- a/src/EchoHub.Core/DTOs/ChatDtos.cs +++ b/src/EchoHub.Core/DTOs/ChatDtos.cs @@ -39,6 +39,8 @@ public record UpdateTopicRequest(string? Topic); public record SendUrlRequest(string Url); +public record JoinChannelResult(bool Success, List History, string? Error = null); + public record EmbedDto( string? SiteName, string? Title, diff --git a/src/EchoHub.Server/Hubs/ChatHub.cs b/src/EchoHub.Server/Hubs/ChatHub.cs index ee8b516..eb73a7a 100644 --- a/src/EchoHub.Server/Hubs/ChatHub.cs +++ b/src/EchoHub.Server/Hubs/ChatHub.cs @@ -56,7 +56,7 @@ public class ChatHub : Hub } } - public async Task> JoinChannel(string channelName) + public async Task JoinChannel(string channelName) { try { @@ -64,19 +64,15 @@ public class ChatHub : Hub Context.ConnectionId, CurrentUserId, CurrentUsername, channelName); if (error is not null) - { - await Clients.Caller.Error(error); - return []; - } + return new JoinChannelResult(false, [], error); await Groups.AddToGroupAsync(Context.ConnectionId, channelName.ToLowerInvariant().Trim()); - return history; + return new JoinChannelResult(true, history); } catch (Exception ex) { _logger.LogError(ex, "Error joining channel '{Channel}' for {User}", channelName, CurrentUsername); - await Clients.Caller.Error($"Failed to join channel: {ex.Message}"); - return []; + return new JoinChannelResult(false, [], $"Failed to join channel: {ex.Message}"); } }