Add versioning, content, and chat presence/notifications services
- SOR.Versioning: version.check handler, ClientRelease entity + admin UI - SOR.Content: incremental card sync (DefinitionVersion cursor via Postgres trigger), content.sync / content.sets / content.card handlers - Chat: presence (account_presence) + notifications with unread count and mark-read - CardDefinition: DefinitionVersion bigint (trigger-assigned) + IsRetired soft-delete - 3 migrations applied to pg-forge-01 (Identity, Chat, Catalog) 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:
@@ -6,6 +6,7 @@
|
||||
<Project Path="src/SOR.Cdn/SOR.Cdn.csproj" />
|
||||
<Project Path="src/SOR.Chat/SOR.Chat.csproj" />
|
||||
<Project Path="src/SOR.Collection/SOR.Collection.csproj" />
|
||||
<Project Path="src/SOR.Content/SOR.Content.csproj" />
|
||||
<Project Path="src/SOR.Database/SOR.Database.csproj" />
|
||||
<Project Path="src/SOR.Gateway/SOR.Gateway.csproj" />
|
||||
<Project Path="src/SOR.Host/SOR.Host.csproj" />
|
||||
@@ -15,5 +16,6 @@
|
||||
<Project Path="src/SOR.Networking.WebSocket/SOR.Networking.WebSocket.csproj" />
|
||||
<Project Path="src/SOR.Shared.Proto/SOR.Shared.Proto.csproj" />
|
||||
<Project Path="src/SOR.Shared/SOR.Shared.csproj" />
|
||||
<Project Path="src/SOR.Versioning/SOR.Versioning.csproj" />
|
||||
</Folder>
|
||||
</Solution>
|
||||
|
||||
@@ -63,6 +63,11 @@
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<NavLink class="nav-link text-white" href="/versioning/releases" Match="NavLinkMatch.All">
|
||||
<i class="bi bi-phone me-2"></i>Client Versions
|
||||
</NavLink>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<NavLink class="nav-link text-white" href="/content/ai-assets" Match="NavLinkMatch.All">
|
||||
<i class="bi bi-robot me-2"></i>AI Art Tracker
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
@page "/versioning/releases/new"
|
||||
@page "/versioning/releases/{Id:guid}"
|
||||
@using SOR.Database.Contexts
|
||||
@using SOR.Database.Entities.Identity
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@inject SorIdentityDbContext IdentityDb
|
||||
@inject NavigationManager Nav
|
||||
|
||||
<PageTitle>@(_isNew ? "New Release" : "Edit Release") — SOR Admin</PageTitle>
|
||||
|
||||
<div class="d-flex align-items-center mb-3 gap-2">
|
||||
<a href="/versioning/releases" class="btn btn-sm btn-outline-secondary">
|
||||
<i class="bi bi-arrow-left me-1"></i>Back
|
||||
</a>
|
||||
<h4 class="mb-0">@(_isNew ? "New Client Release" : $"Edit Release — {_release.Platform} {_release.Version}")</h4>
|
||||
</div>
|
||||
|
||||
@if (_release == null)
|
||||
{
|
||||
<p class="text-muted">Loading...</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="card bg-dark border-secondary" style="max-width:600px;">
|
||||
<div class="card-body">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Platform</label>
|
||||
<select @bind="_release.Platform" class="form-select bg-dark text-white border-secondary">
|
||||
<option value="">— select —</option>
|
||||
<option value="android">Android</option>
|
||||
<option value="ios">iOS</option>
|
||||
<option value="pc">PC</option>
|
||||
<option value="web">Web</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Version <span class="text-muted small">(semver, e.g. 1.2.3)</span></label>
|
||||
<input @bind="_release.Version" type="text" class="form-control bg-dark text-white border-secondary"
|
||||
placeholder="1.0.0" />
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Released At</label>
|
||||
<input @bind="_release.ReleasedAt" type="datetime-local" class="form-control bg-dark text-white border-secondary" />
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Download URL</label>
|
||||
<input @bind="_release.DownloadUrl" type="url" class="form-control bg-dark text-white border-secondary"
|
||||
placeholder="https://..." />
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Release Notes</label>
|
||||
<textarea @bind="_release.ReleaseNotes" class="form-control bg-dark text-white border-secondary"
|
||||
rows="4" placeholder="What's new in this release..."></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-check mb-2">
|
||||
<input @bind="_release.IsRequired" type="checkbox" class="form-check-input" id="required" />
|
||||
<label class="form-check-label text-danger fw-bold" for="required">
|
||||
<i class="bi bi-exclamation-triangle me-1"></i>Update Required
|
||||
<span class="text-muted fw-normal small ms-1">(blocks clients on older versions)</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-check mb-3">
|
||||
<input @bind="_release.IsActive" type="checkbox" class="form-check-input" id="active" />
|
||||
<label class="form-check-label" for="active">Active</label>
|
||||
</div>
|
||||
|
||||
@if (_error != null)
|
||||
{
|
||||
<div class="alert alert-danger py-2 small">@_error</div>
|
||||
}
|
||||
|
||||
<div class="d-flex gap-2">
|
||||
<button class="btn btn-primary" @onclick="SaveAsync">
|
||||
<i class="bi bi-floppy me-1"></i>Save
|
||||
</button>
|
||||
@if (!_isNew)
|
||||
{
|
||||
<button class="btn btn-outline-danger" @onclick="DeleteAsync">
|
||||
<i class="bi bi-trash me-1"></i>Delete
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter] public Guid? Id { get; set; }
|
||||
|
||||
private ClientRelease _release = new() { ReleasedAt = DateTimeOffset.UtcNow, IsActive = true };
|
||||
private bool _isNew = true;
|
||||
private string? _error;
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
if (Id.HasValue)
|
||||
{
|
||||
var existing = await IdentityDb.ClientReleases.FindAsync(Id.Value);
|
||||
if (existing != null)
|
||||
{
|
||||
_release = existing;
|
||||
_isNew = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SaveAsync()
|
||||
{
|
||||
_error = null;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(_release.Platform)) { _error = "Platform is required."; return; }
|
||||
if (string.IsNullOrWhiteSpace(_release.Version)) { _error = "Version is required."; return; }
|
||||
|
||||
if (_isNew)
|
||||
IdentityDb.ClientReleases.Add(_release);
|
||||
|
||||
await IdentityDb.SaveChangesAsync();
|
||||
Nav.NavigateTo("/versioning/releases");
|
||||
}
|
||||
|
||||
private async Task DeleteAsync()
|
||||
{
|
||||
IdentityDb.ClientReleases.Remove(_release);
|
||||
await IdentityDb.SaveChangesAsync();
|
||||
Nav.NavigateTo("/versioning/releases");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
@page "/versioning/releases"
|
||||
@using SOR.Database.Contexts
|
||||
@using SOR.Database.Entities.Identity
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@inject SorIdentityDbContext IdentityDb
|
||||
|
||||
<PageTitle>Client Releases — SOR Admin</PageTitle>
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<h4 class="mb-0"><i class="bi bi-phone me-2"></i>Client Releases</h4>
|
||||
<a href="/versioning/releases/new" class="btn btn-sm btn-primary">
|
||||
<i class="bi bi-plus-lg me-1"></i>New Release
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@if (_releases == null)
|
||||
{
|
||||
<p class="text-muted">Loading...</p>
|
||||
}
|
||||
else if (_releases.Count == 0)
|
||||
{
|
||||
<p class="text-muted">No releases configured yet.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="table table-dark table-hover table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Platform</th>
|
||||
<th>Version</th>
|
||||
<th>Required</th>
|
||||
<th>Active</th>
|
||||
<th>Released</th>
|
||||
<th>Download</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var r in _releases)
|
||||
{
|
||||
<tr>
|
||||
<td><span class="badge bg-secondary text-uppercase">@r.Platform</span></td>
|
||||
<td class="fw-bold">@r.Version</td>
|
||||
<td>
|
||||
@if (r.IsRequired)
|
||||
{
|
||||
<span class="badge bg-danger">Required</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-muted small">Optional</span>
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
@if (r.IsActive)
|
||||
{
|
||||
<i class="bi bi-check-circle-fill text-success"></i>
|
||||
}
|
||||
else
|
||||
{
|
||||
<i class="bi bi-x-circle text-muted"></i>
|
||||
}
|
||||
</td>
|
||||
<td class="text-muted small">@r.ReleasedAt.ToString("yyyy-MM-dd")</td>
|
||||
<td class="small">
|
||||
@if (r.DownloadUrl != null)
|
||||
{
|
||||
<span class="text-muted font-monospace" title="@r.DownloadUrl">
|
||||
@(r.DownloadUrl.Length > 40 ? r.DownloadUrl[..40] + "…" : r.DownloadUrl)
|
||||
</span>
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
<a href="/versioning/releases/@r.Id" class="btn btn-sm btn-outline-secondary">
|
||||
Edit
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
|
||||
@code {
|
||||
private List<ClientRelease>? _releases;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_releases = await IdentityDb.ClientReleases
|
||||
.OrderByDescending(r => r.ReleasedAt)
|
||||
.ThenBy(r => r.Platform)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
namespace SOR.Chat;
|
||||
|
||||
using SOR.Database.Enums;
|
||||
|
||||
// ── Request types (client → server) ──────────────────────────────────────────
|
||||
|
||||
/// <summary>Send a message to a channel the caller is a member of.</summary>
|
||||
@@ -44,6 +46,23 @@ public sealed record UnblockRequest(Guid TargetAccountId);
|
||||
/// <summary>Returns friends, pending requests, and blocked users for the caller.</summary>
|
||||
public sealed record GetSocialRequest; // identity from connection
|
||||
|
||||
/// <summary>Update the caller's presence status.</summary>
|
||||
public sealed record SetPresenceRequest(
|
||||
PresenceStatus Status,
|
||||
Guid? CurrentMatchId = null);
|
||||
|
||||
/// <summary>Batch-fetch presence for a set of account IDs (max 100).</summary>
|
||||
public sealed record GetPresenceRequest(IEnumerable<Guid>? AccountIds);
|
||||
|
||||
/// <summary>Fetch the caller's notifications. UnreadOnly=true filters to unread only.</summary>
|
||||
public sealed record GetNotificationsRequest(bool UnreadOnly = false);
|
||||
|
||||
/// <summary>
|
||||
/// Mark notifications as read.
|
||||
/// Null or empty NotificationIds = mark ALL unread notifications for the caller.
|
||||
/// </summary>
|
||||
public sealed record MarkNotificationsReadRequest(IEnumerable<Guid>? NotificationIds = null);
|
||||
|
||||
// ── Response / DTO types (server → client) ────────────────────────────────────
|
||||
|
||||
public sealed record SendMessageResponse(ChatMessageDto Message);
|
||||
@@ -62,6 +81,14 @@ public sealed record GetSocialResponse(
|
||||
IEnumerable<FriendRequestDto> OutgoingRequests,
|
||||
IEnumerable<BlockedUserDto> Blocked);
|
||||
|
||||
public sealed record SetPresenceResponse(PresenceDto Presence);
|
||||
|
||||
public sealed record GetPresenceResponse(IEnumerable<PresenceDto> Presences);
|
||||
|
||||
public sealed record GetNotificationsResponse(
|
||||
IEnumerable<NotificationDto> Notifications,
|
||||
int UnreadCount);
|
||||
|
||||
// ── DTOs ────────────────────────────────────────────────────────────────────
|
||||
|
||||
public sealed record ChatChannelDto(
|
||||
@@ -95,3 +122,18 @@ public sealed record BlockedUserDto(
|
||||
Guid AccountId,
|
||||
string DisplayName,
|
||||
DateTimeOffset BlockedAt);
|
||||
|
||||
public sealed record PresenceDto(
|
||||
Guid AccountId,
|
||||
string Status,
|
||||
Guid? CurrentMatchId,
|
||||
DateTimeOffset LastSeenAt);
|
||||
|
||||
public sealed record NotificationDto(
|
||||
Guid Id,
|
||||
string NotificationType,
|
||||
string Title,
|
||||
string Body,
|
||||
string? PayloadJson,
|
||||
DateTimeOffset CreatedAt,
|
||||
DateTimeOffset? ReadAt);
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
namespace SOR.Chat.Handlers;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Networking.Abstractions.Transport;
|
||||
using SOR.Shared.Networking;
|
||||
|
||||
/// <summary>
|
||||
/// chat.notifications.get — fetch the caller's notifications (most recent 50),
|
||||
/// with a total unread count.
|
||||
/// </summary>
|
||||
internal sealed class ChatGetNotificationsHandler : ChatHandlerBase, IMessageHandler
|
||||
{
|
||||
private readonly IMessageSerializer _serializer;
|
||||
private readonly ChatDbContext _chatDb;
|
||||
|
||||
public ChatGetNotificationsHandler(IMessageSerializer serializer, ChatDbContext chatDb)
|
||||
{
|
||||
_serializer = serializer;
|
||||
_chatDb = chatDb;
|
||||
}
|
||||
|
||||
public string MessageType => "chat.notifications.get";
|
||||
|
||||
public async Task<IServerMessage?> HandleAsync(
|
||||
IClientMessage message,
|
||||
AuthenticatedConnection connection,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var req = _serializer.DeserializePayload<GetNotificationsRequest>(message.Payload);
|
||||
var accountId = Guid.Parse(connection.UserId);
|
||||
|
||||
var query = _chatDb.Notifications
|
||||
.Where(n => n.RecipientAccountId == accountId);
|
||||
|
||||
if (req.UnreadOnly)
|
||||
query = query.Where(n => n.ReadAt == null);
|
||||
|
||||
var notifications = await query
|
||||
.OrderByDescending(n => n.CreatedAt)
|
||||
.Take(50)
|
||||
.ToListAsync(ct);
|
||||
|
||||
var unreadCount = await _chatDb.Notifications
|
||||
.CountAsync(n => n.RecipientAccountId == accountId && n.ReadAt == null, ct);
|
||||
|
||||
var dtos = notifications.Select(n => new NotificationDto(
|
||||
n.Id,
|
||||
n.NotificationType,
|
||||
n.Title,
|
||||
n.Body,
|
||||
n.PayloadJson,
|
||||
n.CreatedAt,
|
||||
n.ReadAt));
|
||||
|
||||
return ServerMessage.Reply("chat.notifications.get.ack", message.Seq,
|
||||
new GetNotificationsResponse(dtos, unreadCount));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
namespace SOR.Chat.Handlers;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Networking.Abstractions.Transport;
|
||||
using SOR.Shared.Networking;
|
||||
|
||||
/// <summary>
|
||||
/// chat.presence.get — batch-fetch presence for a set of account IDs.
|
||||
/// Accounts with no presence record are returned as Offline.
|
||||
/// Capped at 100 accounts per request.
|
||||
/// </summary>
|
||||
internal sealed class ChatGetPresenceHandler : ChatHandlerBase, IMessageHandler
|
||||
{
|
||||
private readonly IMessageSerializer _serializer;
|
||||
private readonly ChatDbContext _chatDb;
|
||||
|
||||
public ChatGetPresenceHandler(IMessageSerializer serializer, ChatDbContext chatDb)
|
||||
{
|
||||
_serializer = serializer;
|
||||
_chatDb = chatDb;
|
||||
}
|
||||
|
||||
public string MessageType => "chat.presence.get";
|
||||
|
||||
public async Task<IServerMessage?> HandleAsync(
|
||||
IClientMessage message,
|
||||
AuthenticatedConnection connection,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var req = _serializer.DeserializePayload<GetPresenceRequest>(message.Payload);
|
||||
|
||||
var accountIds = (req.AccountIds ?? Enumerable.Empty<Guid>())
|
||||
.Distinct()
|
||||
.Take(100)
|
||||
.ToList();
|
||||
|
||||
if (accountIds.Count == 0)
|
||||
return ServerMessage.Reply("chat.presence.get.ack", message.Seq,
|
||||
new GetPresenceResponse(Array.Empty<PresenceDto>()));
|
||||
|
||||
var presences = await _chatDb.AccountPresences
|
||||
.Where(p => accountIds.Contains(p.AccountId))
|
||||
.ToListAsync(ct);
|
||||
|
||||
var dtos = accountIds.Select(id =>
|
||||
{
|
||||
var p = presences.FirstOrDefault(x => x.AccountId == id);
|
||||
return p != null
|
||||
? ChatSetPresenceHandler.ToDto(p)
|
||||
: new PresenceDto(id, "Offline", null, DateTimeOffset.MinValue);
|
||||
});
|
||||
|
||||
return ServerMessage.Reply("chat.presence.get.ack", message.Seq,
|
||||
new GetPresenceResponse(dtos));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
namespace SOR.Chat.Handlers;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Networking.Abstractions.Transport;
|
||||
using SOR.Shared.Networking;
|
||||
|
||||
/// <summary>
|
||||
/// chat.notifications.read — mark one or more notifications as read.
|
||||
/// If NotificationIds is null or empty, marks ALL unread notifications for the caller.
|
||||
/// </summary>
|
||||
internal sealed class ChatMarkNotificationsReadHandler : ChatHandlerBase, IMessageHandler
|
||||
{
|
||||
private readonly IMessageSerializer _serializer;
|
||||
private readonly ChatDbContext _chatDb;
|
||||
|
||||
public ChatMarkNotificationsReadHandler(IMessageSerializer serializer, ChatDbContext chatDb)
|
||||
{
|
||||
_serializer = serializer;
|
||||
_chatDb = chatDb;
|
||||
}
|
||||
|
||||
public string MessageType => "chat.notifications.read";
|
||||
|
||||
public async Task<IServerMessage?> HandleAsync(
|
||||
IClientMessage message,
|
||||
AuthenticatedConnection connection,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var req = _serializer.DeserializePayload<MarkNotificationsReadRequest>(message.Payload);
|
||||
var accountId = Guid.Parse(connection.UserId);
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
|
||||
if (req.NotificationIds == null || !req.NotificationIds.Any())
|
||||
{
|
||||
// Mark all unread for this account.
|
||||
await _chatDb.Notifications
|
||||
.Where(n => n.RecipientAccountId == accountId && n.ReadAt == null)
|
||||
.ExecuteUpdateAsync(s => s.SetProperty(n => n.ReadAt, now), ct);
|
||||
}
|
||||
else
|
||||
{
|
||||
var ids = req.NotificationIds.ToList();
|
||||
await _chatDb.Notifications
|
||||
.Where(n => n.RecipientAccountId == accountId
|
||||
&& ids.Contains(n.Id)
|
||||
&& n.ReadAt == null)
|
||||
.ExecuteUpdateAsync(s => s.SetProperty(n => n.ReadAt, now), ct);
|
||||
}
|
||||
|
||||
return ServerMessage.Reply("chat.notifications.read.ack", message.Seq, new { });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
namespace SOR.Chat.Handlers;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Database.Entities.Chat;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Networking.Abstractions.Transport;
|
||||
using SOR.Shared.Networking;
|
||||
|
||||
/// <summary>
|
||||
/// chat.presence.set — upserts the caller's presence status.
|
||||
/// Clients should call this on connect (Online), when entering a match (InMatch),
|
||||
/// and on disconnect/background (Offline/Away).
|
||||
/// </summary>
|
||||
internal sealed class ChatSetPresenceHandler : ChatHandlerBase, IMessageHandler
|
||||
{
|
||||
private readonly IMessageSerializer _serializer;
|
||||
private readonly ChatDbContext _chatDb;
|
||||
|
||||
public ChatSetPresenceHandler(IMessageSerializer serializer, ChatDbContext chatDb)
|
||||
{
|
||||
_serializer = serializer;
|
||||
_chatDb = chatDb;
|
||||
}
|
||||
|
||||
public string MessageType => "chat.presence.set";
|
||||
|
||||
public async Task<IServerMessage?> HandleAsync(
|
||||
IClientMessage message,
|
||||
AuthenticatedConnection connection,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var req = _serializer.DeserializePayload<SetPresenceRequest>(message.Payload);
|
||||
var accountId = Guid.Parse(connection.UserId);
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
|
||||
var presence = await _chatDb.AccountPresences
|
||||
.FirstOrDefaultAsync(p => p.AccountId == accountId, ct);
|
||||
|
||||
if (presence == null)
|
||||
{
|
||||
presence = new AccountPresence
|
||||
{
|
||||
AccountId = accountId,
|
||||
Status = req.Status,
|
||||
CurrentMatchId = req.CurrentMatchId,
|
||||
UpdatedAt = now,
|
||||
LastSeenAt = now,
|
||||
};
|
||||
_chatDb.AccountPresences.Add(presence);
|
||||
}
|
||||
else
|
||||
{
|
||||
presence.Status = req.Status;
|
||||
presence.CurrentMatchId = req.CurrentMatchId;
|
||||
presence.UpdatedAt = now;
|
||||
presence.LastSeenAt = now;
|
||||
}
|
||||
|
||||
await _chatDb.SaveChangesAsync(ct);
|
||||
|
||||
return ServerMessage.Reply("chat.presence.set.ack", message.Seq,
|
||||
new SetPresenceResponse(ToDto(presence)));
|
||||
}
|
||||
|
||||
internal static PresenceDto ToDto(AccountPresence p)
|
||||
=> new(p.AccountId, p.Status.ToString(), p.CurrentMatchId, p.LastSeenAt);
|
||||
}
|
||||
@@ -31,6 +31,10 @@ public static class ServiceRegistration
|
||||
services.AddTransient<IMessageHandler, ChatBlockHandler>();
|
||||
services.AddTransient<IMessageHandler, ChatUnblockHandler>();
|
||||
services.AddTransient<IMessageHandler, ChatGetSocialHandler>();
|
||||
services.AddTransient<IMessageHandler, ChatSetPresenceHandler>();
|
||||
services.AddTransient<IMessageHandler, ChatGetPresenceHandler>();
|
||||
services.AddTransient<IMessageHandler, ChatGetNotificationsHandler>();
|
||||
services.AddTransient<IMessageHandler, ChatMarkNotificationsReadHandler>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
namespace SOR.Content;
|
||||
|
||||
// ── Request types (client → server) ──────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Fetch card definitions modified since the given version watermark.
|
||||
/// Pass SinceVersion=0 for the initial full sync; responses are paged.
|
||||
/// Keep fetching (advancing SinceVersion to CurrentVersion each time)
|
||||
/// until HasMore=false.
|
||||
/// </summary>
|
||||
public sealed record SyncCardDefinitionsRequest(long SinceVersion, int PageSize = 200);
|
||||
|
||||
/// <summary>Fetch the manifest of all card sets (no card data).</summary>
|
||||
public sealed record GetCardSetsRequest;
|
||||
|
||||
/// <summary>Fetch a single card definition by ID including assets and animations.</summary>
|
||||
public sealed record GetCardDefinitionRequest(Guid Id);
|
||||
|
||||
// ── Response / DTO types (server → client) ────────────────────────────────────
|
||||
|
||||
public sealed record SyncCardDefinitionsResponse(
|
||||
IEnumerable<CardDefinitionDto> Cards,
|
||||
long CurrentVersion,
|
||||
bool HasMore);
|
||||
|
||||
public sealed record GetCardSetsResponse(IEnumerable<CardSetDto> Sets);
|
||||
|
||||
public sealed record GetCardDefinitionResponse(CardDefinitionDto? Card);
|
||||
|
||||
// ── DTOs ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
public sealed record CardSetDto(
|
||||
Guid Id,
|
||||
string Name,
|
||||
string Code,
|
||||
string? Description,
|
||||
DateOnly? ReleaseDate,
|
||||
bool IsActive,
|
||||
int PublishedCardCount);
|
||||
|
||||
public sealed record CardDefinitionDto(
|
||||
Guid Id,
|
||||
string Name,
|
||||
string Description,
|
||||
string CardType,
|
||||
string Affinity,
|
||||
string Rarity,
|
||||
int SpCost,
|
||||
int StCost,
|
||||
string? OtherCostsJson,
|
||||
// Unit stats
|
||||
int? MinChannelRange,
|
||||
int? MaxChannelRange,
|
||||
string? AttackType,
|
||||
bool? RequiresLos,
|
||||
int? MinAttackRange,
|
||||
int? MaxAttackRange,
|
||||
bool? CanAttack,
|
||||
int? Damage,
|
||||
bool? CanDefend,
|
||||
int? MaxHealth,
|
||||
int? MaxDefense,
|
||||
bool? CanBeAttacked,
|
||||
bool? CanBeBlocked,
|
||||
bool? CanMove,
|
||||
string? MovementType,
|
||||
int? MovementPoints,
|
||||
bool? CanBeObstructed,
|
||||
bool? CanUseAbility,
|
||||
string[]? Genus,
|
||||
bool? CanBeSacrificed,
|
||||
int? Tier,
|
||||
Guid? PreviousTierId,
|
||||
string? TerramorphaMode,
|
||||
string? AbilitiesJson,
|
||||
string? EffectsJson,
|
||||
// Publishing
|
||||
Guid? SetId,
|
||||
int? CollectorNumber,
|
||||
bool IsPublished,
|
||||
bool IsRetired,
|
||||
DateTimeOffset? RetiredAt,
|
||||
DateTimeOffset UpdatedAt,
|
||||
long DefinitionVersion,
|
||||
// Assets
|
||||
IEnumerable<CardAssetDto> Assets,
|
||||
IEnumerable<CardAnimationBindingDto> AnimationBindings);
|
||||
|
||||
public sealed record CardAssetDto(
|
||||
Guid Id,
|
||||
string AssetType,
|
||||
string CdnUrl,
|
||||
string? MimeType,
|
||||
bool IsAiGenerated);
|
||||
|
||||
public sealed record CardAnimationBindingDto(
|
||||
Guid Id,
|
||||
string ActionName,
|
||||
string AnimationCdnUrl,
|
||||
bool IsAiGenerated);
|
||||
@@ -0,0 +1,60 @@
|
||||
namespace SOR.Content.Handlers;
|
||||
|
||||
using SOR.Database.Entities.Catalog;
|
||||
|
||||
internal static class ContentDtoMapper
|
||||
{
|
||||
internal static CardDefinitionDto ToDto(CardDefinition c) => new(
|
||||
Id: c.Id,
|
||||
Name: c.Name,
|
||||
Description: c.Description,
|
||||
CardType: c.CardType.ToString(),
|
||||
Affinity: c.Affinity.ToString(),
|
||||
Rarity: c.Rarity.ToString(),
|
||||
SpCost: c.SpCost,
|
||||
StCost: c.StCost,
|
||||
OtherCostsJson: c.OtherCostsJson,
|
||||
MinChannelRange: c.MinChannelRange,
|
||||
MaxChannelRange: c.MaxChannelRange,
|
||||
AttackType: c.AttackType?.ToString(),
|
||||
RequiresLos: c.RequiresLos,
|
||||
MinAttackRange: c.MinAttackRange,
|
||||
MaxAttackRange: c.MaxAttackRange,
|
||||
CanAttack: c.CanAttack,
|
||||
Damage: c.Damage,
|
||||
CanDefend: c.CanDefend,
|
||||
MaxHealth: c.MaxHealth,
|
||||
MaxDefense: c.MaxDefense,
|
||||
CanBeAttacked: c.CanBeAttacked,
|
||||
CanBeBlocked: c.CanBeBlocked,
|
||||
CanMove: c.CanMove,
|
||||
MovementType: c.MovementType?.ToString(),
|
||||
MovementPoints: c.MovementPoints,
|
||||
CanBeObstructed: c.CanBeObstructed,
|
||||
CanUseAbility: c.CanUseAbility,
|
||||
Genus: c.Genus,
|
||||
CanBeSacrificed: c.CanBeSacrificed,
|
||||
Tier: c.Tier,
|
||||
PreviousTierId: c.PreviousTierId,
|
||||
TerramorphaMode: c.TerramorphaMode?.ToString(),
|
||||
AbilitiesJson: c.AbilitiesJson,
|
||||
EffectsJson: c.EffectsJson,
|
||||
SetId: c.SetId,
|
||||
CollectorNumber: c.CollectorNumber,
|
||||
IsPublished: c.IsPublished,
|
||||
IsRetired: c.IsRetired,
|
||||
RetiredAt: c.RetiredAt,
|
||||
UpdatedAt: c.UpdatedAt,
|
||||
DefinitionVersion: c.DefinitionVersion,
|
||||
Assets: c.Assets.Select(a => new CardAssetDto(
|
||||
a.Id,
|
||||
a.AssetType.ToString(),
|
||||
a.CdnUrl,
|
||||
a.MimeType,
|
||||
a.IsAiGenerated)),
|
||||
AnimationBindings: c.AnimationBindings.Select(b => new CardAnimationBindingDto(
|
||||
b.Id,
|
||||
b.ActionName,
|
||||
b.AnimationCdnUrl,
|
||||
b.IsAiGenerated)));
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
namespace SOR.Content.Handlers;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Networking.Abstractions.Transport;
|
||||
using SOR.Shared.Networking;
|
||||
|
||||
/// <summary>
|
||||
/// content.card — fetch a single card definition by ID including assets and animations.
|
||||
/// Useful when the client needs to refresh one card without triggering a full sync.
|
||||
/// </summary>
|
||||
internal sealed class ContentGetCardDefinitionHandler : IMessageHandler
|
||||
{
|
||||
private readonly IMessageSerializer _serializer;
|
||||
private readonly CatalogDbContext _catalogDb;
|
||||
|
||||
public ContentGetCardDefinitionHandler(IMessageSerializer serializer, CatalogDbContext catalogDb)
|
||||
{
|
||||
_serializer = serializer;
|
||||
_catalogDb = catalogDb;
|
||||
}
|
||||
|
||||
public string MessageType => "content.card";
|
||||
|
||||
public async Task<IServerMessage?> HandleAsync(
|
||||
IClientMessage message,
|
||||
AuthenticatedConnection connection,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var req = _serializer.DeserializePayload<GetCardDefinitionRequest>(message.Payload);
|
||||
var card = await _catalogDb.CardDefinitions
|
||||
.Include(c => c.Assets)
|
||||
.Include(c => c.AnimationBindings)
|
||||
.FirstOrDefaultAsync(c => c.Id == req.Id, ct);
|
||||
|
||||
var dto = card != null ? ContentDtoMapper.ToDto(card) : null;
|
||||
|
||||
return ServerMessage.Reply("content.card.ack", message.Seq,
|
||||
new GetCardDefinitionResponse(dto));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
namespace SOR.Content.Handlers;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Networking.Abstractions.Transport;
|
||||
using SOR.Shared.Networking;
|
||||
|
||||
/// <summary>
|
||||
/// content.sets — returns the manifest of all card sets.
|
||||
/// Lightweight: clients use this to show "Download Expansion X (42 cards)"
|
||||
/// before triggering a sync for a specific set.
|
||||
/// </summary>
|
||||
internal sealed class ContentGetCardSetsHandler : IMessageHandler
|
||||
{
|
||||
private readonly IMessageSerializer _serializer;
|
||||
private readonly CatalogDbContext _catalogDb;
|
||||
|
||||
public ContentGetCardSetsHandler(IMessageSerializer serializer, CatalogDbContext catalogDb)
|
||||
{
|
||||
_serializer = serializer;
|
||||
_catalogDb = catalogDb;
|
||||
}
|
||||
|
||||
public string MessageType => "content.sets";
|
||||
|
||||
public async Task<IServerMessage?> HandleAsync(
|
||||
IClientMessage message,
|
||||
AuthenticatedConnection connection,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var sets = await _catalogDb.CardSets
|
||||
.Select(s => new CardSetDto(
|
||||
s.Id,
|
||||
s.Name,
|
||||
s.Code,
|
||||
s.Description,
|
||||
s.ReleaseDate,
|
||||
s.IsActive,
|
||||
s.Cards.Count(c => c.IsPublished && !c.IsRetired)))
|
||||
.ToListAsync(ct);
|
||||
|
||||
return ServerMessage.Reply("content.sets.ack", message.Seq, new GetCardSetsResponse(sets));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
namespace SOR.Content.Handlers;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Networking.Abstractions.Transport;
|
||||
using SOR.Shared.Networking;
|
||||
|
||||
/// <summary>
|
||||
/// content.sync — incremental card definition sync.
|
||||
///
|
||||
/// Clients call this with SinceVersion=0 on first launch and page through until
|
||||
/// HasMore=false. On subsequent launches they resume from their stored CurrentVersion.
|
||||
/// The DefinitionVersion column is maintained by a Postgres trigger so all INSERTs
|
||||
/// and UPDATEs (including retirements) automatically advance the cursor.
|
||||
/// </summary>
|
||||
internal sealed class ContentSyncHandler : IMessageHandler
|
||||
{
|
||||
private readonly IMessageSerializer _serializer;
|
||||
private readonly CatalogDbContext _catalogDb;
|
||||
|
||||
public ContentSyncHandler(IMessageSerializer serializer, CatalogDbContext catalogDb)
|
||||
{
|
||||
_serializer = serializer;
|
||||
_catalogDb = catalogDb;
|
||||
}
|
||||
|
||||
public string MessageType => "content.sync";
|
||||
|
||||
public async Task<IServerMessage?> HandleAsync(
|
||||
IClientMessage message,
|
||||
AuthenticatedConnection connection,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var req = _serializer.DeserializePayload<SyncCardDefinitionsRequest>(message.Payload);
|
||||
var pageSize = Math.Clamp(req.PageSize, 1, 500);
|
||||
|
||||
// Fetch one extra to detect HasMore without an additional COUNT query.
|
||||
var cards = await _catalogDb.CardDefinitions
|
||||
.Include(c => c.Assets)
|
||||
.Include(c => c.AnimationBindings)
|
||||
.Where(c => c.DefinitionVersion > req.SinceVersion)
|
||||
.OrderBy(c => c.DefinitionVersion)
|
||||
.Take(pageSize + 1)
|
||||
.ToListAsync(ct);
|
||||
|
||||
var hasMore = cards.Count > pageSize;
|
||||
if (hasMore) cards = cards.Take(pageSize).ToList();
|
||||
|
||||
var currentVersion = cards.Count > 0
|
||||
? cards[^1].DefinitionVersion
|
||||
: req.SinceVersion;
|
||||
|
||||
var dtos = cards.Select(ContentDtoMapper.ToDto);
|
||||
|
||||
return ServerMessage.Reply("content.sync.ack", message.Seq,
|
||||
new SyncCardDefinitionsResponse(dtos, currentVersion, hasMore));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<AssemblyName>SOR.Content</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SOR.Database\SOR.Database.csproj" />
|
||||
<ProjectReference Include="..\SOR.Networking.Abstractions\SOR.Networking.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\SOR.Shared\SOR.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace SOR.Content;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SOR.Content.Handlers;
|
||||
using SOR.Database;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
|
||||
/// <summary>
|
||||
/// Registers all content service components into the DI container.
|
||||
/// Called from SOR.Host/Program.cs when ENABLED_SERVICES includes "content".
|
||||
/// </summary>
|
||||
public static class ServiceRegistration
|
||||
{
|
||||
public static IServiceCollection AddContentService(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
services.AddCatalogDatabase(configuration);
|
||||
|
||||
services.AddTransient<IMessageHandler, ContentSyncHandler>();
|
||||
services.AddTransient<IMessageHandler, ContentGetCardSetsHandler>();
|
||||
services.AddTransient<IMessageHandler, ContentGetCardDefinitionHandler>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
@@ -75,6 +75,12 @@ public sealed class CatalogDbContext : DbContext
|
||||
e.HasIndex(c => c.Rarity);
|
||||
e.HasIndex(c => new { c.IsPublished, c.SetId });
|
||||
|
||||
// Incremental sync cursor — clients page through cards ordered by this value.
|
||||
// Default 0 is overridden by a Postgres trigger on every INSERT/UPDATE.
|
||||
e.Property(c => c.DefinitionVersion)
|
||||
.HasDefaultValue(0L);
|
||||
e.HasIndex(c => c.DefinitionVersion);
|
||||
|
||||
// Self-reference: Tier N ArchSpirit → Tier (N-1) ArchSpirit.
|
||||
e.HasOne(c => c.PreviousTier)
|
||||
.WithMany()
|
||||
|
||||
@@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Entities.Chat;
|
||||
using SOR.Database.Enums;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// EF Core DbContext for the chat schema.
|
||||
/// At scale, high-frequency chat messages may be offloaded to a time-series store;
|
||||
@@ -26,6 +27,8 @@ public sealed class ChatDbContext : DbContext
|
||||
public DbSet<ChatMessage> Messages => Set<ChatMessage>();
|
||||
public DbSet<FriendRequest> FriendRequests => Set<FriendRequest>();
|
||||
public DbSet<BlockedUser> BlockedUsers => Set<BlockedUser>();
|
||||
public DbSet<AccountPresence> AccountPresences => Set<AccountPresence>();
|
||||
public DbSet<Notification> Notifications => Set<Notification>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
@@ -83,5 +86,22 @@ public sealed class ChatDbContext : DbContext
|
||||
e.HasIndex(b => new { b.BlockerAccountId, b.BlockedAccountId }).IsUnique();
|
||||
e.HasIndex(b => b.BlockerAccountId);
|
||||
});
|
||||
|
||||
builder.Entity<AccountPresence>(e =>
|
||||
{
|
||||
e.ToTable("account_presence");
|
||||
// One row per account — AccountId is both PK and the cross-schema FK.
|
||||
e.HasKey(p => p.AccountId);
|
||||
e.Property(p => p.Status).HasConversion<string>();
|
||||
});
|
||||
|
||||
builder.Entity<Notification>(e =>
|
||||
{
|
||||
e.ToTable("notifications");
|
||||
e.HasKey(n => n.Id);
|
||||
e.Property(n => n.PayloadJson).HasColumnType("jsonb").HasColumnName("payload");
|
||||
// Primary query: unread notifications for a recipient, newest first.
|
||||
e.HasIndex(n => new { n.RecipientAccountId, n.ReadAt, n.CreatedAt });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ public sealed class SorIdentityDbContext
|
||||
|
||||
public DbSet<AccountSession> AccountSessions => Set<AccountSession>();
|
||||
public DbSet<AccountProperty> AccountProperties => Set<AccountProperty>();
|
||||
public DbSet<ClientRelease> ClientReleases => Set<ClientRelease>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
@@ -66,5 +67,13 @@ public sealed class SorIdentityDbContext
|
||||
e.HasIndex(p => new { p.AccountId, p.Key }).IsUnique();
|
||||
e.HasIndex(p => p.AccountId);
|
||||
});
|
||||
|
||||
builder.Entity<ClientRelease>(e =>
|
||||
{
|
||||
e.ToTable("client_releases");
|
||||
e.HasKey(r => r.Id);
|
||||
// Fast lookup: find latest active release for a platform.
|
||||
e.HasIndex(r => new { r.Platform, r.IsActive, r.ReleasedAt });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,9 +89,24 @@ public sealed class CardDefinition
|
||||
/// <summary>Only published cards are visible in the client and available for collection.</summary>
|
||||
public bool IsPublished { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Soft-deleted cards remain in the catalog so clients can purge them from local cache.
|
||||
/// Retired cards are excluded from new collection grants, booster draws, and shop listings.
|
||||
/// </summary>
|
||||
public bool IsRetired { get; set; }
|
||||
|
||||
public DateTimeOffset? RetiredAt { get; set; }
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
public DateTimeOffset UpdatedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Monotonic version counter assigned by a Postgres trigger on every INSERT or UPDATE.
|
||||
/// Clients use this as a cursor for incremental catalog sync:
|
||||
/// fetch WHERE DefinitionVersion > lastKnownVersion ORDER BY DefinitionVersion ASC LIMIT N.
|
||||
/// </summary>
|
||||
public long DefinitionVersion { get; set; }
|
||||
|
||||
// ── Navigation ───────────────────────────────────────────────────────────
|
||||
public CardSet? Set { get; set; }
|
||||
public ICollection<CardAsset> Assets { get; set; } = new List<CardAsset>();
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace SOR.Database.Entities.Chat;
|
||||
|
||||
using SOR.Database.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// Tracks the real-time presence status of an account.
|
||||
/// One row per account; upserted when the client calls chat.presence.set.
|
||||
/// </summary>
|
||||
public sealed class AccountPresence
|
||||
{
|
||||
/// <summary>PK and FK cross-schema to identity.accounts.</summary>
|
||||
public Guid AccountId { get; set; }
|
||||
|
||||
public PresenceStatus Status { get; set; }
|
||||
|
||||
/// <summary>Populated when Status == InMatch; null otherwise.</summary>
|
||||
public Guid? CurrentMatchId { get; set; }
|
||||
|
||||
/// <summary>When this presence record was last changed.</summary>
|
||||
public DateTimeOffset UpdatedAt { get; set; }
|
||||
|
||||
/// <summary>Last time the account was seen online (even if now Away/Offline).</summary>
|
||||
public DateTimeOffset LastSeenAt { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace SOR.Database.Entities.Chat;
|
||||
|
||||
/// <summary>
|
||||
/// An in-app notification for a specific account.
|
||||
/// Delivered over the existing WebSocket connection; persisted so the client can
|
||||
/// fetch missed notifications on reconnect.
|
||||
///
|
||||
/// Well-known NotificationType values:
|
||||
/// "outbid" — another player placed a higher bid on your auction
|
||||
/// "friend_request" — incoming friend request
|
||||
/// "friend_accept" — your friend request was accepted
|
||||
/// "match_invite" — challenged to a match
|
||||
/// </summary>
|
||||
public sealed class Notification
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
/// <summary>Cross-schema: identity.accounts.Id of the recipient.</summary>
|
||||
public Guid RecipientAccountId { get; set; }
|
||||
|
||||
/// <summary>Well-known type string used by the client to choose how to render the notification.</summary>
|
||||
public string NotificationType { get; set; } = string.Empty;
|
||||
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public string Body { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>JSONB: type-specific payload (e.g. listingId for outbid, requesterId for friend_request).</summary>
|
||||
public string? PayloadJson { get; set; }
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
|
||||
/// <summary>Null = unread. Set when the client calls chat.notifications.read.</summary>
|
||||
public DateTimeOffset? ReadAt { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
namespace SOR.Database.Entities.Identity;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a published client release for a given platform.
|
||||
/// Used by the version check service to inform clients whether an update is available
|
||||
/// or required before they can play.
|
||||
/// </summary>
|
||||
public sealed class ClientRelease
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
/// <summary>Platform identifier: "android", "ios", "pc", "web".</summary>
|
||||
public string Platform { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>Semantic version string, e.g. "1.2.3".</summary>
|
||||
public string Version { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>If true, clients on any older version must update before playing.</summary>
|
||||
public bool IsRequired { get; set; }
|
||||
|
||||
/// <summary>Direct download or store URL for this release.</summary>
|
||||
public string? DownloadUrl { get; set; }
|
||||
|
||||
/// <summary>Human-readable release notes shown in the update prompt.</summary>
|
||||
public string? ReleaseNotes { get; set; }
|
||||
|
||||
/// <summary>Inactive releases are ignored by the version check.</summary>
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
public DateTimeOffset ReleasedAt { get; set; }
|
||||
}
|
||||
@@ -20,3 +20,11 @@ public enum FriendRequestStatus
|
||||
Accepted,
|
||||
Declined,
|
||||
}
|
||||
|
||||
public enum PresenceStatus
|
||||
{
|
||||
Online,
|
||||
InMatch,
|
||||
Away,
|
||||
Offline,
|
||||
}
|
||||
|
||||
Server/src/SOR.Database/Migrations/Catalog/20260226012910_AddDefinitionVersionAndRetired.Designer.cs
Generated
+334
@@ -0,0 +1,334 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using SOR.Database.Contexts;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SOR.Database.Migrations.Catalog
|
||||
{
|
||||
[DbContext(typeof(CatalogDbContext))]
|
||||
[Migration("20260226012910_AddDefinitionVersionAndRetired")]
|
||||
partial class AddDefinitionVersionAndRetired
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasDefaultSchema("catalog")
|
||||
.HasAnnotation("ProductVersion", "8.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardAnimationBinding", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("ActionName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("AnimationCdnUrl")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid>("CardDefinitionId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<bool>("IsAiGenerated")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CardDefinitionId", "ActionName")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("card_animation_bindings", "catalog");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardAsset", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("AssetType")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid>("CardDefinitionId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("CdnUrl")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<bool>("IsAiGenerated")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("MimeType")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CardDefinitionId", "AssetType");
|
||||
|
||||
b.ToTable("card_assets", "catalog");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardDefinition", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("AbilitiesJson")
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("abilities");
|
||||
|
||||
b.Property<string>("Affinity")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("AttackType")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool?>("CanAttack")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool?>("CanBeAttacked")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool?>("CanBeBlocked")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool?>("CanBeObstructed")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool?>("CanBeSacrificed")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool?>("CanDefend")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool?>("CanMove")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool?>("CanUseAbility")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("CardType")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int?>("CollectorNumber")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int?>("Damage")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<long>("DefinitionVersion")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.HasDefaultValue(0L);
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("EffectsJson")
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("effects");
|
||||
|
||||
b.Property<string[]>("Genus")
|
||||
.HasColumnType("text[]");
|
||||
|
||||
b.Property<bool>("IsPublished")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool>("IsRetired")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int?>("MaxAttackRange")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("MaxChannelRange")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("MaxDefense")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("MaxHealth")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("MinAttackRange")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("MinChannelRange")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("MovementPoints")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("MovementType")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("OtherCostsJson")
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("other_costs");
|
||||
|
||||
b.Property<Guid?>("PreviousTierId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Rarity")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool?>("RequiresLos")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<DateTimeOffset?>("RetiredAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid?>("SetId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int>("SpCost")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("StCost")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("TerramorphaMode")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int?>("Tier")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Affinity");
|
||||
|
||||
b.HasIndex("CardType");
|
||||
|
||||
b.HasIndex("DefinitionVersion");
|
||||
|
||||
b.HasIndex("Name");
|
||||
|
||||
b.HasIndex("PreviousTierId");
|
||||
|
||||
b.HasIndex("Rarity");
|
||||
|
||||
b.HasIndex("SetId");
|
||||
|
||||
b.HasIndex("IsPublished", "SetId");
|
||||
|
||||
b.ToTable("card_definitions", "catalog");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardSet", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Code")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateOnly?>("ReleaseDate")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Code")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("card_sets", "catalog");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardAnimationBinding", b =>
|
||||
{
|
||||
b.HasOne("SOR.Database.Entities.Catalog.CardDefinition", "CardDefinition")
|
||||
.WithMany("AnimationBindings")
|
||||
.HasForeignKey("CardDefinitionId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("CardDefinition");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardAsset", b =>
|
||||
{
|
||||
b.HasOne("SOR.Database.Entities.Catalog.CardDefinition", "CardDefinition")
|
||||
.WithMany("Assets")
|
||||
.HasForeignKey("CardDefinitionId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("CardDefinition");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardDefinition", b =>
|
||||
{
|
||||
b.HasOne("SOR.Database.Entities.Catalog.CardDefinition", "PreviousTier")
|
||||
.WithMany()
|
||||
.HasForeignKey("PreviousTierId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.HasOne("SOR.Database.Entities.Catalog.CardSet", "Set")
|
||||
.WithMany("Cards")
|
||||
.HasForeignKey("SetId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("PreviousTier");
|
||||
|
||||
b.Navigation("Set");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardDefinition", b =>
|
||||
{
|
||||
b.Navigation("AnimationBindings");
|
||||
|
||||
b.Navigation("Assets");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardSet", b =>
|
||||
{
|
||||
b.Navigation("Cards");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SOR.Database.Migrations.Catalog
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddDefinitionVersionAndRetired : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<long>(
|
||||
name: "DefinitionVersion",
|
||||
schema: "catalog",
|
||||
table: "card_definitions",
|
||||
type: "bigint",
|
||||
nullable: false,
|
||||
defaultValue: 0L);
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "IsRetired",
|
||||
schema: "catalog",
|
||||
table: "card_definitions",
|
||||
type: "boolean",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
migrationBuilder.AddColumn<DateTimeOffset>(
|
||||
name: "RetiredAt",
|
||||
schema: "catalog",
|
||||
table: "card_definitions",
|
||||
type: "timestamp with time zone",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_card_definitions_DefinitionVersion",
|
||||
schema: "catalog",
|
||||
table: "card_definitions",
|
||||
column: "DefinitionVersion");
|
||||
|
||||
// Postgres sequence + trigger: every INSERT or UPDATE automatically advances
|
||||
// DefinitionVersion, giving clients a monotonic cursor for incremental sync.
|
||||
migrationBuilder.Sql("""
|
||||
CREATE SEQUENCE IF NOT EXISTS catalog.card_definition_version_seq
|
||||
START 1 INCREMENT 1;
|
||||
|
||||
CREATE OR REPLACE FUNCTION catalog.set_definition_version()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
NEW."DefinitionVersion" := nextval('catalog.card_definition_version_seq');
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE TRIGGER trg_card_definitions_version
|
||||
BEFORE INSERT OR UPDATE ON catalog.card_definitions
|
||||
FOR EACH ROW EXECUTE FUNCTION catalog.set_definition_version();
|
||||
""");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.Sql("""
|
||||
DROP TRIGGER IF EXISTS trg_card_definitions_version ON catalog.card_definitions;
|
||||
DROP FUNCTION IF EXISTS catalog.set_definition_version();
|
||||
DROP SEQUENCE IF EXISTS catalog.card_definition_version_seq;
|
||||
""");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_card_definitions_DefinitionVersion",
|
||||
schema: "catalog",
|
||||
table: "card_definitions");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "DefinitionVersion",
|
||||
schema: "catalog",
|
||||
table: "card_definitions");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "IsRetired",
|
||||
schema: "catalog",
|
||||
table: "card_definitions");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "RetiredAt",
|
||||
schema: "catalog",
|
||||
table: "card_definitions");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,6 +138,11 @@ namespace SOR.Database.Migrations.Catalog
|
||||
b.Property<int?>("Damage")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<long>("DefinitionVersion")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.HasDefaultValue(0L);
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
@@ -152,6 +157,9 @@ namespace SOR.Database.Migrations.Catalog
|
||||
b.Property<bool>("IsPublished")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool>("IsRetired")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int?>("MaxAttackRange")
|
||||
.HasColumnType("integer");
|
||||
|
||||
@@ -194,6 +202,9 @@ namespace SOR.Database.Migrations.Catalog
|
||||
b.Property<bool?>("RequiresLos")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<DateTimeOffset?>("RetiredAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid?>("SetId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
@@ -218,6 +229,8 @@ namespace SOR.Database.Migrations.Catalog
|
||||
|
||||
b.HasIndex("CardType");
|
||||
|
||||
b.HasIndex("DefinitionVersion");
|
||||
|
||||
b.HasIndex("Name");
|
||||
|
||||
b.HasIndex("PreviousTierId");
|
||||
|
||||
Generated
+272
@@ -0,0 +1,272 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using SOR.Database.Contexts;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SOR.Database.Migrations.Chat
|
||||
{
|
||||
[DbContext(typeof(ChatDbContext))]
|
||||
[Migration("20260226012908_AddPresenceAndNotifications")]
|
||||
partial class AddPresenceAndNotifications
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasDefaultSchema("chat")
|
||||
.HasAnnotation("ProductVersion", "8.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Chat.AccountPresence", b =>
|
||||
{
|
||||
b.Property<Guid>("AccountId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid?>("CurrentMatchId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("LastSeenAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("AccountId");
|
||||
|
||||
b.ToTable("account_presence", "chat");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Chat.BlockedUser", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("BlockedAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("BlockedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("BlockerAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BlockerAccountId");
|
||||
|
||||
b.HasIndex("BlockerAccountId", "BlockedAccountId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("blocked_users", "chat");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Chat.ChatChannel", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("ChannelType")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("MatchId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ChannelType");
|
||||
|
||||
b.HasIndex("MatchId");
|
||||
|
||||
b.ToTable("channels", "chat");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Chat.ChatMember", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("AccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("ChannelId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("JoinedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTimeOffset?>("LeftAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AccountId");
|
||||
|
||||
b.HasIndex("ChannelId", "AccountId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("members", "chat");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Chat.ChatMessage", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("ChannelId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Content")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTimeOffset?>("EditedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<Guid>("SenderAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("SentAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("SenderAccountId");
|
||||
|
||||
b.HasIndex("ChannelId", "SentAt");
|
||||
|
||||
b.ToTable("messages", "chat");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Chat.FriendRequest", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("RecipientAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("RequesterAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RecipientAccountId");
|
||||
|
||||
b.HasIndex("Status");
|
||||
|
||||
b.HasIndex("RequesterAccountId", "RecipientAccountId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("friend_requests", "chat");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Chat.Notification", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Body")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("NotificationType")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PayloadJson")
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("payload");
|
||||
|
||||
b.Property<DateTimeOffset?>("ReadAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("RecipientAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RecipientAccountId", "ReadAt", "CreatedAt");
|
||||
|
||||
b.ToTable("notifications", "chat");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Chat.ChatMember", b =>
|
||||
{
|
||||
b.HasOne("SOR.Database.Entities.Chat.ChatChannel", "Channel")
|
||||
.WithMany("Members")
|
||||
.HasForeignKey("ChannelId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Channel");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Chat.ChatMessage", b =>
|
||||
{
|
||||
b.HasOne("SOR.Database.Entities.Chat.ChatChannel", "Channel")
|
||||
.WithMany("Messages")
|
||||
.HasForeignKey("ChannelId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Channel");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Chat.ChatChannel", b =>
|
||||
{
|
||||
b.Navigation("Members");
|
||||
|
||||
b.Navigation("Messages");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SOR.Database.Migrations.Chat
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddPresenceAndNotifications : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "account_presence",
|
||||
schema: "chat",
|
||||
columns: table => new
|
||||
{
|
||||
AccountId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
Status = table.Column<string>(type: "text", nullable: false),
|
||||
CurrentMatchId = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
LastSeenAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_account_presence", x => x.AccountId);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "notifications",
|
||||
schema: "chat",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
RecipientAccountId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
NotificationType = table.Column<string>(type: "text", nullable: false),
|
||||
Title = table.Column<string>(type: "text", nullable: false),
|
||||
Body = table.Column<string>(type: "text", nullable: false),
|
||||
payload = table.Column<string>(type: "jsonb", nullable: true),
|
||||
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
ReadAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_notifications", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_notifications_RecipientAccountId_ReadAt_CreatedAt",
|
||||
schema: "chat",
|
||||
table: "notifications",
|
||||
columns: new[] { "RecipientAccountId", "ReadAt", "CreatedAt" });
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "account_presence",
|
||||
schema: "chat");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "notifications",
|
||||
schema: "chat");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,30 @@ namespace SOR.Database.Migrations.Chat
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Chat.AccountPresence", b =>
|
||||
{
|
||||
b.Property<Guid>("AccountId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid?>("CurrentMatchId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("LastSeenAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("AccountId");
|
||||
|
||||
b.ToTable("account_presence", "chat");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Chat.BlockedUser", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@@ -173,6 +197,44 @@ namespace SOR.Database.Migrations.Chat
|
||||
b.ToTable("friend_requests", "chat");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Chat.Notification", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Body")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("NotificationType")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PayloadJson")
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("payload");
|
||||
|
||||
b.Property<DateTimeOffset?>("ReadAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("RecipientAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RecipientAccountId", "ReadAt", "CreatedAt");
|
||||
|
||||
b.ToTable("notifications", "chat");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Chat.ChatMember", b =>
|
||||
{
|
||||
b.HasOne("SOR.Database.Entities.Chat.ChatChannel", "Channel")
|
||||
|
||||
+407
@@ -0,0 +1,407 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using SOR.Database.Contexts;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SOR.Database.Migrations.Identity
|
||||
{
|
||||
[DbContext(typeof(SorIdentityDbContext))]
|
||||
[Migration("20260226012858_AddClientReleases")]
|
||||
partial class AddClientReleases
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasDefaultSchema("identity")
|
||||
.HasAnnotation("ProductVersion", "8.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole<System.Guid>", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("ConcurrencyStamp")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)");
|
||||
|
||||
b.Property<string>("NormalizedName")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NormalizedName")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("RoleNameIndex");
|
||||
|
||||
b.ToTable("roles", "identity");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<System.Guid>", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ClaimType")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ClaimValue")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid>("RoleId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("role_claims", "identity");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<System.Guid>", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ClaimType")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ClaimValue")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("account_claims", "identity");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<System.Guid>", b =>
|
||||
{
|
||||
b.Property<string>("LoginProvider")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ProviderKey")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ProviderDisplayName")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("LoginProvider", "ProviderKey");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("external_logins", "identity");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<System.Guid>", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("RoleId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("UserId", "RoleId");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("account_roles", "identity");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<System.Guid>", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("LoginProvider")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Value")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("UserId", "LoginProvider", "Name");
|
||||
|
||||
b.ToTable("account_tokens", "identity");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Identity.Account", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int>("AccessFailedCount")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("AvatarCdnUrl")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ConcurrencyStamp")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("DisplayName")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)");
|
||||
|
||||
b.Property<bool>("EmailConfirmed")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<DateTimeOffset?>("LastLoginAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<bool>("LockoutEnabled")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<DateTimeOffset?>("LockoutEnd")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("NormalizedEmail")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)");
|
||||
|
||||
b.Property<string>("NormalizedUserName")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)");
|
||||
|
||||
b.Property<int>("OriginPoints")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("PhoneNumberConfirmed")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("SecurityStamp")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTimeOffset?>("StarterDeckSelectedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<bool>("TwoFactorEnabled")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("UserName")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DisplayName");
|
||||
|
||||
b.HasIndex("NormalizedEmail")
|
||||
.HasDatabaseName("EmailIndex");
|
||||
|
||||
b.HasIndex("NormalizedUserName")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("UserNameIndex");
|
||||
|
||||
b.ToTable("accounts", "identity");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Identity.AccountProperty", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("AccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AccountId");
|
||||
|
||||
b.HasIndex("AccountId", "Key")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("account_properties", "identity");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Identity.AccountSession", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("AccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("DeviceId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("IpAddress")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTimeOffset?>("RevokedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("TokenHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("UserAgent")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("TokenHash")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("AccountId", "ExpiresAt");
|
||||
|
||||
b.ToTable("account_sessions", "identity");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Identity.ClientRelease", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("DownloadUrl")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool>("IsRequired")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Platform")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ReleaseNotes")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTimeOffset>("ReleasedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Version")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Platform", "IsActive", "ReleasedAt");
|
||||
|
||||
b.ToTable("client_releases", "identity");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<System.Guid>", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole<System.Guid>", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<System.Guid>", b =>
|
||||
{
|
||||
b.HasOne("SOR.Database.Entities.Identity.Account", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<System.Guid>", b =>
|
||||
{
|
||||
b.HasOne("SOR.Database.Entities.Identity.Account", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<System.Guid>", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole<System.Guid>", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SOR.Database.Entities.Identity.Account", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<System.Guid>", b =>
|
||||
{
|
||||
b.HasOne("SOR.Database.Entities.Identity.Account", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SOR.Database.Migrations.Identity
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddClientReleases : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "client_releases",
|
||||
schema: "identity",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
Platform = table.Column<string>(type: "text", nullable: false),
|
||||
Version = table.Column<string>(type: "text", nullable: false),
|
||||
IsRequired = table.Column<bool>(type: "boolean", nullable: false),
|
||||
DownloadUrl = table.Column<string>(type: "text", nullable: true),
|
||||
ReleaseNotes = table.Column<string>(type: "text", nullable: true),
|
||||
IsActive = table.Column<bool>(type: "boolean", nullable: false),
|
||||
ReleasedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_client_releases", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_client_releases_Platform_IsActive_ReleasedAt",
|
||||
schema: "identity",
|
||||
table: "client_releases",
|
||||
columns: new[] { "Platform", "IsActive", "ReleasedAt" });
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "client_releases",
|
||||
schema: "identity");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -312,6 +312,42 @@ namespace SOR.Database.Migrations.Identity
|
||||
b.ToTable("account_sessions", "identity");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Identity.ClientRelease", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("DownloadUrl")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool>("IsRequired")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Platform")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ReleaseNotes")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTimeOffset>("ReleasedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Version")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Platform", "IsActive", "ReleasedAt");
|
||||
|
||||
b.ToTable("client_releases", "identity");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<System.Guid>", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole<System.Guid>", null)
|
||||
|
||||
@@ -16,7 +16,9 @@ using SOR.Auth;
|
||||
using SOR.Bazaar;
|
||||
using SOR.Chat;
|
||||
using SOR.Collection;
|
||||
using SOR.Content;
|
||||
using SOR.Gateway;
|
||||
using SOR.Versioning;
|
||||
using SOR.Networking.Nats;
|
||||
using SOR.Networking.Redis;
|
||||
using SOR.Networking.WebSocket;
|
||||
@@ -136,10 +138,11 @@ if (IsEnabled("collection")) builder.Services.AddCollectionService(builder.Confi
|
||||
if (IsEnabled("gateway")) builder.Services.AddGatewayService(builder.Configuration);
|
||||
|
||||
if (IsEnabled("bazaar")) builder.Services.AddBazaarService(builder.Configuration);
|
||||
if (IsEnabled("content")) builder.Services.AddContentService(builder.Configuration);
|
||||
if (IsEnabled("versioning")) builder.Services.AddVersioningService(builder.Configuration);
|
||||
|
||||
// TODO: Uncomment as each service is implemented:
|
||||
// if (IsEnabled("leaderboard")) builder.Services.AddLeaderboardService(builder.Configuration);
|
||||
// if (IsEnabled("content")) builder.Services.AddContentService(builder.Configuration);
|
||||
// if (IsEnabled("admin")) builder.Services.AddAdminService(builder.Configuration);
|
||||
|
||||
// ── BUILD ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -32,5 +32,7 @@
|
||||
<ProjectReference Include="..\SOR.Chat\SOR.Chat.csproj" />
|
||||
<ProjectReference Include="..\SOR.Collection\SOR.Collection.csproj" />
|
||||
<ProjectReference Include="..\SOR.Bazaar\SOR.Bazaar.csproj" />
|
||||
<ProjectReference Include="..\SOR.Content\SOR.Content.csproj" />
|
||||
<ProjectReference Include="..\SOR.Versioning\SOR.Versioning.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
namespace SOR.Versioning.Handlers;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Networking.Abstractions.Transport;
|
||||
using SOR.Shared.Networking;
|
||||
|
||||
/// <summary>
|
||||
/// version.check — returns whether the client is current, needs an optional update,
|
||||
/// or is blocked until it updates.
|
||||
/// </summary>
|
||||
internal sealed class VersionCheckHandler : IMessageHandler
|
||||
{
|
||||
private readonly IMessageSerializer _serializer;
|
||||
private readonly SorIdentityDbContext _identityDb;
|
||||
|
||||
public VersionCheckHandler(IMessageSerializer serializer, SorIdentityDbContext identityDb)
|
||||
{
|
||||
_serializer = serializer;
|
||||
_identityDb = identityDb;
|
||||
}
|
||||
|
||||
public string MessageType => "version.check";
|
||||
|
||||
public async Task<IServerMessage?> HandleAsync(
|
||||
IClientMessage message,
|
||||
AuthenticatedConnection connection,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var req = _serializer.DeserializePayload<CheckVersionRequest>(message.Payload);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(req.ClientVersion) || string.IsNullOrWhiteSpace(req.Platform))
|
||||
return ServerMessage.Error(message.Seq, "INVALID_REQUEST",
|
||||
"ClientVersion and Platform are required.");
|
||||
|
||||
var platform = req.Platform.Trim().ToLowerInvariant();
|
||||
|
||||
// All active releases for this platform, newest first.
|
||||
var releases = await _identityDb.ClientReleases
|
||||
.Where(r => r.IsActive && r.Platform == platform)
|
||||
.OrderByDescending(r => r.ReleasedAt)
|
||||
.ToListAsync(ct);
|
||||
|
||||
if (releases.Count == 0)
|
||||
{
|
||||
// No releases configured — treat as up to date.
|
||||
return ServerMessage.Reply("version.check.ack", message.Seq,
|
||||
new CheckVersionResponse("Ok", req.ClientVersion, null, null));
|
||||
}
|
||||
|
||||
var latest = releases[0];
|
||||
var isOutdated = CompareVersions(req.ClientVersion, latest.Version) < 0;
|
||||
|
||||
if (!isOutdated)
|
||||
{
|
||||
return ServerMessage.Reply("version.check.ack", message.Seq,
|
||||
new CheckVersionResponse("Ok", latest.Version, latest.DownloadUrl, null));
|
||||
}
|
||||
|
||||
// If any active release newer than the client is marked IsRequired, block the client.
|
||||
var requiresUpdate = releases.Any(r =>
|
||||
CompareVersions(req.ClientVersion, r.Version) < 0 && r.IsRequired);
|
||||
|
||||
var status = requiresUpdate ? "UpdateRequired" : "UpdateAvailable";
|
||||
|
||||
return ServerMessage.Reply("version.check.ack", message.Seq,
|
||||
new CheckVersionResponse(status, latest.Version, latest.DownloadUrl, latest.ReleaseNotes));
|
||||
}
|
||||
|
||||
private static int CompareVersions(string a, string b)
|
||||
{
|
||||
if (Version.TryParse(a, out var va) && Version.TryParse(b, out var vb))
|
||||
return va.CompareTo(vb);
|
||||
return string.Compare(a, b, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<AssemblyName>SOR.Versioning</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SOR.Database\SOR.Database.csproj" />
|
||||
<ProjectReference Include="..\SOR.Networking.Abstractions\SOR.Networking.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\SOR.Shared\SOR.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace SOR.Versioning;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SOR.Database;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Versioning.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// Registers all versioning service components into the DI container.
|
||||
/// Called from SOR.Host/Program.cs when ENABLED_SERVICES includes "versioning".
|
||||
/// </summary>
|
||||
public static class ServiceRegistration
|
||||
{
|
||||
public static IServiceCollection AddVersioningService(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
services.AddIdentityDatabase(configuration);
|
||||
|
||||
services.AddTransient<IMessageHandler, VersionCheckHandler>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace SOR.Versioning;
|
||||
|
||||
// ── Request types (client → server) ──────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Check whether the client is on the latest version.
|
||||
/// Platform values: "android", "ios", "pc", "web".
|
||||
/// </summary>
|
||||
public sealed record CheckVersionRequest(string ClientVersion, string Platform);
|
||||
|
||||
// ── Response / DTO types (server → client) ────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Status values:
|
||||
/// Ok — client is up to date.
|
||||
/// UpdateAvailable — a newer version exists but is not required to play.
|
||||
/// UpdateRequired — client must update before proceeding.
|
||||
/// </summary>
|
||||
public sealed record CheckVersionResponse(
|
||||
string Status,
|
||||
string LatestVersion,
|
||||
string? DownloadUrl,
|
||||
string? ReleaseNotes);
|
||||
Reference in New Issue
Block a user