feat(web): wire domain events into realtime stream
This commit is contained in:
1 parent
8c8ff11fd7
commit
d5f0175dc2
6 files changed
+155
-1
No files matched your search
@@ -0,0 +1,53 @@
|
||||
interface DeliveryEvents {
|
||||
messageSent(input: { id: string; username: string; conversationId?: string }): unknown;
|
||||
messageFailed(input: { username: string; error: unknown; messageId?: string; conversationId?: string }): unknown;
|
||||
}
|
||||
|
||||
interface ConversationEvents {
|
||||
conversation(input: { id: string; state: 'replied'; unread?: number }): unknown;
|
||||
reply(input: { conversationId: string; id: string; username: string; body?: string }): unknown;
|
||||
}
|
||||
|
||||
interface RateLimitEvents {
|
||||
rateLimit(input: { blocked: boolean; resetAt?: number; reason?: string }): unknown;
|
||||
}
|
||||
|
||||
interface DeliveryResult {
|
||||
success: boolean;
|
||||
messageId: string;
|
||||
username: string;
|
||||
conversationId?: string;
|
||||
error?: unknown;
|
||||
}
|
||||
|
||||
export function reportDeliveryResult(events: DeliveryEvents, result: DeliveryResult): void {
|
||||
if (result.success) {
|
||||
events.messageSent({ id: result.messageId, username: result.username, conversationId: result.conversationId });
|
||||
return;
|
||||
}
|
||||
events.messageFailed({
|
||||
messageId: result.messageId,
|
||||
username: result.username,
|
||||
conversationId: result.conversationId,
|
||||
error: result.error ?? 'Message delivery failed',
|
||||
});
|
||||
}
|
||||
|
||||
export function reportReply(
|
||||
events: ConversationEvents,
|
||||
reply: { conversationId: string; replyId: string; username: string; body?: string },
|
||||
): void {
|
||||
events.conversation({ id: reply.conversationId, state: 'replied', unread: 1 });
|
||||
events.reply({ conversationId: reply.conversationId, id: reply.replyId, username: reply.username, body: reply.body });
|
||||
}
|
||||
|
||||
export function reportInvitationCooldown(
|
||||
events: RateLimitEvents,
|
||||
cooldown: { until: number; reason: string } | null,
|
||||
): void {
|
||||
if (cooldown) {
|
||||
events.rateLimit({ blocked: true, resetAt: cooldown.until, reason: cooldown.reason });
|
||||
return;
|
||||
}
|
||||
events.rateLimit({ blocked: false });
|
||||
}
|
||||
Reference in new issue
Block a user