fix: ghost channel when trying to join a channel that doesn't exist

This commit is contained in:
Stone_Red
2026-02-24 21:45:33 +01:00
parent 5391d2cb1c
commit 24a5bdb9a1
3 changed files with 10 additions and 10 deletions
+4 -8
View File
@@ -56,7 +56,7 @@ public class ChatHub : Hub<IEchoHubClient>
}
}
public async Task<List<MessageDto>> JoinChannel(string channelName)
public async Task<JoinChannelResult> JoinChannel(string channelName)
{
try
{
@@ -64,19 +64,15 @@ public class ChatHub : Hub<IEchoHubClient>
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}");
}
}