feat: enhance message broadcasting to exclude sender's connection and improve IRC compliance

This commit is contained in:
HueByte
2026-07-17 17:05:03 +02:00
parent 953e081123
commit 96736d69df
9 changed files with 47 additions and 16 deletions
+1 -1
View File
@@ -103,7 +103,7 @@ public class ChatHub : Hub<IEchoHubClient>
{
try
{
var error = await _chatService.SendMessageAsync(CurrentUserId, CurrentUsername, channelName, content);
var error = await _chatService.SendMessageAsync(CurrentUserId, CurrentUsername, channelName, content, Context.ConnectionId);
if (error is not null)
await Clients.Caller.Error(error);
}
+2 -2
View File
@@ -151,7 +151,7 @@ public class ChatService : IChatService
_logger.LogInformation("{User} left channel '{Channel}'", username, channelName);
}
public async Task<string?> SendMessageAsync(Guid userId, string username, string channelName, string content)
public async Task<string?> SendMessageAsync(Guid userId, string username, string channelName, string content, string? originConnectionId = null)
{
channelName = channelName.ToLowerInvariant().Trim();
@@ -240,7 +240,7 @@ public class ChatService : IChatService
Embeds: embeds,
SenderDisplayName: sender?.DisplayName);
await BroadcastToAllAsync(b => b.SendMessageToChannelAsync(channelName, messageDto));
await BroadcastToAllAsync(b => b.SendMessageToChannelAsync(channelName, messageDto, originConnectionId));
_logger.LogDebug("{User} sent message in '{Channel}'", username, channelName);
return null;
@@ -20,7 +20,9 @@ public class SignalRBroadcaster : IChatBroadcaster
_presenceTracker = presenceTracker;
}
public Task SendMessageToChannelAsync(string channelName, MessageDto message)
// The exclusion only applies to the IRC gateway (SignalR clients render their own
// message from the broadcast echo), so the id is ignored here.
public Task SendMessageToChannelAsync(string channelName, MessageDto message, string? excludeConnectionId = null)
=> HubContext.Clients.Group(channelName).ReceiveMessage(message);
public Task SendUserJoinedAsync(string channelName, string username, UserPresenceDto? presence, string? excludeConnectionId = null)