refactor(guild_chat): extract chat-user lookup to viewer repo; fix NEW-direction exclusivity

Add ChatUserProfile record and IViewerRepository.LoadChatProfilesAsync (AsNoTracking,
projects Name/EmblemId/CountryCode/Rank/DegreeId from Viewer+Info nav refs).
GuildChatController.Messages now injects IViewerRepository instead of SVSimDbContext;
calls LoadChatProfilesAsync to populate users[] (removes direct db access from controller).
GuildChatMessageRepository direction=2 (NEW): change >= start to > start (exclusive).
GuildChatPollTests updated to assert the start message is NOT returned by direction=NEW.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-27 14:51:44 -04:00
parent 358f43aa7a
commit a248c167e0
5 changed files with 74 additions and 29 deletions

View File

@@ -2,6 +2,17 @@ using SVSim.Database.Enums;
namespace SVSim.Database.Repositories.Viewer;
/// <summary>
/// Lightweight profile shape used by chat surfaces (guild_chat, gathering_chat).
/// Fields match the ChatUserDto wire shape.
/// </summary>
public record ChatUserProfile(
string Name,
long EmblemId,
string CountryCode,
int Rank,
int DegreeId);
public interface IViewerRepository
{
Task<Models.Viewer?> GetViewerBySocialConnection(SocialAccountType accountType, ulong socialId);
@@ -39,4 +50,11 @@ public interface IViewerRepository
/// ids with no matching row are absent from the result. Read-only (AsNoTracking).
/// </summary>
Task<Dictionary<long, string>> LoadDisplayNamesAsync(IReadOnlyCollection<long> viewerIds, CancellationToken ct = default);
/// <summary>
/// Batch-loads the <see cref="ChatUserProfile"/> fields for a set of viewer ids. Used by chat
/// surfaces (guild_chat, gathering_chat) to populate <c>users[]</c> without a direct DB context
/// in the controller. Ids with no matching row are absent from the result. Read-only (AsNoTracking).
/// </summary>
Task<IReadOnlyDictionary<long, ChatUserProfile>> LoadChatProfilesAsync(IReadOnlyCollection<long> viewerIds, CancellationToken ct = default);
}