Files
sor/Server/src/SOR.Chat/Handlers/ChatHandlerBase.cs
T
c6dc56a350 Add chat service, collection clone/tier rules, social graph
SOR.Chat (new project):
- 10 WebSocket message handlers: send, get_channels, get_messages,
  dm_open, friend_request, friend_respond, friend_remove, block,
  unblock, get_social
- Cursor-based pagination for message history
- Block checks on DM send and dm_open
- Social graph: friends / pending requests (in+out) / blocked list
- Batch identity DB lookups for display names

Collection updates:
- clone_deck handler (copy deck + re-validate)
- Tier-chain validation: deck ArchSpirit must be Tier 1 (hard rule);
  warn on Tier 2+ card without previous tier present (soft warning)
- Tier 2+ ArchSpirits now allowed in card list as ascension targets
- ValidationWarnings field added to DeckSummaryDto + DeckDetailDto

Database:
- CardDefinition.PreviousTierId self-reference FK for ascension chains
- FriendRequest + BlockedUser entities in chat schema
- ChatChannelType.System + FriendRequestStatus enum values
- Migrations: AddArchSpiritTierChain (catalog), AddSocialGraph (chat)

Admin portal:
- ChatOverview (/chat) — stats + channel list with type filter
- ChatChannelViewer (/chat/channel/{id}) — message history + system
  message compose for admins
- SocialModerationPage (/chat/social) — friend/block lookup + actions
- NavMenu: Chat section with Social Graph sub-item

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-02-25 13:16:43 -05:00

46 lines
1.5 KiB
C#

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