From 24a5bdb9a1cfb51d7b42a72866c3fbbac8e2e75a Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Tue, 24 Feb 2026 20:10:15 +0100 Subject: [PATCH 1/5] fix: ghost channel when trying to join a channel that doesn't exist --- src/EchoHub.Client/Services/EchoHubConnection.cs | 6 ++++-- src/EchoHub.Core/DTOs/ChatDtos.cs | 2 ++ src/EchoHub.Server/Hubs/ChatHub.cs | 12 ++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) 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..6a73e4d 100644 --- a/src/EchoHub.Core/DTOs/ChatDtos.cs +++ b/src/EchoHub.Core/DTOs/ChatDtos.cs @@ -15,6 +15,8 @@ public record MessageDto( long? AttachmentFileSize = null, List? Embeds = null); +public record JoinChannelResult(bool Success, List History, string? Error = null); + public record ChannelDto( Guid Id, string Name, 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}"); } } From b0adb55b8f032c51979ab7ba231f8cb610f9acaf Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Tue, 24 Feb 2026 20:14:49 +0100 Subject: [PATCH 2/5] refactor: Move JoinChannelResult to the correct position in ChatDtos.cs --- src/EchoHub.Core/DTOs/ChatDtos.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EchoHub.Core/DTOs/ChatDtos.cs b/src/EchoHub.Core/DTOs/ChatDtos.cs index 6a73e4d..3a7e624 100644 --- a/src/EchoHub.Core/DTOs/ChatDtos.cs +++ b/src/EchoHub.Core/DTOs/ChatDtos.cs @@ -15,8 +15,6 @@ public record MessageDto( long? AttachmentFileSize = null, List? Embeds = null); -public record JoinChannelResult(bool Success, List History, string? Error = null); - public record ChannelDto( Guid Id, string Name, @@ -41,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, From 29bfd87d8b41dbdd43d45e8e4d0a338489a5074d Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Tue, 24 Feb 2026 20:10:15 +0100 Subject: [PATCH 3/5] fix: ghost channel when trying to join a channel that doesn't exist --- src/EchoHub.Core/DTOs/ChatDtos.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/EchoHub.Core/DTOs/ChatDtos.cs b/src/EchoHub.Core/DTOs/ChatDtos.cs index 3a7e624..24bf514 100644 --- a/src/EchoHub.Core/DTOs/ChatDtos.cs +++ b/src/EchoHub.Core/DTOs/ChatDtos.cs @@ -15,6 +15,8 @@ public record MessageDto( long? AttachmentFileSize = null, List? Embeds = null); +public record JoinChannelResult(bool Success, List History, string? Error = null); + public record ChannelDto( Guid Id, string Name, From 3896640ac76bb110396ab8b757f006eef9e5a8e6 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Tue, 24 Feb 2026 20:14:49 +0100 Subject: [PATCH 4/5] refactor: Move JoinChannelResult to the correct position in ChatDtos.cs --- src/EchoHub.Core/DTOs/ChatDtos.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/EchoHub.Core/DTOs/ChatDtos.cs b/src/EchoHub.Core/DTOs/ChatDtos.cs index 24bf514..3a7e624 100644 --- a/src/EchoHub.Core/DTOs/ChatDtos.cs +++ b/src/EchoHub.Core/DTOs/ChatDtos.cs @@ -15,8 +15,6 @@ public record MessageDto( long? AttachmentFileSize = null, List? Embeds = null); -public record JoinChannelResult(bool Success, List History, string? Error = null); - public record ChannelDto( Guid Id, string Name, From d4f540285b7936470382856fdb1808983eec134c Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Tue, 24 Feb 2026 21:45:18 +0100 Subject: [PATCH 5/5] chore: add ghost channel fixes to changelog --- docs/changelog/v0.2.8.md | 2 ++ 1 file changed, 2 insertions(+) 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