Files
sor/Server/src/SOR.Admin/Components/Pages/Chat/SocialModerationPage.razor
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

283 lines
10 KiB
Plaintext

@page "/chat/social"
@using Microsoft.EntityFrameworkCore
@using SOR.Database.Contexts
@using SOR.Database.Entities.Identity
@using SOR.Database.Enums
@inject ChatDbContext ChatDb
@inject SorIdentityDbContext IdentityDb
<PageTitle>Social Graph — SOR Admin</PageTitle>
<nav aria-label="breadcrumb" class="mb-3">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/chat" class="text-decoration-none">Chat</a></li>
<li class="breadcrumb-item active">Social Graph</li>
</ol>
</nav>
<h4 class="fw-bold mb-4">Social Graph</h4>
<!-- Player lookup -->
<div class="card bg-dark text-white border-secondary mb-4">
<div class="card-header fw-semibold">Player Lookup</div>
<div class="card-body">
<div class="input-group" style="max-width:420px">
<input type="text" class="form-control bg-dark text-white border-secondary"
placeholder="Account ID (GUID)..."
@bind="_lookupInput" @bind:event="oninput" @onkeydown="OnLookupKeyDown" />
<button class="btn btn-outline-secondary" @onclick="LookupAsync">Search</button>
</div>
@if (!string.IsNullOrEmpty(_lookupError))
{
<div class="text-danger small mt-1">@_lookupError</div>
}
</div>
</div>
@if (_loading)
{
<div class="text-muted">Loading...</div>
}
else if (_accountId.HasValue)
{
<div class="mb-3 text-muted small">
Showing social graph for <span class="font-monospace text-white">@_accountId</span>
@if (!string.IsNullOrEmpty(_accountName))
{
<span> — <strong class="text-white">@_accountName</strong></span>
}
</div>
<!-- Friends -->
<div class="card bg-dark text-white border-secondary mb-3">
<div class="card-header fw-semibold">
Friends <span class="badge bg-secondary ms-1">@_friends.Count</span>
</div>
<div class="card-body p-0">
<table class="table table-dark table-hover mb-0 small">
<thead><tr><th>Account ID</th><th>Name</th><th>Since</th><th></th></tr></thead>
<tbody>
@foreach (var f in _friends)
{
<tr>
<td class="font-monospace">@f.AccountId</td>
<td>@f.DisplayName</td>
<td class="text-muted">@f.Since.ToString("yyyy-MM-dd")</td>
<td>
<button class="btn btn-sm btn-outline-danger"
@onclick="() => RemoveFriendAsync(f.RowId)">
Remove
</button>
</td>
</tr>
}
@if (!_friends.Any())
{
<tr><td colspan="4" class="text-center text-muted py-2">No friends.</td></tr>
}
</tbody>
</table>
</div>
</div>
<!-- Pending requests -->
<div class="card bg-dark text-white border-secondary mb-3">
<div class="card-header fw-semibold">
Pending Friend Requests <span class="badge bg-secondary ms-1">@_pending.Count</span>
</div>
<div class="card-body p-0">
<table class="table table-dark table-hover mb-0 small">
<thead><tr><th>Direction</th><th>Other Account</th><th>Name</th><th>Since</th><th></th></tr></thead>
<tbody>
@foreach (var r in _pending)
{
<tr>
<td>
<span class="badge @(r.IsIncoming ? "bg-info text-dark" : "bg-secondary")">
@(r.IsIncoming ? "Incoming" : "Outgoing")
</span>
</td>
<td class="font-monospace">@r.AccountId</td>
<td>@r.DisplayName</td>
<td class="text-muted">@r.CreatedAt.ToString("yyyy-MM-dd")</td>
<td>
<button class="btn btn-sm btn-outline-danger"
@onclick="() => CancelRequestAsync(r.RowId)">
Cancel
</button>
</td>
</tr>
}
@if (!_pending.Any())
{
<tr><td colspan="5" class="text-center text-muted py-2">No pending requests.</td></tr>
}
</tbody>
</table>
</div>
</div>
<!-- Blocked -->
<div class="card bg-dark text-white border-secondary">
<div class="card-header fw-semibold">
Blocked Players <span class="badge bg-secondary ms-1">@_blocked.Count</span>
</div>
<div class="card-body p-0">
<table class="table table-dark table-hover mb-0 small">
<thead><tr><th>Account ID</th><th>Name</th><th>Blocked At</th><th></th></tr></thead>
<tbody>
@foreach (var b in _blocked)
{
<tr>
<td class="font-monospace">@b.AccountId</td>
<td>@b.DisplayName</td>
<td class="text-muted">@b.BlockedAt.ToString("yyyy-MM-dd")</td>
<td>
<button class="btn btn-sm btn-outline-secondary"
@onclick="() => UnblockAsync(b.RowId)">
Unblock
</button>
</td>
</tr>
}
@if (!_blocked.Any())
{
<tr><td colspan="4" class="text-center text-muted py-2">Not blocking anyone.</td></tr>
}
</tbody>
</table>
</div>
</div>
}
@code {
private bool _loading = false;
private string _lookupInput = "";
private string _lookupError = "";
private Guid? _accountId;
private string _accountName = "";
private record FriendRow(Guid RowId, Guid AccountId, string DisplayName, DateTimeOffset Since);
private record PendingRow(Guid RowId, Guid AccountId, string DisplayName, bool IsIncoming, DateTimeOffset CreatedAt);
private record BlockedRow(Guid RowId, Guid AccountId, string DisplayName, DateTimeOffset BlockedAt);
private List<FriendRow> _friends = new();
private List<PendingRow> _pending = new();
private List<BlockedRow> _blocked = new();
private async Task OnLookupKeyDown(KeyboardEventArgs e)
{
if (e.Key == "Enter") await LookupAsync();
}
private async Task LookupAsync()
{
_lookupError = "";
if (!Guid.TryParse(_lookupInput.Trim(), out var id))
{
_lookupError = "Invalid GUID.";
return;
}
_loading = true;
_accountId = id;
// Resolve display name
var account = await IdentityDb.Set<Account>()
.Where(a => a.Id == id)
.Select(a => new { a.DisplayName, a.Email })
.FirstOrDefaultAsync();
_accountName = account?.DisplayName ?? account?.Email ?? "";
// Load all social rows
var friendRows = await ChatDb.FriendRequests
.Where(f => f.RequesterAccountId == id || f.RecipientAccountId == id)
.ToListAsync();
var blockedRows = await ChatDb.BlockedUsers
.Where(b => b.BlockerAccountId == id)
.ToListAsync();
// Collect other account IDs for name resolution
var otherIds = new HashSet<Guid>();
foreach (var f in friendRows)
{
otherIds.Add(f.RequesterAccountId);
otherIds.Add(f.RecipientAccountId);
}
foreach (var b in blockedRows)
otherIds.Add(b.BlockedAccountId);
otherIds.Remove(id);
var names = new Dictionary<Guid, string>();
if (otherIds.Any())
{
names = await IdentityDb.Set<Account>()
.Where(a => otherIds.Contains(a.Id))
.ToDictionaryAsync(a => a.Id, a => a.DisplayName ?? a.Email ?? a.Id.ToString());
}
_friends = friendRows
.Where(f => f.Status == FriendRequestStatus.Accepted)
.Select(f =>
{
var other = f.RequesterAccountId == id ? f.RecipientAccountId : f.RequesterAccountId;
return new FriendRow(f.Id, other, names.GetValueOrDefault(other, other.ToString()), f.UpdatedAt);
})
.ToList();
_pending = friendRows
.Where(f => f.Status == FriendRequestStatus.Pending)
.Select(f =>
{
var isIncoming = f.RecipientAccountId == id;
var other = isIncoming ? f.RequesterAccountId : f.RecipientAccountId;
return new PendingRow(f.Id, other, names.GetValueOrDefault(other, other.ToString()), isIncoming, f.CreatedAt);
})
.ToList();
_blocked = blockedRows
.Select(b => new BlockedRow(
b.Id,
b.BlockedAccountId,
names.GetValueOrDefault(b.BlockedAccountId, b.BlockedAccountId.ToString()),
b.BlockedAt))
.ToList();
_loading = false;
}
private async Task RemoveFriendAsync(Guid rowId)
{
var row = await ChatDb.FriendRequests.FindAsync(rowId);
if (row != null)
{
ChatDb.FriendRequests.Remove(row);
await ChatDb.SaveChangesAsync();
}
_friends.RemoveAll(f => f.RowId == rowId);
}
private async Task CancelRequestAsync(Guid rowId)
{
var row = await ChatDb.FriendRequests.FindAsync(rowId);
if (row != null)
{
ChatDb.FriendRequests.Remove(row);
await ChatDb.SaveChangesAsync();
}
_pending.RemoveAll(r => r.RowId == rowId);
}
private async Task UnblockAsync(Guid rowId)
{
var row = await ChatDb.BlockedUsers.FindAsync(rowId);
if (row != null)
{
ChatDb.BlockedUsers.Remove(row);
await ChatDb.SaveChangesAsync();
}
_blocked.RemoveAll(b => b.RowId == rowId);
}
}