feat(guild-realtime): broadcast message lifecycle events over websocket

This commit is contained in:
nav
2026-05-12 12:18:01 +00:00
parent 01090273c6
commit 33d101af22
2 changed files with 10 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ import { Message } from '../entities/message.entity';
import { IdempotencyRecord } from '../entities/idempotency-record.entity';
import { EventsService } from '../events/events.service';
import { clampLimit, computeNextExpectedSeq } from './pagination.util';
import { RealtimeGateway } from '../realtime/realtime.gateway';
const EDIT_WINDOW_MS = 15 * 60 * 1000;
const DEFAULT_PAGE_LIMIT = 50;
@@ -34,6 +35,7 @@ export class MessagingController {
@InjectRepository(IdempotencyRecord)
private readonly idemRepo: Repository<IdempotencyRecord>,
private readonly events: EventsService,
private readonly realtime: RealtimeGateway,
) {}
private async getIdempotentResponse(
@@ -125,6 +127,7 @@ export class MessagingController {
actorId: body.authorUserId ?? 'anonymous',
data: responseBody,
});
this.realtime.emitChannelEvent(channelId, 'message.created', responseBody);
return responseBody;
}
@@ -161,6 +164,7 @@ export class MessagingController {
actorId: saved.authorUserId,
data: responseBody,
});
this.realtime.emitChannelEvent(channelId, 'message.updated', responseBody);
return responseBody;
}
@@ -202,6 +206,11 @@ export class MessagingController {
deletedAt: item.deletedAt?.toISOString() ?? null,
},
});
this.realtime.emitChannelEvent(channelId, 'message.deleted', {
messageId,
seq: item.seq,
deletedAt: item.deletedAt?.toISOString() ?? null,
});
return responseBody;
}