🐛 Trying to fix chat response missing sender

This commit is contained in:
LittleSheep 2025-06-01 03:22:11 +08:00
parent 7dee2a15e7
commit 02ae634690

View File

@ -50,6 +50,8 @@ public class ChatService(
} }
}); });
message.Sender = sender;
message.ChatRoom = room;
return message; return message;
} }
@ -60,6 +62,9 @@ public class ChatService(
string type = WebSocketPacketType.MessageNew string type = WebSocketPacketType.MessageNew
) )
{ {
message.Sender = sender;
message.ChatRoom = room;
using var scope = scopeFactory.CreateScope(); using var scope = scopeFactory.CreateScope();
var scopedWs = scope.ServiceProvider.GetRequiredService<WebSocketService>(); var scopedWs = scope.ServiceProvider.GetRequiredService<WebSocketService>();
var scopedNty = scope.ServiceProvider.GetRequiredService<NotificationService>(); var scopedNty = scope.ServiceProvider.GetRequiredService<NotificationService>();
@ -101,16 +106,15 @@ public class ChatService(
List<Account.Account> accountsToNotify = []; List<Account.Account> accountsToNotify = [];
foreach (var member in members) foreach (var member in members)
{ {
// Send WebSocket packet if (member.Account.Id == sender.AccountId) continue;
scopedWs.SendPacketToAccount(member.AccountId, new WebSocketPacket scopedWs.SendPacketToAccount(member.AccountId, new WebSocketPacket
{ {
Type = type, Type = type,
Data = message Data = message
}); });
// Only add accounts that aren't null accountsToNotify.Add(member.Account);
if (member.Account.Id != sender.AccountId)
accountsToNotify.Add(member.Account);
} }
logger.LogInformation($"Trying to deliver message to {accountsToNotify.Count} accounts..."); logger.LogInformation($"Trying to deliver message to {accountsToNotify.Count} accounts...");