Files
SVSimServer/SVSim.Database/Repositories/Viewer/IViewerRepository.cs
gamer147 a248c167e0 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>
2026-06-27 14:51:44 -04:00

61 lines
2.8 KiB
C#

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);
Task<Models.Viewer?> GetViewerWithSocials(long id);
Task<Models.Viewer?> GetViewerByShortUdid(long shortUdid);
Task<Models.Viewer?> GetViewerByUdid(Guid udid);
Task<Models.Viewer> RegisterViewer(string displayName, SocialAccountType socialType,
ulong socialAccountIdentifier, ulong? shortUdid = null);
Task<Models.Viewer> RegisterAnonymousViewer(Guid udid);
Task LinkSteamToViewer(long viewerId, ulong steamId);
/// <summary>
/// Merges an anonymous viewer (just created by <c>/tool/signup</c> on a fresh UDID)
/// into a target viewer that the Steam ticket resolved to. Transfers the anonymous
/// viewer's UDID to the target, then deletes the anonymous viewer.
/// </summary>
Task MergeAnonymousViewerInto(long anonymousViewerId, long targetViewerId);
/// <summary>
/// Focused load for building a battle-node <c>MatchContext</c>: viewer + Info + Info's
/// equipped Emblem/Degree nav refs. Read-only (AsNoTracking). Returns null if the viewer
/// doesn't exist.
/// </summary>
Task<Models.Viewer?> LoadForMatchContextAsync(long viewerId);
/// <summary>Sets Viewer.GuildId to <paramref name="guildId"/>. No-op if the viewer does not exist.</summary>
Task SetGuildIdAsync(long viewerId, int guildId, CancellationToken ct = default);
/// <summary>Clears Viewer.GuildId to null. No-op if the viewer does not exist.</summary>
Task ClearGuildIdAsync(long viewerId, CancellationToken ct = default);
/// <summary>
/// Batch-loads <c>DisplayName</c> for a set of viewer ids. Returns a dictionary keyed by viewer id;
/// 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);
}