Files
sor/Server/src/SOR.Chat/ChatMessages.cs
T
4663003dd7 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>
2026-02-25 20:35:35 -05:00

140 lines
4.9 KiB
C#

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>
public sealed record SendMessageRequest(Guid ChannelId, string Content);
/// <summary>List all channels the caller is currently a member of.</summary>
public sealed record GetChannelsRequest; // identity from connection
/// <summary>
/// Fetch message history for a channel.
/// BeforeMessageId enables cursor-based pagination: pass the oldest
/// message Id from the previous page to load earlier messages.
/// Null = start from the most recent messages.
/// </summary>
public sealed record GetMessagesRequest(
Guid ChannelId,
Guid? BeforeMessageId = null,
int PageSize = ChatLimits.DefaultPageSize);
/// <summary>
/// Open (or retrieve) the DM channel with another player.
/// Creates the channel and adds both members if it does not already exist.
/// Fails if the recipient has blocked the caller or vice-versa.
/// </summary>
public sealed record DmOpenRequest(Guid RecipientAccountId);
/// <summary>Send a friend request to another player.</summary>
public sealed record FriendRequestRequest(Guid RecipientAccountId);
/// <summary>Accept or decline an incoming friend request.</summary>
public sealed record FriendRespondRequest(Guid RequestId, bool Accept);
/// <summary>Remove an existing friendship.</summary>
public sealed record FriendRemoveRequest(Guid FriendAccountId);
/// <summary>Block a player (dissolves friendship and any pending friend request).</summary>
public sealed record BlockRequest(Guid TargetAccountId);
/// <summary>Remove a block previously placed on a player.</summary>
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);
public sealed record GetChannelsResponse(IEnumerable<ChatChannelDto> Channels);
public sealed record GetMessagesResponse(
IEnumerable<ChatMessageDto> Messages,
bool HasMore);
public sealed record DmOpenResponse(Guid ChannelId);
public sealed record GetSocialResponse(
IEnumerable<FriendDto> Friends,
IEnumerable<FriendRequestDto> IncomingRequests,
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(
Guid Id,
string Name,
string ChannelType,
DateTimeOffset CreatedAt);
public sealed record ChatMessageDto(
Guid Id,
Guid ChannelId,
Guid SenderAccountId,
string SenderDisplayName,
string Content,
DateTimeOffset SentAt,
DateTimeOffset? EditedAt,
bool IsDeleted);
public sealed record FriendDto(
Guid AccountId,
string DisplayName,
DateTimeOffset FriendsSince);
public sealed record FriendRequestDto(
Guid RequestId,
Guid OtherAccountId,
string OtherDisplayName,
DateTimeOffset CreatedAt);
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);