Structured ability builder UI + chat moderation
AbilityBuilder: - Replace all raw JSON textareas with structured per-type editors - Cost editor: Add/remove list with type dropdown + amount input (8 cost types) - Activation & action condition editors: grouped type dropdown (Turn/Timing, Unit, Player, Tile, Battlefield, Composite) + Subject select + per-type inline fields for every condition (N inputs, affinity/ownership/comparator selects, etc.) - Effect fields: dedicated labeled inputs for all 59 effect types — Amount, BypassDefense, Tiles, BlockedDamage, Direction, Duration, Player, Affinity, Tag, AbilityRef, StatTarget, Multiplier, etc.; raw JSON textarea kept only for AddAbility/ApplyOnEvent/SummonToken ChatChannelViewer: - Add "Send as Admin" compose panel (message attributed to logged-in admin account) alongside the existing System message panel - Add Delete (trash) button per message row for soft-delete (IsDeleted=true) - Add Restore button on deleted messages to reverse the soft-delete 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>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,14 @@
|
||||
@page "/chat/channel/{ChannelId:guid}"
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@using SOR.Database.Contexts
|
||||
@using SOR.Database.Entities.Chat
|
||||
@using SOR.Database.Entities.Identity
|
||||
@inject ChatDbContext ChatDb
|
||||
@inject SorIdentityDbContext IdentityDb
|
||||
@inject UserManager<Account> UserManager
|
||||
@inject AuthenticationStateProvider AuthState
|
||||
|
||||
<PageTitle>Channel Viewer — SOR Admin</PageTitle>
|
||||
|
||||
@@ -36,29 +40,68 @@ else
|
||||
<div class="text-muted small">Created @_channel.CreatedAt.ToString("yyyy-MM-dd HH:mm")</div>
|
||||
</div>
|
||||
|
||||
<!-- System message compose (admins only) -->
|
||||
@if (_channel.ChannelType != SOR.Database.Enums.ChatChannelType.Match)
|
||||
{
|
||||
<div class="card bg-dark text-white border-secondary mb-4">
|
||||
<div class="card-header fw-semibold text-danger border-bottom border-secondary">
|
||||
<i class="bi bi-megaphone me-1"></i>Post System Message
|
||||
<div class="row g-3 mb-4">
|
||||
<!-- System message -->
|
||||
<div class="col-md-6">
|
||||
<div class="card bg-dark text-white border-secondary h-100">
|
||||
<div class="card-header fw-semibold text-danger border-bottom border-secondary">
|
||||
<i class="bi bi-megaphone me-1"></i>Post System Message
|
||||
<small class="text-white-50 ms-2">shows as [System]</small>
|
||||
</div>
|
||||
<div class="card-body d-flex flex-column">
|
||||
<textarea class="form-control bg-dark text-white border-secondary mb-2 flex-grow-1"
|
||||
rows="2" placeholder="System message content..."
|
||||
@bind="_systemMessageText" maxlength="500"></textarea>
|
||||
@if (!string.IsNullOrEmpty(_systemError))
|
||||
{
|
||||
<div class="text-danger small mb-2">@_systemError</div>
|
||||
}
|
||||
@if (_systemSuccess)
|
||||
{
|
||||
<div class="text-success small mb-2">Message posted.</div>
|
||||
}
|
||||
<div>
|
||||
<button class="btn btn-sm btn-danger" @onclick="PostSystemMessageAsync"
|
||||
disabled="@_posting">
|
||||
@(_posting ? "Posting..." : "Post")
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<textarea class="form-control bg-dark text-white border-secondary mb-2"
|
||||
rows="2" placeholder="System message content..."
|
||||
@bind="_systemMessageText" maxlength="500"></textarea>
|
||||
@if (!string.IsNullOrEmpty(_systemError))
|
||||
{
|
||||
<div class="text-danger small mb-2">@_systemError</div>
|
||||
}
|
||||
@if (_systemSuccess)
|
||||
{
|
||||
<div class="text-success small mb-2">Message posted.</div>
|
||||
}
|
||||
<button class="btn btn-sm btn-danger" @onclick="PostSystemMessageAsync"
|
||||
disabled="@_posting">
|
||||
@(_posting ? "Posting..." : "Post")
|
||||
</button>
|
||||
|
||||
<!-- Admin message -->
|
||||
<div class="col-md-6">
|
||||
<div class="card bg-dark text-white border-secondary h-100">
|
||||
<div class="card-header fw-semibold text-warning border-bottom border-secondary">
|
||||
<i class="bi bi-person-badge me-1"></i>Send as Admin
|
||||
@if (_adminDisplayName != null)
|
||||
{
|
||||
<small class="text-white-50 ms-2">@_adminDisplayName</small>
|
||||
}
|
||||
</div>
|
||||
<div class="card-body d-flex flex-column">
|
||||
<textarea class="form-control bg-dark text-white border-secondary mb-2 flex-grow-1"
|
||||
rows="2" placeholder="Admin message content..."
|
||||
@bind="_adminMessageText" maxlength="500"></textarea>
|
||||
@if (!string.IsNullOrEmpty(_adminError))
|
||||
{
|
||||
<div class="text-danger small mb-2">@_adminError</div>
|
||||
}
|
||||
@if (_adminSuccess)
|
||||
{
|
||||
<div class="text-success small mb-2">Message sent.</div>
|
||||
}
|
||||
<div>
|
||||
<button class="btn btn-sm btn-warning" @onclick="PostAdminMessageAsync"
|
||||
disabled="@(_postingAdmin || _adminAccountId == null)">
|
||||
@(_postingAdmin ? "Sending..." : "Send")
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -73,25 +116,48 @@ else
|
||||
<table class="table table-dark table-hover mb-0 small">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:160px">Sent</th>
|
||||
<th style="width:180px">Sender</th>
|
||||
<th style="width:150px">Sent</th>
|
||||
<th style="width:170px">Sender</th>
|
||||
<th>Content</th>
|
||||
<th style="width:80px">Deleted</th>
|
||||
<th style="width:100px"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var m in _messages)
|
||||
{
|
||||
<tr class="@(m.IsDeleted ? "text-muted" : "")">
|
||||
<tr class="@(m.IsDeleted ? "opacity-50" : "")">
|
||||
<td class="font-monospace">@m.SentAt.ToString("MM-dd HH:mm:ss")</td>
|
||||
<td>
|
||||
<span class="font-monospace">@(_senderNames.GetValueOrDefault(m.SenderAccountId, m.SenderAccountId.ToString()[..8]))</span>
|
||||
<span class="font-monospace">
|
||||
@(_senderNames.GetValueOrDefault(m.SenderAccountId, m.SenderAccountId.ToString()[..8]))
|
||||
</span>
|
||||
</td>
|
||||
<td>@(m.IsDeleted ? "[deleted]" : m.Content)</td>
|
||||
<td>
|
||||
@if (m.IsDeleted)
|
||||
{
|
||||
<span class="badge bg-secondary">yes</span>
|
||||
<span class="text-muted fst-italic">[deleted]</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
@m.Content
|
||||
}
|
||||
</td>
|
||||
<td class="text-end">
|
||||
@if (m.IsDeleted)
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-secondary py-0 px-1"
|
||||
title="Restore message"
|
||||
@onclick="() => ToggleDeleteAsync(m, false)">
|
||||
<i class="bi bi-arrow-counterclockwise"></i>
|
||||
</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-danger py-0 px-1"
|
||||
title="Delete message"
|
||||
@onclick="() => ToggleDeleteAsync(m, true)">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
@@ -120,21 +186,25 @@ else
|
||||
@code {
|
||||
[Parameter] public Guid ChannelId { get; set; }
|
||||
|
||||
private bool _loading = true;
|
||||
private bool _loadingMore = false;
|
||||
private bool _posting = false;
|
||||
private bool _loading = true;
|
||||
private bool _loadingMore = false;
|
||||
private bool _posting = false;
|
||||
private bool _postingAdmin = false;
|
||||
private bool _systemSuccess = false;
|
||||
private bool _adminSuccess = false;
|
||||
private string _systemError = "";
|
||||
private string _adminError = "";
|
||||
private string _systemMessageText = "";
|
||||
private string _adminMessageText = "";
|
||||
private string? _adminDisplayName;
|
||||
private Guid? _adminAccountId;
|
||||
private ChatChannel? _channel;
|
||||
private List<ChatMessage> _messages = new();
|
||||
private List<ChatMessage> _messages = new();
|
||||
private Dictionary<Guid, string> _senderNames = new();
|
||||
private bool _hasMore = false;
|
||||
|
||||
private const int PageSize = 50;
|
||||
|
||||
// Sentinel: a fixed Guid used as the "system" sender for admin-injected messages.
|
||||
// All-zeros so it's obvious in the DB this was a server-posted message.
|
||||
private static readonly Guid SystemSenderId = Guid.Empty;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
@@ -149,6 +219,19 @@ else
|
||||
return;
|
||||
}
|
||||
|
||||
// Resolve the logged-in admin's account for attributed sends
|
||||
var authState = await AuthState.GetAuthenticationStateAsync();
|
||||
var email = authState.User.Identity?.Name;
|
||||
if (email != null)
|
||||
{
|
||||
var account = await UserManager.FindByNameAsync(email);
|
||||
if (account != null)
|
||||
{
|
||||
_adminAccountId = account.Id;
|
||||
_adminDisplayName = account.DisplayName ?? account.Email;
|
||||
}
|
||||
}
|
||||
|
||||
await LoadPageAsync(null);
|
||||
_loading = false;
|
||||
}
|
||||
@@ -196,7 +279,6 @@ else
|
||||
foreach (var kv in found)
|
||||
_senderNames[kv.Key] = kv.Value;
|
||||
|
||||
// Mark system messages
|
||||
if (!_senderNames.ContainsKey(SystemSenderId))
|
||||
_senderNames[SystemSenderId] = "[System]";
|
||||
}
|
||||
@@ -229,15 +311,62 @@ else
|
||||
ChatDb.Messages.Add(msg);
|
||||
await ChatDb.SaveChangesAsync();
|
||||
|
||||
// Prepend to the visible list.
|
||||
_messages.Insert(0, msg);
|
||||
_senderNames[SystemSenderId] = "[System]";
|
||||
|
||||
_systemMessageText = "";
|
||||
_systemSuccess = true;
|
||||
_posting = false;
|
||||
}
|
||||
|
||||
private async Task PostAdminMessageAsync()
|
||||
{
|
||||
_adminError = "";
|
||||
_adminSuccess = false;
|
||||
|
||||
if (_adminAccountId == null)
|
||||
{
|
||||
_adminError = "Could not resolve admin account.";
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(_adminMessageText))
|
||||
{
|
||||
_adminError = "Message cannot be empty.";
|
||||
return;
|
||||
}
|
||||
if (_adminMessageText.Length > 500)
|
||||
{
|
||||
_adminError = "Message must be 500 characters or fewer.";
|
||||
return;
|
||||
}
|
||||
|
||||
_postingAdmin = true;
|
||||
|
||||
var msg = new ChatMessage
|
||||
{
|
||||
ChannelId = ChannelId,
|
||||
SenderAccountId = _adminAccountId.Value,
|
||||
Content = _adminMessageText.Trim(),
|
||||
SentAt = DateTimeOffset.UtcNow,
|
||||
};
|
||||
ChatDb.Messages.Add(msg);
|
||||
await ChatDb.SaveChangesAsync();
|
||||
|
||||
if (!_senderNames.ContainsKey(_adminAccountId.Value))
|
||||
_senderNames[_adminAccountId.Value] = _adminDisplayName ?? "[Admin]";
|
||||
|
||||
_messages.Insert(0, msg);
|
||||
_adminMessageText = "";
|
||||
_adminSuccess = true;
|
||||
_postingAdmin = false;
|
||||
}
|
||||
|
||||
private async Task ToggleDeleteAsync(ChatMessage msg, bool deleted)
|
||||
{
|
||||
msg.IsDeleted = deleted;
|
||||
ChatDb.Messages.Update(msg);
|
||||
await ChatDb.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private static string TypeBadge(SOR.Database.Enums.ChatChannelType t) => t switch
|
||||
{
|
||||
SOR.Database.Enums.ChatChannelType.Global => "bg-primary",
|
||||
|
||||
Reference in New Issue
Block a user