Implement useful account mailbox with thread view, reply, and delete
This commit is contained in:
@@ -63,6 +63,12 @@ public sealed record GetNotificationsRequest(bool UnreadOnly = false);
|
||||
/// </summary>
|
||||
public sealed record MarkNotificationsReadRequest(IEnumerable<Guid>? NotificationIds = null);
|
||||
|
||||
/// <summary>
|
||||
/// Delete notifications from mailbox.
|
||||
/// Null or empty NotificationIds = delete ALL notifications for the caller.
|
||||
/// </summary>
|
||||
public sealed record DeleteNotificationsRequest(IEnumerable<Guid>? NotificationIds = null);
|
||||
|
||||
/// <summary>
|
||||
/// Invite another player to the caller's party.
|
||||
/// Creates a Party channel for the caller if they don't have one yet.
|
||||
@@ -107,6 +113,8 @@ public sealed record GetNotificationsResponse(
|
||||
|
||||
public sealed record MarkNotificationsReadResponse;
|
||||
|
||||
public sealed record DeleteNotificationsResponse;
|
||||
|
||||
/// <summary>Returned to the inviter after a successful party invite is dispatched.</summary>
|
||||
public sealed record PartyInviteResponse(ChatChannelDto Channel);
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
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.delete — deletes one or more notifications for the caller.
|
||||
/// If NotificationIds is null or empty, deletes ALL notifications for the caller.
|
||||
/// </summary>
|
||||
internal sealed class ChatDeleteNotificationsHandler : ChatHandlerBase, IMessageHandler
|
||||
{
|
||||
private readonly IMessageSerializer _serializer;
|
||||
private readonly ChatDbContext _chatDb;
|
||||
|
||||
public ChatDeleteNotificationsHandler(IMessageSerializer serializer, ChatDbContext chatDb)
|
||||
{
|
||||
_serializer = serializer;
|
||||
_chatDb = chatDb;
|
||||
}
|
||||
|
||||
public string MessageType => "chat.notifications.delete";
|
||||
|
||||
public async Task<IServerMessage?> HandleAsync(
|
||||
IClientMessage message,
|
||||
AuthenticatedConnection connection,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var req = _serializer.DeserializePayload<DeleteNotificationsRequest>(message.Payload);
|
||||
var accountId = Guid.Parse(connection.UserId);
|
||||
|
||||
if (req.NotificationIds is null || !req.NotificationIds.Any())
|
||||
{
|
||||
await _chatDb.Notifications
|
||||
.Where(n => n.RecipientAccountId == accountId)
|
||||
.ExecuteDeleteAsync(ct);
|
||||
}
|
||||
else
|
||||
{
|
||||
var ids = req.NotificationIds.ToList();
|
||||
await _chatDb.Notifications
|
||||
.Where(n => n.RecipientAccountId == accountId && ids.Contains(n.Id))
|
||||
.ExecuteDeleteAsync(ct);
|
||||
}
|
||||
|
||||
return ServerMessage.Reply("chat.notifications.delete.ack", message.Seq, new DeleteNotificationsResponse());
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ public static class ServiceRegistration
|
||||
services.AddTransient<IMessageHandler, ChatGetPresenceHandler>();
|
||||
services.AddTransient<IMessageHandler, ChatGetNotificationsHandler>();
|
||||
services.AddTransient<IMessageHandler, ChatMarkNotificationsReadHandler>();
|
||||
services.AddTransient<IMessageHandler, ChatDeleteNotificationsHandler>();
|
||||
services.AddTransient<IMessageHandler, ChatPartyInviteHandler>();
|
||||
services.AddTransient<IMessageHandler, ChatPartyInviteRespondHandler>();
|
||||
services.AddTransient<IMessageHandler, ChatPartyLeaveHandler>();
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
namespace SOR.Support.Handlers;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Networking.Abstractions.Transport;
|
||||
using SOR.Shared.Networking;
|
||||
|
||||
/// <summary>
|
||||
/// support.get_bug_report_thread — fetches a specific bug report thread for the caller.
|
||||
/// </summary>
|
||||
internal sealed class GetBugReportThreadHandler : IMessageHandler
|
||||
{
|
||||
private readonly IMessageSerializer _serializer;
|
||||
private readonly SupportDbContext _supportDb;
|
||||
|
||||
public GetBugReportThreadHandler(IMessageSerializer serializer, SupportDbContext supportDb)
|
||||
{
|
||||
_serializer = serializer;
|
||||
_supportDb = supportDb;
|
||||
}
|
||||
|
||||
public string MessageType => "support.get_bug_report_thread";
|
||||
|
||||
public async Task<IServerMessage?> HandleAsync(
|
||||
IClientMessage message,
|
||||
AuthenticatedConnection connection,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var req = _serializer.DeserializePayload<GetBugReportThreadRequest>(message.Payload);
|
||||
var accountId = Guid.Parse(connection.UserId);
|
||||
|
||||
var report = await _supportDb.BugReports
|
||||
.Include(r => r.Responses)
|
||||
.FirstOrDefaultAsync(r => r.Id == req.BugReportId, cancellationToken);
|
||||
|
||||
if (report is null)
|
||||
return ServerMessage.Error(message.Seq, "NOT_FOUND", "Bug report not found.");
|
||||
|
||||
if (report.SubmitterAccountId != accountId)
|
||||
return ServerMessage.Error(message.Seq, "FORBIDDEN", "You do not have access to this bug report.");
|
||||
|
||||
var responseDtos = report.Responses
|
||||
.OrderBy(r => r.CreatedAt)
|
||||
.Select(r => new BugReportResponseDto(
|
||||
r.Id,
|
||||
r.AdminAccountId,
|
||||
r.AdminDisplayName,
|
||||
r.Content,
|
||||
r.CreatedAt));
|
||||
|
||||
var dto = new BugReportThreadDto(
|
||||
report.Id,
|
||||
report.Category,
|
||||
report.Title,
|
||||
report.Description,
|
||||
report.StepsToReproduce,
|
||||
report.Status,
|
||||
report.CreatedAt,
|
||||
report.UpdatedAt,
|
||||
responseDtos);
|
||||
|
||||
return ServerMessage.Reply("support.get_bug_report_thread.ack", message.Seq,
|
||||
new GetBugReportThreadResponse(dto));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
namespace SOR.Support.Handlers;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Database.Entities.Support;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Networking.Abstractions.Transport;
|
||||
using SOR.Shared.Networking;
|
||||
|
||||
/// <summary>
|
||||
/// support.reply_bug_report — lets the submitter reply to their own support thread.
|
||||
/// </summary>
|
||||
internal sealed class ReplyBugReportHandler : IMessageHandler
|
||||
{
|
||||
private readonly IMessageSerializer _serializer;
|
||||
private readonly SupportDbContext _supportDb;
|
||||
|
||||
public ReplyBugReportHandler(IMessageSerializer serializer, SupportDbContext supportDb)
|
||||
{
|
||||
_serializer = serializer;
|
||||
_supportDb = supportDb;
|
||||
}
|
||||
|
||||
public string MessageType => "support.reply_bug_report";
|
||||
|
||||
public async Task<IServerMessage?> HandleAsync(
|
||||
IClientMessage message,
|
||||
AuthenticatedConnection connection,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var req = _serializer.DeserializePayload<ReplyBugReportRequest>(message.Payload);
|
||||
var accountId = Guid.Parse(connection.UserId);
|
||||
|
||||
var content = req.Content?.Trim() ?? string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(content))
|
||||
return ServerMessage.Error(message.Seq, "INVALID_PAYLOAD", "Reply content is required.");
|
||||
|
||||
var report = await _supportDb.BugReports
|
||||
.FirstOrDefaultAsync(r => r.Id == req.BugReportId, cancellationToken);
|
||||
|
||||
if (report is null)
|
||||
return ServerMessage.Error(message.Seq, "NOT_FOUND", "Bug report not found.");
|
||||
|
||||
if (report.SubmitterAccountId != accountId)
|
||||
return ServerMessage.Error(message.Seq, "FORBIDDEN", "You can only reply to your own bug report.");
|
||||
|
||||
var response = new BugReportResponse
|
||||
{
|
||||
BugReportId = report.Id,
|
||||
AdminAccountId = accountId,
|
||||
AdminDisplayName = connection.DisplayName,
|
||||
Content = content[..Math.Min(content.Length, 4000)],
|
||||
CreatedAt = DateTimeOffset.UtcNow,
|
||||
};
|
||||
|
||||
report.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
if (report.Status is "Resolved" or "Closed")
|
||||
report.Status = "InProgress";
|
||||
|
||||
_supportDb.BugReportResponses.Add(response);
|
||||
await _supportDb.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return ServerMessage.Reply("support.reply_bug_report.ack", message.Seq,
|
||||
new ReplyBugReportResponse(new BugReportResponseDto(
|
||||
response.Id,
|
||||
response.AdminAccountId,
|
||||
response.AdminDisplayName,
|
||||
response.Content,
|
||||
response.CreatedAt)));
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,8 @@ public static class ServiceRegistration
|
||||
services.AddTransient<IMessageHandler, SubmitBugReportHandler>();
|
||||
services.AddTransient<IMessageHandler, GetLeaderboardHandler>();
|
||||
services.AddTransient<IMessageHandler, GetAccountProfileHandler>();
|
||||
services.AddTransient<IMessageHandler, GetBugReportThreadHandler>();
|
||||
services.AddTransient<IMessageHandler, ReplyBugReportHandler>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,12 @@ public sealed record GetLeaderboardRequest(
|
||||
/// <summary>Fetch the caller's own account profile.</summary>
|
||||
public sealed record GetAccountProfileRequest; // identity from connection
|
||||
|
||||
/// <summary>Fetch full thread details for one bug report in the caller's mailbox.</summary>
|
||||
public sealed record GetBugReportThreadRequest(Guid BugReportId);
|
||||
|
||||
/// <summary>Reply to an existing bug report thread as the submitting player.</summary>
|
||||
public sealed record ReplyBugReportRequest(Guid BugReportId, string Content);
|
||||
|
||||
// ── Response types (server → client) ─────────────────────────────────────────
|
||||
|
||||
public sealed record SubmitBugReportResponse(Guid ReportId);
|
||||
@@ -33,6 +39,10 @@ public sealed record GetAccountProfileResponse(
|
||||
int OriginPoints,
|
||||
int RankScore);
|
||||
|
||||
public sealed record GetBugReportThreadResponse(BugReportThreadDto Thread);
|
||||
|
||||
public sealed record ReplyBugReportResponse(BugReportResponseDto Response);
|
||||
|
||||
// ── DTOs ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
public sealed record LeaderboardEntryDto(
|
||||
@@ -40,3 +50,21 @@ public sealed record LeaderboardEntryDto(
|
||||
Guid AccountId,
|
||||
string DisplayName,
|
||||
int RankScore);
|
||||
|
||||
public sealed record BugReportThreadDto(
|
||||
Guid Id,
|
||||
string Category,
|
||||
string Title,
|
||||
string Description,
|
||||
string? StepsToReproduce,
|
||||
string Status,
|
||||
DateTimeOffset CreatedAt,
|
||||
DateTimeOffset? UpdatedAt,
|
||||
IEnumerable<BugReportResponseDto> Responses);
|
||||
|
||||
public sealed record BugReportResponseDto(
|
||||
Guid Id,
|
||||
Guid AuthorAccountId,
|
||||
string AuthorDisplayName,
|
||||
string Content,
|
||||
DateTimeOffset CreatedAt);
|
||||
|
||||
Reference in New Issue
Block a user