namespace SOR.Chat.Handlers; using Microsoft.EntityFrameworkCore; using SOR.Database.Contexts; using SOR.Database.Entities.Identity; /// /// Shared helpers for all chat message handlers. /// internal abstract class ChatHandlerBase { /// /// Batch-fetches display names for a set of account IDs from the identity DB. /// Returns a dictionary keyed by AccountId → DisplayName (or email fallback). /// protected static async Task> GetDisplayNamesAsync( SorIdentityDbContext identityDb, IEnumerable accountIds, CancellationToken ct) { var ids = accountIds.Distinct().ToList(); if (ids.Count == 0) return new Dictionary(); return await identityDb.Set() .Where(a => ids.Contains(a.Id)) .ToDictionaryAsync( a => a.Id, a => a.DisplayName ?? a.Email ?? a.Id.ToString(), ct); } /// /// Returns true if either player has blocked the other. /// protected static async Task IsBlockedEitherWayAsync( ChatDbContext chatDb, Guid playerA, Guid playerB, CancellationToken ct) => await chatDb.BlockedUsers.AnyAsync( b => (b.BlockerAccountId == playerA && b.BlockedAccountId == playerB) || (b.BlockerAccountId == playerB && b.BlockedAccountId == playerA), ct); }