English
Topic 10. Chats and permissions: direct chats, groups, channels, roles, membership and real-time events
Goal: implement the rules of chats — who sees a chat, who may post, edit and manage members — and the chat service that opens direct chats once per pair, creates groups and channels with public handles, manages membership, roles and read positions, and announces every change through an event interface that the API will connect to SignalR.
Where we are
The largest service of the business layer (Fig. 10.1). It is also the first one that raises events; the SignalR side comes in topic 14.
Fig. 10.1. The chat service and its rules
- Starting point: topic 9 — users, profiles and avatars work; 17 business tests pass.
- At the end of the topic
IChatServiceis complete, every change raises an event, a recording fake proves the events in tests, and 26 business tests pass. Four more chat tests need messages and follow in topic 11.
Steps
- Rules of chats — errors and limits · permissions as small functions · visibility of private chats
- Events — dependency inversion · the message and attachment DTOs ·
IChatNotifierand the Null Object - The chat service — DTOs and validators · direct chats and races · groups and channels · membership and roles · read positions · registration
- Testing chats — a recording notifier · new helpers · the chat tests
- Checkpoint — what must work, self-check questions and exercises
Materials
- Course slides, part 2, Data (slide "Chat types and roles") and part 3, Backend in C# (slides "Dependency inversion: IChatNotifier", "Permissions as switch expressions")
Chats/,IChatNotifier.csDocs/ChatRules.md– chat types, roles, permissions and visibilityChatServiceTests.cs