Skip to content
bitzorcas
EN

Reference

Chat module

Multi-channel messaging — ChatService with channels, members, messages, mentions, read markers, file attachments, and a pluggable realtime adapter interface.

Last updated

The Chat module provides multi-channel messaging with channels, members, threaded messages, mentions, read markers, and file attachments. It follows the same port/adapter pattern as other modules.

Endpoints

EndpointMethodDescription
/api/chat/channelsPOSTCreate channel
/api/chat/channelsGETList channels
/api/chat/channels/{id}/membersPOSTAdd member
/api/chat/channels/{id}/messagesPOSTSend message
/api/chat/channels/{id}/messagesGETPaginated messages
/api/chat/channels/{id}/readPOSTMark as read
/api/chat/messages/{id}PATCHEdit message

Architecture

ChatEndpoints (Minimal API)
ChatService
├── IChatRepository → SqlSugarChatRepository
├── IChatEventPublisher → NullChatEventPublisher
├── IChatRealtimeAdapter → NullChatRealtimeAdapter (roadmap: SignalR)
└── IChatAttachmentAccessService → FileAssetChatAttachmentAccessService

Entities

EntityPurpose
ChatChannelEntityChannel definition (name, type, tenant)
ChatMemberEntityChannel membership (user + role)
ChatMessageEntityMessages (content, sender, edited flag)
ChatAttachmentEntityMessage file attachments
ChatMentionEntity@mention tracking
ChatReadMarkerEntityPer-user read position

Permissions

Chat uses attribute-based permissions via ChatPermissions:

public static class ChatPermissions
{
public const string ChannelCreate = "chat.channel.create";
public const string ChannelManage = "chat.channel.manage";
public const string MessageSend = "chat.message.send";
public const string MessageEdit = "chat.message.edit";
public const string MemberManage = "chat.member.manage";
}

Message pagination

public class ChatMessagePage
{
public IReadOnlyList<ChatMessage> Messages { get; }
public int TotalCount { get; }
public bool HasMore { get; }
}

Messages are loaded in reverse chronological order with cursor-based pagination.

Realtime adapter (roadmap)

public interface IChatRealtimeAdapter
{
Task MessageCreatedAsync(ChatMessage message, CancellationToken ct);
Task MessageEditedAsync(ChatMessage message, CancellationToken ct);
Task MemberJoinedAsync(ChatMember member, CancellationToken ct);
}

Planned implementations: SignalR hub, Server-Sent Events, WebSocket adapter.

See also